Skip to content

Commit

Permalink
[BUG]: Sql groupby and orderby with aliases and projections (#3177)
Browse files Browse the repository at this point in the history
Co-authored-by: Kev Wang <[email protected]>
  • Loading branch information
universalmind303 and kevinzwang authored Nov 6, 2024
1 parent 2829a09 commit 8ed174c
Show file tree
Hide file tree
Showing 4 changed files with 360 additions and 77 deletions.
1 change: 0 additions & 1 deletion src/daft-sql/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use common_error::DaftError;
use snafu::Snafu;
use sqlparser::{parser::ParserError, tokenizer::TokenizerError};

#[derive(Debug, Snafu)]
pub enum PlannerError {
#[snafu(display("Tokenization error: {source}"))]
Expand Down
26 changes: 26 additions & 0 deletions src/daft-sql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,35 @@ mod tests {

let expected = LogicalPlanBuilder::new(tbl_1, None)
.aggregate(vec![col("i32").max()], vec![])?
.select(vec![col("i32")])?
.build();

assert_eq!(plan, expected);
Ok(())
}

#[rstest]
#[case::basic("select utf8 from tbl1 order by utf8")]
#[case::asc("select utf8 from tbl1 order by utf8 asc")]
#[case::desc("select utf8 from tbl1 order by utf8 desc")]
#[case::with_alias("select utf8 as a from tbl1 order by a")]
#[case::with_alias_in_projection_only("select utf8 as a from tbl1 order by utf8")]
#[case::with_groupby("select utf8, sum(i32) from tbl1 group by utf8 order by utf8")]
#[case::with_groupby_and_alias(
"select utf8 as a, sum(i32) from tbl1 group by utf8 order by utf8"
)]
#[case::with_groupby_and_alias_mixed("select utf8 as a from tbl1 group by a order by utf8")]
#[case::with_groupby_and_alias_mixed_2("select utf8 as a from tbl1 group by utf8 order by a")]
#[case::with_groupby_and_alias_mixed_asc(
"select utf8 as a from tbl1 group by utf8 order by a asc"
)]
fn test_compiles_orderby(mut planner: SQLPlanner, #[case] query: &str) -> SQLPlannerResult<()> {
let plan = planner.plan_sql(query);
if let Err(e) = plan {
panic!("query: {query}\nerror: {e:?}");
}
assert!(plan.is_ok(), "query: {query}\nerror: {plan:?}");

Ok(())
}
}
Loading

0 comments on commit 8ed174c

Please sign in to comment.