Skip to content

Commit

Permalink
reverted Parser.js as it wasnt part of this PR
Browse files Browse the repository at this point in the history
  • Loading branch information
khushishukla2813 authored Mar 4, 2025
1 parent 4b079a6 commit 66a3ec6
Showing 1 changed file with 8 additions and 43 deletions.
51 changes: 8 additions & 43 deletions datafusion/sql/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,11 @@ use sqlparser::{

// Use `Parser::expected` instead, if possible
macro_rules! parser_err {
($MSG:expr, $token:expr, $line:expr, $column:expr) => {
Err(ParserError::ParserError(format!(
"{} at Line: {}, Column: {}. Found: '{}'.",
$MSG, $line, $column, $token
)))
($MSG:expr) => {
Err(ParserError::ParserError($MSG.to_string()))
};
}



fn parse_file_type(s: &str) -> Result<String, ParserError> {
Ok(s.to_uppercase())
}
Expand Down Expand Up @@ -421,15 +416,13 @@ impl<'a> DFParser<'a> {
}

/// Report an unexpected token
fn expected<T>(&self, expected: &str, found: TokenWithSpan) -> Result<T, ParserError> {
parser_err!(
format!("Expected: {}", expected),
found.token.to_string(),
found.span.start.line,
found.span.start.column
)
fn expected<T>(
&self,
expected: &str,
found: TokenWithSpan,
) -> Result<T, ParserError> {
parser_err!(format!("Expected {expected}, found: {found}"))
}


/// Parse a new expression
pub fn parse_statement(&mut self) -> Result<Statement, ParserError> {
Expand Down Expand Up @@ -1018,34 +1011,6 @@ mod tests {
}
}

#[test]
fn test_parser_error_message() {
let sql = "WITH cte AS (SELECT 1 AS col), SELECT * FROM cte"; // Incorrect SQL
let result = DFParser::parse_sql(sql);

match result {
Err(ParserError::ParserError(msg)) => {
assert!(
msg.contains("Expected: AS"),
"Expected error message to contain 'Expected: AS', got: {}",
msg
);
assert!(
msg.contains("Found: '*'"),
"Expected error message to mention the incorrect token '*', got: {}",
msg
);
assert!(
msg.contains("Line: 1, Column: 39"),
"Expected error message to contain correct position, got: {}",
msg
);
}
_ => panic!("Expected ParserError, but got {:?}", result),
}
}


#[test]
fn create_external_table() -> Result<(), ParserError> {
// positive case
Expand Down

0 comments on commit 66a3ec6

Please sign in to comment.