Skip to content

Apache DataFusion SQL Query Engine

ARROW-11574: [Rust][DataFusion] Upgrade sqlparser to support parsing all TPC-H queries

Heres, Daniel6a8c41be4ed9
diff --git a/rust/benchmarks/src/bin/tpch.rs b/rust/benchmarks/src/bin/tpch.rs
index 90b7de5827..6934512802 100644
--- a/rust/benchmarks/src/bin/tpch.rs
+++ b/rust/benchmarks/src/bin/tpch.rs
@@ -385,7 +385,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logic
// where
// l_shipdate >= date '1994-01-01'
// and l_shipdate < date '1994-01-01' + interval '1' year
- // and l_discount between 0.06 - 0.01 and 0.06 + 0.01
+ // and l_discount between .06 - 0.01 and .06 + 0.01
// and l_quantity < 24;"
// ),
6 => ctx.create_logical_plan(
@@ -396,7 +396,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logic
where
l_shipdate >= date '1994-01-01'
and l_shipdate < date '1995-01-01'
- and l_discount between 0.06 - 0.01 and 0.06 + 0.01
+ and l_discount between .06 - 0.01 and .06 + 0.01
and l_quantity < 24;",
),
diff --git a/rust/datafusion/Cargo.toml b/rust/datafusion/Cargo.toml
index 8f62b8d63c..ea556662e3 100644
--- a/rust/datafusion/Cargo.toml
+++ b/rust/datafusion/Cargo.toml
@@ -49,7 +49,7 @@ ahash = "0.7"
hashbrown = "0.9"
arrow = { path = "../arrow", version = "4.0.0-SNAPSHOT", features = ["prettyprint"] }
parquet = { path = "../parquet", version = "4.0.0-SNAPSHOT", features = ["arrow"] }
-sqlparser = "0.7.0"
+sqlparser = "0.8.0"
clap = "2.33"
rustyline = {version = "7.0", optional = true}
crossbeam = "0.8"
diff --git a/rust/datafusion/src/sql/planner.rs b/rust/datafusion/src/sql/planner.rs
index a90def60b6..5d505fd2ec 100644
--- a/rust/datafusion/src/sql/planner.rs
+++ b/rust/datafusion/src/sql/planner.rs
@@ -310,6 +310,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
"NATURAL JOIN is not supported (https://issues.apache.org/jira/browse/ARROW-10727)".to_string(),
))
}
+ JoinConstraint::None => Err(DataFusionError::NotImplemented(
+ "NONE contraint is not supported".to_string(),
+ )),
}
}
@@ -714,7 +717,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
fn sql_expr_to_logical_expr(&self, sql: &SQLExpr) -> Result<Expr> {
match sql {
- SQLExpr::Value(Value::Number(n)) => match n.parse::<i64>() {
+ SQLExpr::Value(Value::Number(n, _)) => match n.parse::<i64>() {
Ok(n) => Ok(lit(n)),
Err(_) => Ok(lit(n.parse::<f64>().unwrap())),
},
@@ -833,7 +836,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
match expr.as_ref() {
// optimization: if it's a number literal, we applly the negative operator
// here directly to calculate the new literal.
- SQLExpr::Value(Value::Number(n)) => match n.parse::<i64>() {
+ SQLExpr::Value(Value::Number(n,_)) => match n.parse::<i64>() {
Ok(n) => Ok(lit(-n)),
Err(_) => Ok(lit(-n
.parse::<f64>()
@@ -939,6 +942,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
.map(|a| match a {
FunctionArg::Unnamed(SQLExpr::Value(Value::Number(
_,
+ _,
))) => Ok(lit(1_u8)),
FunctionArg::Unnamed(SQLExpr::Wildcard) => Ok(lit(1_u8)),
_ => self.sql_fn_arg_to_logical_expr(a),
@@ -1405,7 +1409,8 @@ mod tests {
#[test]
fn test_timestamp_filter() {
- let sql = "SELECT state FROM person WHERE birth_date < CAST (158412331400600000 as timestamp)";
+ let sql =
+ "SELECT state FROM person WHERE birth_date < CAST (158412331400600000 as timestamp)";
let expected = "Projection: #state\
\n Filter: #birth_date Lt CAST(Int64(158412331400600000) AS Timestamp(Nanosecond, None))\
@@ -2052,7 +2057,8 @@ mod tests {
fn select_simple_aggregate_with_groupby_non_column_expression_nested_and_not_resolvable(
) {
// The query should fail, because age + 9 is not in the group by.
- let sql = "SELECT ((age + 1) / 2) * (age + 9), MIN(first_name) FROM person GROUP BY age + 1";
+ let sql =
+ "SELECT ((age + 1) / 2) * (age + 9), MIN(first_name) FROM person GROUP BY age + 1";
let err = logical_plan(sql).expect_err("query should have failed");
assert_eq!(
"Plan(\"Projection references non-aggregate values\")",