MCPcopy Create free account
hub / github.com/apache/datafusion / create_cube_physical_expr

Function create_cube_physical_expr

datafusion/core/src/physical_planner.rs:1997–2039  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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>)
1997fn 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>)

Callers 2

test_create_cube_exprFunction · 0.85

Calls 6

get_physical_expr_pairFunction · 0.85
newFunction · 0.85
lenMethod · 0.45
pushMethod · 0.45
into_iterMethod · 0.45

Tested by 1

test_create_cube_exprFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…