Skip to content

Commit aa0c85a

Browse files
committed
reduce stack overhead
1 parent a45765f commit aa0c85a

1 file changed

Lines changed: 64 additions & 28 deletions

File tree

‎datafusion/sql/src/planner.rs‎

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,34 +2332,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
23322332
}
23332333
}
23342334

2335-
SQLExpr::Rollup(exprs) => {
2336-
let args: Result<Vec<_>> = exprs.into_iter().map(|v| {
2337-
if v.len() != 1 {
2338-
Err(DataFusionError::Internal("Tuple expressions are not supported for Rollup expressions".to_string()))
2339-
} else {
2340-
self.sql_expr_to_logical_expr(v[0].clone(), schema, planner_context)
2341-
}
2342-
}).collect();
2343-
Ok(Expr::GroupingSet(GroupingSet::Rollup(args?)))
2344-
}
2345-
2346-
SQLExpr::Cube(exprs) => {
2347-
let args: Result<Vec<_>> = exprs.into_iter().map(|v| {
2348-
if v.len() != 1 {
2349-
Err(DataFusionError::Internal("Tuple expressions not are supported for Cube expressions".to_string()))
2350-
} else {
2351-
self.sql_expr_to_logical_expr(v[0].clone(), schema, planner_context)
2352-
}
2353-
}).collect();
2354-
Ok(Expr::GroupingSet(GroupingSet::Cube(args?)))
2355-
}
2356-
2357-
SQLExpr::GroupingSets(exprs) => {
2358-
let args: Result<Vec<Vec<_>>> = exprs.into_iter().map(|v| {
2359-
v.into_iter().map(|e| self.sql_expr_to_logical_expr(e, schema, planner_context)).collect()
2360-
}).collect();
2361-
Ok(Expr::GroupingSet(GroupingSet::GroupingSets(args?)))
2362-
}
2335+
SQLExpr::Rollup(exprs) => self.sql_rollup_to_expr(exprs, schema, planner_context),
2336+
SQLExpr::Cube(exprs) => self.sql_cube_to_expr(exprs,schema, planner_context),
2337+
SQLExpr::GroupingSets(exprs) => self.sql_grouping_sets_to_expr(exprs, schema, planner_context),
23632338

23642339
SQLExpr::Floor { expr, field: _field } => {
23652340
let fun = BuiltinScalarFunction::Floor;
@@ -2401,6 +2376,67 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
24012376
})
24022377
}
24032378

2379+
fn sql_rollup_to_expr(
2380+
&self,
2381+
exprs: Vec<Vec<SQLExpr>>,
2382+
schema: &DFSchema,
2383+
planner_context: &mut PlannerContext,
2384+
) -> Result<Expr> {
2385+
let args: Result<Vec<_>> = exprs
2386+
.into_iter()
2387+
.map(|v| {
2388+
if v.len() != 1 {
2389+
Err(DataFusionError::Internal(
2390+
"Tuple expressions are not supported for Rollup expressions"
2391+
.to_string(),
2392+
))
2393+
} else {
2394+
self.sql_expr_to_logical_expr(v[0].clone(), schema, planner_context)
2395+
}
2396+
})
2397+
.collect();
2398+
Ok(Expr::GroupingSet(GroupingSet::Rollup(args?)))
2399+
}
2400+
2401+
fn sql_cube_to_expr(
2402+
&self,
2403+
exprs: Vec<Vec<SQLExpr>>,
2404+
schema: &DFSchema,
2405+
planner_context: &mut PlannerContext,
2406+
) -> Result<Expr> {
2407+
let args: Result<Vec<_>> = exprs
2408+
.into_iter()
2409+
.map(|v| {
2410+
if v.len() != 1 {
2411+
Err(DataFusionError::Internal(
2412+
"Tuple expressions not are supported for Cube expressions"
2413+
.to_string(),
2414+
))
2415+
} else {
2416+
self.sql_expr_to_logical_expr(v[0].clone(), schema, planner_context)
2417+
}
2418+
})
2419+
.collect();
2420+
Ok(Expr::GroupingSet(GroupingSet::Cube(args?)))
2421+
}
2422+
2423+
fn sql_grouping_sets_to_expr(
2424+
&self,
2425+
exprs: Vec<Vec<SQLExpr>>,
2426+
schema: &DFSchema,
2427+
planner_context: &mut PlannerContext,
2428+
) -> Result<Expr> {
2429+
let args: Result<Vec<Vec<_>>> = exprs
2430+
.into_iter()
2431+
.map(|v| {
2432+
v.into_iter()
2433+
.map(|e| self.sql_expr_to_logical_expr(e, schema, planner_context))
2434+
.collect()
2435+
})
2436+
.collect();
2437+
Ok(Expr::GroupingSet(GroupingSet::GroupingSets(args?)))
2438+
}
2439+
24042440
fn parse_exists_subquery(
24052441
&self,
24062442
subquery: Query,

0 commit comments

Comments
 (0)