diff --git a/datafusion/core/src/physical_planner.rs b/datafusion/core/src/physical_planner.rs index d1d21634815c..f1a99a7714ac 100644 --- a/datafusion/core/src/physical_planner.rs +++ b/datafusion/core/src/physical_planner.rs @@ -654,16 +654,12 @@ impl DefaultPhysicalPlanner { let physical_input_schema = input_exec.schema(); let logical_input_schema = input.as_ref().schema(); let physical_input_schema_from_logical = logical_input_schema.inner(); - // If the physical input schema has only one field and the logical input schema has no fields, we skip the schema check - // This is because the physical plan may add a dummy column to the input schema to represent the row, - // e.g. with test AS (SELECT i as v FROM generate_series(1, 10) t(i)) select count(1) from test WHERE 1 = 1; - if !(options.execution.skip_physical_aggregate_schema_check - || schema_satisfied_by( + + if !options.execution.skip_physical_aggregate_schema_check + && !schema_satisfied_by( physical_input_schema_from_logical, &physical_input_schema, ) - || (physical_input_schema.fields().len() == 1 - && physical_input_schema_from_logical.fields().len() == 0)) { let mut differences = Vec::new(); if physical_input_schema.fields().len() diff --git a/datafusion/functions-table/src/generate_series.rs b/datafusion/functions-table/src/generate_series.rs index 5bb56f28bc8d..ced1a9324cd7 100644 --- a/datafusion/functions-table/src/generate_series.rs +++ b/datafusion/functions-table/src/generate_series.rs @@ -138,12 +138,15 @@ impl TableProvider for GenerateSeriesTable { async fn scan( &self, state: &dyn Session, - _projection: Option<&Vec>, + projection: Option<&Vec>, _filters: &[Expr], _limit: Option, ) -> Result> { let batch_size = state.config_options().execution.batch_size; - + let schema = match projection { + Some(projection) => Arc::new(self.schema.project(projection)?), + None => self.schema.clone() + }; let state = match self.args { // if args have null, then return 0 row GenSeriesArgs::ContainsNull { include_end, name } => GenerateSeriesState { @@ -175,7 +178,7 @@ impl TableProvider for GenerateSeriesTable { }; Ok(Arc::new(LazyMemoryExec::try_new( - self.schema(), + schema, vec![Arc::new(RwLock::new(state))], )?)) }