Skip to content

Commit

Permalink
fix: update to rust 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
l1xnan committed Feb 24, 2025
1 parent 5154f03 commit 9426907
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions connector/src/dialect/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn count_stmt(dialect: &str, stmt: &Statement) -> Option<String> {
let count_sql = count_sql(&tmp.to_string());
let stmt: &mut Statement = &mut Parser::parse_sql(dialect, &count_sql).unwrap()[0];

if let Statement::Query(ref mut tmp) = stmt {
if let Statement::Query(tmp) = stmt {
tmp.with = Some(with.clone());
Some(tmp.to_string())
} else {
Expand Down Expand Up @@ -74,7 +74,7 @@ pub fn limit_stmt(
let count_sql = limit_sql(&tmp.to_string(), limit, offset);
let stmt: &mut Statement = &mut Parser::parse_sql(dialect, &count_sql).unwrap()[0];

if let Statement::Query(ref mut tmp) = stmt {
if let Statement::Query(tmp) = stmt {
tmp.with = Some(with.clone());
Some(tmp.to_string())
} else {
Expand All @@ -96,7 +96,7 @@ fn parse_order_by_expr(order_by: &str) -> Vec<(String, Option<bool>)> {

let mut exprs = vec![];
for stmt in &stmts {
if let Statement::Query(ref tmp) = stmt {
if let Statement::Query(tmp) = stmt {
if let Some(order_by) = &tmp.order_by {
for expr in &order_by.exprs {
exprs.push((expr.expr.to_string(), expr.asc));
Expand Down Expand Up @@ -135,7 +135,10 @@ mod tests {

let ast = Parser::parse_sql(dialect, select_sql).unwrap();

assert_eq!(count_stmt("generic", &ast[0]).unwrap(), "select count(*) from (SELECT a, b, 123, myfunc(b) FROM table_1 WHERE a > b AND b < 100 ORDER BY a DESC, b) ____");
assert_eq!(
count_stmt("generic", &ast[0]).unwrap(),
"select count(*) from (SELECT a, b, 123, myfunc(b) FROM table_1 WHERE a > b AND b < 100 ORDER BY a DESC, b) ____"
);

let cte_sql = "
with tmp as (select * from table_1)
Expand All @@ -146,7 +149,10 @@ mod tests {

let ast = Parser::parse_sql(dialect, cte_sql).unwrap();

assert_eq!(count_stmt("generic", &ast[0]).unwrap(), "WITH tmp AS (SELECT * FROM table_1) SELECT count(*) FROM (SELECT a, b, 123, myfunc(b) FROM tmp WHERE a > b AND b < 100 ORDER BY a DESC, b) AS ____")
assert_eq!(
count_stmt("generic", &ast[0]).unwrap(),
"WITH tmp AS (SELECT * FROM table_1) SELECT count(*) FROM (SELECT a, b, 123, myfunc(b) FROM tmp WHERE a > b AND b < 100 ORDER BY a DESC, b) AS ____"
)
}

#[test]
Expand Down

0 comments on commit 9426907

Please # to comment.