Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions datafusion/substrait/src/logical_plan/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,14 +713,27 @@ pub async fn from_substrait_rel(
}
_ => false,
};
let order_by = if !f.sorts.is_empty() {
Some(
from_substrait_sorts(
ctx,
&f.sorts,
input.schema(),
extensions,
)
.await?,
)
} else {
None
};

from_substrait_agg_func(
ctx,
f,
input.schema(),
extensions,
filter,
// TODO: Add parsing of order_by also
None,
order_by,
distinct,
)
.await
Expand Down
16 changes: 15 additions & 1 deletion datafusion/substrait/tests/cases/roundtrip_logical_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,19 @@ async fn aggregate_wo_projection_consume() -> Result<()> {
.await
}

#[tokio::test]
async fn aggregate_wo_projection_sorted_consume() -> Result<()> {
let proto_plan =
read_json("tests/testdata/test_plans/aggregate_sorted_no_project.substrait.json");

assert_expected_plan_substrait(
proto_plan,
"Aggregate: groupBy=[[data.a]], aggr=[[count(data.a) ORDER BY [data.a DESC NULLS FIRST] AS countA]]\
\n TableScan: data projection=[a]",
)
.await
}

#[tokio::test]
async fn simple_intersect_consume() -> Result<()> {
let proto_plan = read_json("tests/testdata/test_plans/intersect.substrait.json");
Expand Down Expand Up @@ -1020,8 +1033,9 @@ async fn roundtrip_aggregate_udf() -> Result<()> {

let ctx = create_context().await?;
ctx.register_udaf(dummy_agg);
roundtrip_with_ctx("select dummy_agg(a) from data", ctx.clone()).await?;
roundtrip_with_ctx("select dummy_agg(a order by a) from data", ctx.clone()).await?;

roundtrip_with_ctx("select dummy_agg(a) from data", ctx).await?;
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"extensionUris": [
{
"uri": "https://github.com/substrait-io/substrait/blob/main/extensions/functions_aggregate_generic.yaml"
}
],
"extensions": [
{
"extensionFunction": {
"functionAnchor": 185,
"name": "count:any"
}
}
],
"relations": [
{
"root": {
"input": {
"aggregate": {
"input": {
"read": {
"common": {
"direct": {}
},
"baseSchema": {
"names": [
"a"
],
"struct": {
"types": [
{
"i64": {
"nullability": "NULLABILITY_NULLABLE"
}
}
],
"nullability": "NULLABILITY_NULLABLE"
}
},
"namedTable": {
"names": [
"data"
]
}
}
},
"groupings": [
{
"groupingExpressions": [
{
"selection": {
"directReference": {
"structField": {}
},
"rootReference": {}
}
}
]
}
],
"measures": [
{
"measure": {
"functionReference": 185,
"phase": "AGGREGATION_PHASE_INITIAL_TO_RESULT",
"outputType": {
"i64": {}
},
"arguments": [
{
"value": {
"selection": {
"directReference": {
"structField": {}
},
"rootReference": {}
}
}
}
],
"sorts": [
{
"expr": {
"selection": {
"directReference": {
"structField": {
"field": 0
}
},
"rootReference": {
}
}
},
"direction": "SORT_DIRECTION_DESC_NULLS_FIRST"
}
]
}
}
]
}
},
"names": [
"a",
"countA"
]
}
}
],
"version": {
"minorNumber": 54,
"producer": "manual"
}
}