diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a6e9d2b..c1dd91e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.3.2] - 2023-09-25 +### Changed +- Updated `sqlparser` ## [0.3.2] - 2023-09-25 ### Added - conversion DataType -> Value for Expr::Function [MR122](https://github.com/Qrlew/qrlew/pull/122) diff --git a/Cargo.toml b/Cargo.toml index 6b3b54e3..dda2df96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Nicolas Grislain "] name = "qrlew" -version = "0.3.2" +version = "0.3.3" edition = "2021" description = "Sarus Qrlew Engine" documentation = "https://docs.rs/qrlew" @@ -24,7 +24,7 @@ paste = "1.0.7" serde = { version = "1.0", features = ["derive", "rc"] } serde_json = "1.0" chrono = { version = "0.4", features = ["serde"] } -sqlparser = "0.37.0" +sqlparser = "0.38.0" dot = "0.1" base64 = "0.21" rusqlite = { version = "0.29", features = ["chrono"], optional = true } diff --git a/src/relation/sql.rs b/src/relation/sql.rs index cd660b4f..75372f5b 100644 --- a/src/relation/sql.rs +++ b/src/relation/sql.rs @@ -99,7 +99,7 @@ fn query( projection: Vec, from: ast::TableWithJoins, selection: Option, - group_by: Vec, + group_by: ast::GroupByExpr, order_by: Vec, limit: Option, ) -> ast::Query { @@ -158,6 +158,7 @@ fn table_factor(relation: &Relation) -> ast::TableFactor { args: None, with_hints: vec![], version: None, + partitions: vec![], }, relation => ast::TableFactor::Table { name: Identifier::from(relation.name()).into(), @@ -165,6 +166,7 @@ fn table_factor(relation: &Relation) -> ast::TableFactor { args: None, with_hints: vec![], version: None, + partitions: vec![], }, } } @@ -237,7 +239,7 @@ impl<'a> Visitor<'a, ast::Query> for FromRelationVisitor { )], table_with_joins(&table.clone().into(), vec![]), None, - vec![], + ast::GroupByExpr::Expressions(vec![]), vec![], None, ) @@ -266,7 +268,7 @@ impl<'a> Visitor<'a, ast::Query> for FromRelationVisitor { .collect(), table_with_joins(map.input.as_ref().into(), vec![]), map.filter.as_ref().map(ast::Expr::from), - vec![], + ast::GroupByExpr::Expressions(vec![]), map.order_by .iter() .map(|OrderBy { expr, asc }| ast::OrderByExpr { @@ -284,7 +286,7 @@ impl<'a> Visitor<'a, ast::Query> for FromRelationVisitor { all(), table_with_joins(&map.clone().into(), vec![]), None, - vec![], + ast::GroupByExpr::Expressions(vec![]), vec![], map.limit .map(|limit| ast::Expr::Value(ast::Value::Number(limit.to_string(), false))), @@ -316,7 +318,7 @@ impl<'a> Visitor<'a, ast::Query> for FromRelationVisitor { .collect(), table_with_joins(reduce.input.as_ref().into(), vec![]), None, - reduce.group_by.iter().map(ast::Expr::from).collect(), + ast::GroupByExpr::Expressions(reduce.group_by.iter().map(ast::Expr::from).collect()), vec![], None, ), @@ -326,7 +328,7 @@ impl<'a> Visitor<'a, ast::Query> for FromRelationVisitor { all(), table_with_joins(&reduce.clone().into(), vec![]), None, - vec![], + ast::GroupByExpr::Expressions(vec![]), vec![], None, ) @@ -364,7 +366,7 @@ impl<'a> Visitor<'a, ast::Query> for FromRelationVisitor { }], ), None, - vec![], + ast::GroupByExpr::Expressions(vec![]), vec![], None, ), @@ -374,7 +376,7 @@ impl<'a> Visitor<'a, ast::Query> for FromRelationVisitor { all(), table_with_joins(&join.clone().into(), vec![]), None, - vec![], + ast::GroupByExpr::Expressions(vec![]), vec![], None, ) @@ -414,7 +416,7 @@ impl<'a> Visitor<'a, ast::Query> for FromRelationVisitor { all(), table_with_joins(&set.clone().into(), vec![]), None, - vec![], + ast::GroupByExpr::Expressions(vec![]), vec![], None, ) @@ -449,7 +451,7 @@ impl<'a> Visitor<'a, ast::Query> for FromRelationVisitor { }, joins: vec![], }; - query(vec![], all(), from, None, vec![], vec![], None) + query(vec![], all(), from, None, ast::GroupByExpr::Expressions(vec![]), vec![], None) } } diff --git a/src/sql/expr.rs b/src/sql/expr.rs index 2ba1cfe2..80e430bc 100644 --- a/src/sql/expr.rs +++ b/src/sql/expr.rs @@ -104,8 +104,12 @@ impl<'a> Acceptor<'a> for ast::Expr { pattern, escape_char: _, } => Dependencies::from([expr.as_ref(), pattern.as_ref()]), - ast::Expr::AnyOp(expr) => Dependencies::from([expr.as_ref()]), - ast::Expr::AllOp(expr) => Dependencies::from([expr.as_ref()]), + ast::Expr::AnyOp {left, compare_op: _, right} => { + Dependencies::from([left.as_ref(), right.as_ref()]) + }, + ast::Expr::AllOp {left, compare_op: _, right} => { + Dependencies::from([left.as_ref(), right.as_ref()]) + }, ast::Expr::UnaryOp { op: _, expr } => Dependencies::from([expr.as_ref()]), ast::Expr::Cast { expr, data_type: _ } => Dependencies::from([expr.as_ref()]), ast::Expr::TryCast { expr, data_type: _ } => Dependencies::from([expr.as_ref()]), @@ -323,8 +327,12 @@ impl<'a, T: Clone, V: Visitor<'a, T>> visitor::Visitor<'a, ast::Expr, T> for V { pattern, escape_char, } => todo!(), - ast::Expr::AnyOp(_) => todo!(), - ast::Expr::AllOp(_) => todo!(), + ast::Expr::AnyOp {left, compare_op: _, right} => { + todo!() + }, + ast::Expr::AllOp {left, compare_op: _, right} => { + todo!() + }, ast::Expr::UnaryOp { op, expr } => self.unary_op(op, dependencies.get(expr).clone()), ast::Expr::Cast { expr, data_type } => todo!(), ast::Expr::TryCast { expr, data_type } => todo!(), diff --git a/src/sql/relation.rs b/src/sql/relation.rs index a3460bf5..a5ab97d9 100644 --- a/src/sql/relation.rs +++ b/src/sql/relation.rs @@ -310,7 +310,7 @@ impl<'a> VisitedQueryRelations<'a> { names: &'a Hierarchy, select_items: &'a [ast::SelectItem], selection: &'a Option, - group_by: &'a Vec, + group_by: &'a ast::GroupByExpr, from: Rc, ) -> Result> { // Collect all expressions with their aliases @@ -349,10 +349,12 @@ impl<'a> VisitedQueryRelations<'a> { .map(|e| e.with(columns).try_into()) .map_or(Ok(None), |r| r.map(Some))?; // Prepare the GROUP BY - let group_by: Result> = group_by - .iter() - .map(|e| e.with(columns).try_into()) - .collect(); + let group_by: Result> = match group_by { + ast::GroupByExpr::All => todo!(), + ast::GroupByExpr::Expressions(group_by_exprs) => group_by_exprs.iter() + .map(|e| e.with(columns).try_into()) + .collect(), + }; // Build a Relation let relation = match split { Split::Map(map) => {