Skip to content

Commit a619e00

Browse files
authored
fix: aggregation corner case (#15457)
* fix: aggregation corner case * Update generate_series.rs * Update physical_planner.rs * format * Update generate_series.rs
1 parent 28451b5 commit a619e00

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

datafusion/functions-table/src/generate_series.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,15 @@ impl TableProvider for GenerateSeriesTable {
138138
async fn scan(
139139
&self,
140140
state: &dyn Session,
141-
_projection: Option<&Vec<usize>>,
141+
projection: Option<&Vec<usize>>,
142142
_filters: &[Expr],
143143
_limit: Option<usize>,
144144
) -> Result<Arc<dyn ExecutionPlan>> {
145145
let batch_size = state.config_options().execution.batch_size;
146-
146+
let schema = match projection {
147+
Some(projection) => Arc::new(self.schema.project(projection)?),
148+
None => self.schema(),
149+
};
147150
let state = match self.args {
148151
// if args have null, then return 0 row
149152
GenSeriesArgs::ContainsNull { include_end, name } => GenerateSeriesState {
@@ -175,7 +178,7 @@ impl TableProvider for GenerateSeriesTable {
175178
};
176179

177180
Ok(Arc::new(LazyMemoryExec::try_new(
178-
self.schema(),
181+
schema,
179182
vec![Arc::new(RwLock::new(state))],
180183
)?))
181184
}

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6729,3 +6729,26 @@ SELECT a, median(b), arrow_typeof(median(b)) FROM group_median_all_nulls GROUP B
67296729
----
67306730
group0 NULL Int32
67316731
group1 NULL Int32
6732+
6733+
query I
6734+
with test AS (SELECT i as c1, i + 1 as c2 FROM generate_series(1, 10) t(i))
6735+
select count(*) from test WHERE 1 = 1;
6736+
----
6737+
10
6738+
6739+
query I
6740+
with test AS (SELECT i as c1, i + 1 as c2 FROM generate_series(1, 10) t(i))
6741+
select count(c1) from test WHERE 1 = 1;
6742+
----
6743+
10
6744+
6745+
query II rowsort
6746+
with test AS (SELECT i as c1, i + 1 as c2 FROM generate_series(1, 5) t(i))
6747+
select c2, count(*) from test WHERE 1 = 1 group by c2;
6748+
----
6749+
2 1
6750+
3 1
6751+
4 1
6752+
5 1
6753+
6 1
6754+

0 commit comments

Comments
 (0)