waynexia commented on code in PR #7382:
URL: https://github.com/apache/arrow-datafusion/pull/7382#discussion_r1304421152
##########
datafusion/substrait/src/logical_plan/producer.rs:
##########
@@ -494,6 +491,75 @@ pub fn operator_to_name(op: Operator) -> &'static str {
}
}
+pub fn parse_flat_grouping_exprs(
+ exprs: &Vec<Expr>,
+ schema: &DFSchemaRef,
+ extension_info: &mut (
+ Vec<extensions::SimpleExtensionDeclaration>,
+ HashMap<String, u32>,
+ ),
+) -> Result<Grouping> {
+ let grouping_expressions = exprs
+ .iter()
+ .map(|e| to_substrait_rex(e, schema, 0, extension_info))
+ .collect::<Result<Vec<_>>>()?;
+ Ok(Grouping {
+ grouping_expressions,
+ })
+}
+
+pub fn to_substrait_groupings(
+ exprs: &Vec<Expr>,
+ schema: &DFSchemaRef,
+ extension_info: &mut (
+ Vec<extensions::SimpleExtensionDeclaration>,
+ HashMap<String, u32>,
+ ),
+) -> Result<Vec<Grouping>> {
+ match exprs.len() {
+ 1 => {
+ match &exprs[0] {
+ Expr::GroupingSet(gs) => {
+ match gs {
+ GroupingSet::Cube(_) =>
Err(DataFusionError::NotImplemented(
+ "GroupingSet CUBE is not yet
supported".to_string(),
+ )),
+ GroupingSet::GroupingSets(sets) => Ok(sets
+ .iter()
+ .map(|set| {
+ parse_flat_grouping_exprs(set, schema,
extension_info)
+ })
+ .collect::<Result<Vec<_>>>()?),
+ GroupingSet::Rollup(set) => {
+ let mut sets: Vec<Vec<Expr>> = vec![vec![]];
+ for i in 0..set.len() {
+ sets.push(set[..=i].to_vec());
+ }
Review Comment:
This looks great. It generates the same result (after `.rev()`) with
`create_rollup_physical_expr`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]