Skip to content

WIP: Update to sqlparser-rs 0.52.0 pre-release #13282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ rand = "0.8"
regex = "1.8"
rstest = "0.23.0"
serde_json = "1"
sqlparser = { version = "0.51.0", features = ["visitor"] }
sqlparser = { version = "0.52.0", features = ["visitor"], git = "https://github.com/apache/datafusion-sqlparser-rs.git", rev = "a4aa6e28d68b83099db77e594e9209d85820ec96" }
tempfile = "3"
tokio = { version = "1.36", features = ["macros", "rt", "sync"] }
url = "2.2"
Expand Down
32 changes: 15 additions & 17 deletions datafusion-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions datafusion/sql/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
expr,
pattern,
escape_char,
any,
} => self.sql_like_to_expr(
negated,
*expr,
Expand All @@ -372,13 +373,15 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
schema,
planner_context,
false,
any,
),

SQLExpr::ILike {
negated,
expr,
pattern,
escape_char,
any,
} => self.sql_like_to_expr(
negated,
*expr,
Expand All @@ -387,6 +390,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
schema,
planner_context,
true,
any,
),

SQLExpr::SimilarTo {
Expand Down Expand Up @@ -529,6 +533,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
left,
compare_op,
right,
// ANY/SOME are equivalent, this field specifies which the user
// specified but it doesn't affect the plan so ignore the field
is_some: _,
} => {
let mut binary_expr = RawBinaryExpr {
op: compare_op,
Expand Down Expand Up @@ -776,7 +783,11 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
schema: &DFSchema,
planner_context: &mut PlannerContext,
case_insensitive: bool,
any: bool,
) -> Result<Expr> {
if any {
return not_impl_err!("ANY in LIKE expression");
}
let pattern = self.sql_expr_to_logical_expr(pattern, schema, planner_context)?;
let pattern_type = pattern.get_type(schema)?;
if pattern_type != DataType::Utf8 && pattern_type != DataType::Null {
Expand Down
4 changes: 2 additions & 2 deletions datafusion/sql/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub enum CopyToSource {
/// `COPY <table> TO ...`
Relation(ObjectName),
/// COPY (...query...) TO ...
Query(Query),
Query(Box<Query>),
}

impl fmt::Display for CopyToSource {
Expand Down Expand Up @@ -1444,7 +1444,7 @@ mod tests {
};

let query = if let SQLStatement::Query(query) = statement {
*query
query
} else {
panic!("Expected query, got {statement:?}");
};
Expand Down
9 changes: 8 additions & 1 deletion datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConst
| ast::ColumnOption::OnUpdate(_)
| ast::ColumnOption::Materialized(_)
| ast::ColumnOption::Ephemeral(_)
| ast::ColumnOption::Identity(_)
| ast::ColumnOption::OnConflict(_)
| ast::ColumnOption::Policy(_)
| ast::ColumnOption::Tags(_)
| ast::ColumnOption::Alias(_) => {}
}
}
Expand Down Expand Up @@ -672,6 +676,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
full,
db_name,
filter,
// specifies IN/FROM, both of which DataFusion trets the same
// so ignored
clause: _,
} => self.show_tables_to_plan(extended, full, db_name, filter),

Statement::ShowColumns {
Expand Down Expand Up @@ -1103,7 +1110,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
(plan, input_schema, Some(table_ref))
}
CopyToSource::Query(query) => {
let plan = self.query_to_plan(query, &mut PlannerContext::new())?;
let plan = self.query_to_plan(*query, &mut PlannerContext::new())?;
let input_schema = Arc::clone(plan.schema());
(plan, input_schema, None)
}
Expand Down
1 change: 1 addition & 0 deletions datafusion/sql/src/unparser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ impl SelectBuilder {
pub fn build(&self) -> Result<ast::Select, BuilderError> {
Ok(ast::Select {
distinct: self.distinct.clone(),
top_before_distinct: false,
top: self.top.clone(),
projection: self.projection.clone(),
into: self.into.clone(),
Expand Down
1 change: 1 addition & 0 deletions datafusion/sql/src/unparser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ impl Unparser<'_> {
expr: Box::new(self.expr_to_sql_inner(expr)?),
pattern: Box::new(self.expr_to_sql_inner(pattern)?),
escape_char: escape_char.map(|c| c.to_string()),
any: false,
}),
Expr::AggregateFunction(agg) => {
let func_name = agg.func.name();
Expand Down
2 changes: 1 addition & 1 deletion datafusion/sqllogictest/test_files/distinct_on.slt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ b 1 29 -18218 994303988 5983957848665088916 204 9489 3275293996 1485709125918647
c 2 1 18109 2033001162 -6513304855495910254 25 43062 1491205016 5863949479783605708 0.110830784 0.929409733247 6WfVFBVGJSQb7FhA7E0lBwdvjfZnSW

# can't distinct on *
query error DataFusion error: SQL error: ParserError\("Expected: an expression:, found: \*"\)
query error DataFusion error: SQL error: ParserError\("Expected: an expression, found: \*"\)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error messages improved wiht apache/datafusion-sqlparser-rs#1434

SELECT DISTINCT ON (*) c1 FROM aggregate_test_100 ORDER BY c1 LIMIT 3;


Expand Down
4 changes: 2 additions & 2 deletions datafusion/sqllogictest/test_files/select.slt
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@ NULL 1
statement error DataFusion error: SQL error: ParserError\("Expected: \(, found: EOF"\)
VALUES

statement error DataFusion error: SQL error: ParserError\("Expected: an expression:, found: \)"\)
statement error DataFusion error: SQL error: ParserError\("Expected: an expression, found: \)"\)
VALUES ()

statement error DataFusion error: SQL error: ParserError\("Expected: an expression:, found: \)"\)
statement error DataFusion error: SQL error: ParserError\("Expected: an expression, found: \)"\)
VALUES (1),()

statement error DataFusion error: Error during planning: Inconsistent data length across values list: got 2 values in row 1 but expected 1
Expand Down
2 changes: 1 addition & 1 deletion datafusion/sqllogictest/test_files/unnest.slt
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ query error DataFusion error: Error during planning: unnest\(\) requires exactly
select unnest();

## Unnest empty expression in from clause
query error DataFusion error: SQL error: ParserError\("Expected: an expression:, found: \)"\)
query error DataFusion error: SQL error: ParserError\("Expected: an expression, found: \)"\)
select * from unnest();


Expand Down
Loading