Skip to content

Commit

Permalink
revert: from_plan keep same schema Agg/Window in #6820
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwener committed Jul 3, 2023
1 parent a08ea21 commit 14d75b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ WITH HEADER ROW
LOCATION '../../testing/data/csv/aggregate_test_100.csv'


statement error DataFusion error: Error during planning: Mismatch between schema and batches
statement ok
CREATE TABLE aggregate_test_100_nullable_by_sql AS
SELECT
*,
Expand All @@ -82,13 +82,15 @@ SELECT
WHEN c3 % 3 != 0 THEN c9
ELSE NULL
END AS n9
FROM aggregate_test_100_by_sql;
FROM aggregate_test_100_by_sql


query error DataFusion error: Error during planning: table 'datafusion\.public\.aggregate_test_100_nullable_by_sql' not found
query III
SELECT
COUNT(*), COUNT(n5), COUNT(n9)
FROM aggregate_test_100_nullable_by_sql
----
100 66 72


########
Expand All @@ -97,5 +99,5 @@ FROM aggregate_test_100_nullable_by_sql
statement ok
DROP TABLE aggregate_test_100_by_sql

statement error DataFusion error: Execution error: Table 'aggregate_test_100_nullable_by_sql' doesn't exist\.
statement ok
DROP TABLE aggregate_test_100_nullable_by_sql
30 changes: 17 additions & 13 deletions datafusion/expr/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,19 +821,23 @@ pub fn from_plan(
input: Arc::new(inputs[0].clone()),
})),
},
LogicalPlan::Window(Window { window_expr, .. }) => {
Ok(LogicalPlan::Window(Window::try_new(
expr[0..window_expr.len()].to_vec(),
Arc::new(inputs[0].clone()),
)?))
}
LogicalPlan::Aggregate(Aggregate { group_expr, .. }) => {
Ok(LogicalPlan::Aggregate(Aggregate::try_new(
Arc::new(inputs[0].clone()),
expr[0..group_expr.len()].to_vec(),
expr[group_expr.len()..].to_vec(),
)?))
}
LogicalPlan::Window(Window {
window_expr,
schema,
..
}) => Ok(LogicalPlan::Window(Window {
input: Arc::new(inputs[0].clone()),
window_expr: expr[0..window_expr.len()].to_vec(),
schema: schema.clone(),
})),
LogicalPlan::Aggregate(Aggregate {
group_expr, schema, ..
}) => Ok(LogicalPlan::Aggregate(Aggregate::try_new_with_schema(
Arc::new(inputs[0].clone()),
expr[0..group_expr.len()].to_vec(),
expr[group_expr.len()..].to_vec(),
schema.clone(),
)?)),
LogicalPlan::Sort(SortPlan { fetch, .. }) => Ok(LogicalPlan::Sort(SortPlan {
expr: expr.to_vec(),
input: Arc::new(inputs[0].clone()),
Expand Down

0 comments on commit 14d75b7

Please sign in to comment.