Skip to content

Commit

Permalink
Updated SQLparser
Browse files Browse the repository at this point in the history
  • Loading branch information
ngrislain committed Sep 25, 2023
1 parent a11c254 commit b80fde3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Nicolas Grislain <ng@sarus.tech>"]
name = "qrlew"
version = "0.3.2"
version = "0.3.3"
edition = "2021"
description = "Sarus Qrlew Engine"
documentation = "https://docs.rs/qrlew"
Expand All @@ -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 }
Expand Down
22 changes: 12 additions & 10 deletions src/relation/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn query(
projection: Vec<ast::SelectItem>,
from: ast::TableWithJoins,
selection: Option<ast::Expr>,
group_by: Vec<ast::Expr>,
group_by: ast::GroupByExpr,
order_by: Vec<ast::OrderByExpr>,
limit: Option<ast::Expr>,
) -> ast::Query {
Expand Down Expand Up @@ -158,13 +158,15 @@ 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(),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
},
}
}
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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 {
Expand All @@ -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))),
Expand Down Expand Up @@ -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,
),
Expand All @@ -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,
)
Expand Down Expand Up @@ -364,7 +366,7 @@ impl<'a> Visitor<'a, ast::Query> for FromRelationVisitor {
}],
),
None,
vec![],
ast::GroupByExpr::Expressions(vec![]),
vec![],
None,
),
Expand All @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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)
}
}

Expand Down
16 changes: 12 additions & 4 deletions src/sql/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()]),
Expand Down Expand Up @@ -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!(),
Expand Down
12 changes: 7 additions & 5 deletions src/sql/relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl<'a> VisitedQueryRelations<'a> {
names: &'a Hierarchy<String>,
select_items: &'a [ast::SelectItem],
selection: &'a Option<ast::Expr>,
group_by: &'a Vec<ast::Expr>,
group_by: &'a ast::GroupByExpr,
from: Rc<Relation>,
) -> Result<Rc<Relation>> {
// Collect all expressions with their aliases
Expand Down Expand Up @@ -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<Vec<Expr>> = group_by
.iter()
.map(|e| e.with(columns).try_into())
.collect();
let group_by: Result<Vec<Expr>> = 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) => {
Expand Down

0 comments on commit b80fde3

Please sign in to comment.