Repository navigation
fix: give a multi-set aggregate the grouping set index Substrait defines #25527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
namanjain24-sudo
wants to merge
10
commits into
apache:main
from
namanjain24-sudo:fix-substrait-grouping-set-index
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8d16378
fix: give a multi-set aggregate the grouping set index Substrait defines
namanjain24-sudo 25e78f3
chore: retrigger CI after transient MinIO/quay.io registry outage
namanjain24-sudo 95dc419
fix: handle the three grouping-set-index edge cases review flagged
namanjain24-sudo 473ecb8
fix: check ordinal fits in the remaining bits before shifting in grou…
namanjain24-sudo c8a5a7d
Merge branch 'main' into fix-substrait-grouping-set-index
kosiew 27a08f1
test: isolate ordinal-driven grouping id widening, cover the consumer…
namanjain24-sudo 68ce736
test: pin how a pre-index DataFusion plan reads back, and document th…
namanjain24-sudo 0bbbeb2
Merge remote-tracking branch 'origin/main' into HEAD
namanjain24-sudo 86c53ac
fix: write the grouping set index map as a Substrait switch
namanjain24-sudo b1679d8
docs: describe the switch mapping with what the spec actually says
namanjain24-sudo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
datafusion/substrait/src/logical_plan/consumer/expr/switch.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| use crate::logical_plan::consumer::{SubstraitConsumer, from_literal}; | ||
| use datafusion::common::{DFSchema, substrait_err}; | ||
| use datafusion::logical_expr::{Case, Expr}; | ||
| use substrait::proto::expression::SwitchExpression; | ||
|
|
||
| /// Reads Substrait's [`SwitchExpression`] as a `CASE` over a base expression. | ||
| /// | ||
| /// Substrait defines a [switch] as "an optimized form of a generic if | ||
| /// expression where all conditions are equality to the same value", which is | ||
| /// what `CASE <base> WHEN <value>` is, down to `CaseExpr` evaluating the base | ||
| /// once rather than once per arm. | ||
| /// | ||
| /// [switch]: https://substrait.io/expressions/specialized_record_expressions/#switch-expression | ||
| pub async fn from_switch( | ||
| consumer: &impl SubstraitConsumer, | ||
| switch: &SwitchExpression, | ||
| input_schema: &DFSchema, | ||
| ) -> datafusion::common::Result<Expr> { | ||
| let Some(base) = switch.r#match.as_ref() else { | ||
| return substrait_err!("Switch expression without a match expression"); | ||
| }; | ||
| let expr = Box::new(consumer.consume_expression(base, input_schema).await?); | ||
|
|
||
| let mut when_then_expr = Vec::with_capacity(switch.ifs.len()); | ||
| for arm in &switch.ifs { | ||
| let (Some(value), Some(then)) = (arm.r#if.as_ref(), arm.then.as_ref()) else { | ||
| return substrait_err!( | ||
| "Switch expression arm needs both a value to match and a result" | ||
| ); | ||
| }; | ||
| when_then_expr.push(( | ||
| Box::new(from_literal(consumer, value).await?), | ||
| Box::new(consumer.consume_expression(then, input_schema).await?), | ||
| )); | ||
| } | ||
|
|
||
| let else_expr = match switch.r#else.as_ref() { | ||
| Some(e) => Some(Box::new( | ||
| consumer.consume_expression(e, input_schema).await?, | ||
| )), | ||
| None => None, | ||
| }; | ||
|
|
||
| Ok(Expr::Case(Case { | ||
| expr: Some(expr), | ||
| when_then_expr, | ||
| else_expr, | ||
| })) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.