Skip to content

Commit b4f61f5

Browse files
committed
chore: Support ArrayAgg ORDER BY (stub)
1 parent f5bc6d4 commit b4f61f5

File tree

7 files changed

+88
-7
lines changed

7 files changed

+88
-7
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion-cli/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/common/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ cranelift-module = { version = "0.82.0", optional = true }
4444
ordered-float = "2.10"
4545
parquet = { git = 'https://github.com/cube-js/arrow-rs.git', rev = "096ef28dde6b1ae43ce89ba2c3a9d98295f2972e", features = ["arrow"], optional = true }
4646
pyo3 = { version = "0.16", optional = true }
47-
sqlparser = { git = 'https://github.com/cube-js/sqlparser-rs.git', rev = "10782e5d11fc0e2900c9359dddee0fbefbffd359" }
47+
sqlparser = { git = 'https://github.com/cube-js/sqlparser-rs.git', rev = "b3b40586d4c32a218ffdfcb0462e7e216cf3d6eb" }

datafusion/core/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pin-project-lite= "^0.2.7"
7979
pyo3 = { version = "0.16", optional = true }
8080
rand = "0.8"
8181
smallvec = { version = "1.6", features = ["union"] }
82-
sqlparser = { git = 'https://github.com/cube-js/sqlparser-rs.git', rev = "10782e5d11fc0e2900c9359dddee0fbefbffd359" }
82+
sqlparser = { git = 'https://github.com/cube-js/sqlparser-rs.git', rev = "b3b40586d4c32a218ffdfcb0462e7e216cf3d6eb" }
8383
tempfile = "3"
8484
tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "fs", "parking_lot"] }
8585
tokio-stream = "0.1"

datafusion/core/src/sql/planner.rs

+50-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ use hashbrown::HashMap;
5353
use log::warn;
5454

5555
use sqlparser::ast::{
56-
BinaryOperator, DataType as SQLDataType, DateTimeField, Expr as SQLExpr, FunctionArg,
57-
FunctionArgExpr, Ident, Join, JoinConstraint, JoinOperator, ObjectName,
56+
ArrayAgg, BinaryOperator, DataType as SQLDataType, DateTimeField, Expr as SQLExpr,
57+
FunctionArg, FunctionArgExpr, Ident, Join, JoinConstraint, JoinOperator, ObjectName,
5858
Offset as SQLOffset, Query, Select, SelectItem, SetExpr, SetOperator,
5959
ShowStatementFilter, TableFactor, TableWithJoins, TrimWhereField, UnaryOperator,
6060
Value, Values as SQLValues,
@@ -2318,13 +2318,61 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
23182318
self.sql_expr_to_logical_expr(*timestamp, schema)
23192319
}
23202320

2321+
SQLExpr::ArrayAgg(array_agg) => self.parse_array_agg(array_agg, schema),
2322+
23212323
_ => Err(DataFusionError::NotImplemented(format!(
23222324
"Unsupported ast node {:?} in sqltorel",
23232325
sql
23242326
))),
23252327
}
23262328
}
23272329

2330+
fn parse_array_agg(
2331+
&self,
2332+
array_agg: ArrayAgg,
2333+
input_schema: &DFSchema,
2334+
) -> Result<Expr> {
2335+
// Some dialects have special syntax for array_agg. DataFusion only supports it like a function.
2336+
let ArrayAgg {
2337+
distinct,
2338+
expr,
2339+
limit,
2340+
within_group,
2341+
..
2342+
} = array_agg;
2343+
2344+
// FIXME: ORDER BY is not supported but we ignore it
2345+
/*if let Some(order_by) = order_by {
2346+
return Err(DataFusionError::NotImplemented(format!(
2347+
"ORDER BY not supported in ARRAY_AGG: {}",
2348+
order_by
2349+
)));
2350+
}*/
2351+
2352+
if let Some(limit) = limit {
2353+
return Err(DataFusionError::NotImplemented(format!(
2354+
"LIMIT not supported in ARRAY_AGG: {}",
2355+
limit
2356+
)));
2357+
}
2358+
2359+
if within_group {
2360+
return Err(DataFusionError::NotImplemented(
2361+
"WITHIN GROUP not supported in ARRAY_AGG".to_string(),
2362+
));
2363+
}
2364+
2365+
let args = vec![self.sql_expr_to_logical_expr(*expr, input_schema)?];
2366+
// next, aggregate built-ins
2367+
let fun = aggregates::AggregateFunction::ArrayAgg;
2368+
2369+
Ok(Expr::AggregateFunction {
2370+
fun,
2371+
distinct,
2372+
args,
2373+
})
2374+
}
2375+
23282376
fn function_args_to_expr(
23292377
&self,
23302378
args: Vec<FunctionArg>,

datafusion/core/tests/sql/aggregates.rs

+33
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,39 @@ async fn csv_query_array_agg_distinct() -> Result<()> {
704704
Ok(())
705705
}
706706

707+
#[tokio::test]
708+
async fn csv_query_array_agg_unsupported() -> Result<()> {
709+
let ctx = SessionContext::new();
710+
register_aggregate_csv(&ctx).await?;
711+
712+
// FIXME: ORDER BY is not supported but we ignore it
713+
/*let results = plan_and_collect(
714+
&ctx,
715+
"SELECT array_agg(c13 ORDER BY c1) FROM aggregate_test_100",
716+
)
717+
.await
718+
.unwrap_err();
719+
720+
assert_eq!(
721+
results.to_string(),
722+
"This feature is not implemented: ORDER BY not supported in ARRAY_AGG: c1"
723+
);*/
724+
725+
let results = plan_and_collect(
726+
&ctx,
727+
"SELECT array_agg(c13 LIMIT 1) FROM aggregate_test_100",
728+
)
729+
.await
730+
.unwrap_err();
731+
732+
assert_eq!(
733+
results.to_string(),
734+
"This feature is not implemented: LIMIT not supported in ARRAY_AGG: 1"
735+
);
736+
737+
Ok(())
738+
}
739+
707740
#[tokio::test]
708741
async fn csv_query_projection_drop_out_aggr_merge() -> Result<()> {
709742
let ctx = SessionContext::new();

datafusion/expr/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ path = "src/lib.rs"
3838
ahash = { version = "0.7", default-features = false }
3939
arrow = { git = 'https://github.com/cube-js/arrow-rs.git', rev = "096ef28dde6b1ae43ce89ba2c3a9d98295f2972e", features = ["prettyprint"] }
4040
datafusion-common = { path = "../common", version = "7.0.0" }
41-
sqlparser = { git = 'https://github.com/cube-js/sqlparser-rs.git', rev = "10782e5d11fc0e2900c9359dddee0fbefbffd359" }
41+
sqlparser = { git = 'https://github.com/cube-js/sqlparser-rs.git', rev = "b3b40586d4c32a218ffdfcb0462e7e216cf3d6eb" }

0 commit comments

Comments
 (0)