Skip to content
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

Update sqlparser to 0.19 #2981

Merged
merged 5 commits into from
Jul 29, 2022
Merged
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 datafusion/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ object_store = { version = "0.3", optional = true }
ordered-float = "3.0"
parquet = { version = "19.0.0", features = ["arrow"], optional = true }
pyo3 = { version = "0.16", optional = true }
sqlparser = "0.18"
sqlparser = "0.19"
2 changes: 1 addition & 1 deletion datafusion/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pyo3 = { version = "0.16", optional = true }
rand = "0.8"
rayon = { version = "1.5", optional = true }
smallvec = { version = "1.6", features = ["union"] }
sqlparser = "0.18"
sqlparser = "0.19"
tempfile = "3"
tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "fs", "parking_lot"] }
tokio-stream = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion datafusion/expr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ path = "src/lib.rs"
ahash = { version = "0.7", default-features = false }
arrow = { version = "19.0.0", features = ["prettyprint"] }
datafusion-common = { path = "../common", version = "10.0.0" }
sqlparser = "0.18"
sqlparser = "0.19"
2 changes: 1 addition & 1 deletion datafusion/sql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ arrow = { version = "19.0.0", features = ["prettyprint"] }
datafusion-common = { path = "../common", version = "10.0.0" }
datafusion-expr = { path = "../expr", version = "10.0.0" }
hashbrown = "0.12"
sqlparser = "0.18"
sqlparser = "0.19"
tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "fs", "parking_lot"] }
27 changes: 16 additions & 11 deletions datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
ctes.insert(cte_name, logical_plan);
}
}
let plan = self.set_expr_to_plan(set_expr, alias, ctes, outer_query_schema)?;
let plan = self.set_expr_to_plan(*set_expr, alias, ctes, outer_query_schema)?;

let plan = self.order_by(plan, query.order_by)?;
self.limit(plan, query.offset, query.limit)
Expand Down Expand Up @@ -1649,7 +1649,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
last_field,
fractional_seconds_precision,
}) => self.sql_interval_to_literal(
value,
*value,
leading_field,
leading_precision,
last_field,
Expand Down Expand Up @@ -1820,13 +1820,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}),


SQLExpr::UnaryOp { op, expr } => match (&op, expr.as_ref()) {
// The AST for Exists does not support the NOT EXISTS case so it gets
// wrapped in a unary NOT
// https://github.com/sqlparser-rs/sqlparser-rs/issues/472
Copy link
Contributor Author

Choose a reason for hiding this comment

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

apache/datafusion-sqlparser-rs#472 is indeed fixed 🎉 (thanks @togami2864)

(&UnaryOperator::Not, &SQLExpr::Exists(ref subquery)) => self.parse_exists_subquery(subquery, true, schema, ctes),
_ => self.parse_sql_unary_op(op, *expr, schema, ctes)
}
SQLExpr::UnaryOp { op, expr } => self.parse_sql_unary_op(op, *expr, schema, ctes),

SQLExpr::Between {
expr,
Expand Down Expand Up @@ -2066,7 +2060,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {

SQLExpr::Nested(e) => self.sql_expr_to_logical_expr(*e, schema, ctes),

SQLExpr::Exists(subquery) => self.parse_exists_subquery(&subquery, false, schema, ctes),
SQLExpr::Exists{ subquery, negated } => self.parse_exists_subquery(&subquery, negated, schema, ctes),

SQLExpr::InSubquery { expr, subquery, negated } => self.parse_in_subquery(&expr, &subquery, negated, schema, ctes),

Expand Down Expand Up @@ -2184,7 +2178,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {

fn sql_interval_to_literal(
&self,
value: String,
value: SQLExpr,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Intervals now support arbitrary expressions, not just strings: apache/datafusion-sqlparser-rs#517

leading_field: Option<DateTimeField>,
leading_precision: Option<u64>,
last_field: Option<DateTimeField>,
Expand All @@ -2211,6 +2205,17 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
)));
}

// Only handle string exprs for now
let value = match value {
SQLExpr::Value(Value::SingleQuotedString(s)) => s,
_ => {
return Err(DataFusionError::NotImplemented(format!(
"Unsupported interval argument. Expected string literal, got: {:?}",
value
)))
}
};

const SECONDS_PER_HOUR: f32 = 3_600_f32;
const MILLIS_PER_SECOND: f32 = 1_000_f32;

Expand Down