Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -145,7 +145,7 @@ recursive = "0.1.1"
regex = "1.8"
rstest = "0.23.0"
serde_json = "1"
sqlparser = { version = "0.51.0", features = ["visitor"] }
sqlparser = { version = "0.52.0", features = ["visitor"] }
tempfile = "3"
tokio = { version = "1.36", features = ["macros", "rt", "sync"] }
url = "2.2"
Expand Down
11 changes: 11 additions & 0 deletions datafusion/sql/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
expr,
pattern,
escape_char,
any,
} => self.sql_like_to_expr(
negated,
*expr,
Expand All @@ -375,13 +376,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 @@ -390,6 +393,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
schema,
planner_context,
true,
any,
),

SQLExpr::SimilarTo {
Expand Down Expand Up @@ -532,6 +536,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 @@ -779,7 +786,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
14 changes: 12 additions & 2 deletions 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 @@ -646,6 +650,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
name,
parameters,
using,
// has_parentheses specifies the syntax, but the plan is the
// same no matter the synax used, so ignore it
has_parentheses: _,
} => {
// `USING` is a MySQL-specific syntax and currently not supported.
if !using.is_empty() {
Expand All @@ -661,7 +668,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
.collect::<Result<Vec<Expr>>>()?;

Ok(LogicalPlan::Statement(PlanStatement::Execute(Execute {
name: ident_to_string(&name),
name: object_name_to_string(&name),
parameters,
})))
}
Expand All @@ -680,6 +687,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
full,
db_name,
filter,
// SHOW TABLES IN/FROM are equivalent, this field specifies which the user
// specified, but it doesn't affect the plan so ignore the field
clause: _,
} => self.show_tables_to_plan(extended, full, db_name, filter),

Statement::ShowColumns {
Expand Down Expand Up @@ -1108,7 +1118,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: \*"\)
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