Expand and align a CUBE expression. This is a special case of GROUPING SETS (see )
(
exprs: &[Expr],
input_dfschema: &DFSchema,
input_schema: &Schema,
execution_props: &ExecutionProps,
)
| 1995 | /// Expand and align a CUBE expression. This is a special case of GROUPING SETS |
| 1996 | /// (see <https://www.postgresql.org/docs/current/queries-table-expressions.html#QUERIES-GROUPING-SETS>) |
| 1997 | fn create_cube_physical_expr( |
| 1998 | exprs: &[Expr], |
| 1999 | input_dfschema: &DFSchema, |
| 2000 | input_schema: &Schema, |
| 2001 | execution_props: &ExecutionProps, |
| 2002 | ) -> Result<PhysicalGroupBy> { |
| 2003 | let num_of_exprs = exprs.len(); |
| 2004 | let num_groups = num_of_exprs * num_of_exprs; |
| 2005 | |
| 2006 | let mut null_exprs: Vec<(Arc<dyn PhysicalExpr>, String)> = |
| 2007 | Vec::with_capacity(num_of_exprs); |
| 2008 | let mut all_exprs: Vec<(Arc<dyn PhysicalExpr>, String)> = |
| 2009 | Vec::with_capacity(num_of_exprs); |
| 2010 | |
| 2011 | for expr in exprs { |
| 2012 | null_exprs.push(get_null_physical_expr_pair( |
| 2013 | expr, |
| 2014 | input_dfschema, |
| 2015 | input_schema, |
| 2016 | execution_props, |
| 2017 | )?); |
| 2018 | |
| 2019 | all_exprs.push(get_physical_expr_pair( |
| 2020 | expr, |
| 2021 | input_dfschema, |
| 2022 | execution_props, |
| 2023 | )?) |
| 2024 | } |
| 2025 | |
| 2026 | let mut groups: Vec<Vec<bool>> = Vec::with_capacity(num_groups); |
| 2027 | |
| 2028 | groups.push(vec![false; num_of_exprs]); |
| 2029 | |
| 2030 | for null_count in 1..=num_of_exprs { |
| 2031 | for null_idx in (0..num_of_exprs).combinations(null_count) { |
| 2032 | let mut next_group: Vec<bool> = vec![false; num_of_exprs]; |
| 2033 | null_idx.into_iter().for_each(|i| next_group[i] = true); |
| 2034 | groups.push(next_group); |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | Ok(PhysicalGroupBy::new(all_exprs, null_exprs, groups, true)) |
| 2039 | } |
| 2040 | |
| 2041 | /// Expand and align a ROLLUP expression. This is a special case of GROUPING SETS |
| 2042 | /// (see <https://www.postgresql.org/docs/current/queries-table-expressions.html#QUERIES-GROUPING-SETS>) |
searching dependent graphs…