From 936d21cdd8c11557b57c8009a9ba500545c45144 Mon Sep 17 00:00:00 2001 From: jiacai2050 Date: Tue, 5 Mar 2024 11:38:47 +0800 Subject: [PATCH 1/3] fix: use source schema to find time column instead of projected schema --- .../handle_gapfill/range_predicate.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/iox_query/src/logical_optimizer/handle_gapfill/range_predicate.rs b/iox_query/src/logical_optimizer/handle_gapfill/range_predicate.rs index 1a2cbcc..017a759 100644 --- a/iox_query/src/logical_optimizer/handle_gapfill/range_predicate.rs +++ b/iox_query/src/logical_optimizer/handle_gapfill/range_predicate.rs @@ -4,7 +4,7 @@ use std::ops::{Bound, Range}; use datafusion::{ common::{ tree_node::{TreeNode, TreeNodeVisitor, VisitRecursion}, - DFSchema, + DFField, DFSchema, }, error::Result, logical_expr::{Between, BinaryExpr, LogicalPlan, Operator}, @@ -44,13 +44,22 @@ impl TreeNodeVisitor for TimeRangeVisitor { Ok(VisitRecursion::Continue) } LogicalPlan::TableScan(t) => { + let source_schema = t.source.schema(); + let df_schema = DFSchema::new_with_metadata( + source_schema + .fields() + .iter() + .map(|f| DFField::from(f.clone())) + .collect(), + source_schema.metadata().clone(), + )?; let range = self.range.clone(); let range = t .filters .iter() .flat_map(split_conjunction) .try_fold(range, |range, expr| { - range.with_expr(&t.projected_schema, &self.col, expr) + range.with_expr(&df_schema, &self.col, expr) })?; self.range = range; Ok(VisitRecursion::Continue) From 5605c3ea7c34af6cf2563b88dff3b85b455d4b34 Mon Sep 17 00:00:00 2001 From: jiacai2050 Date: Tue, 5 Mar 2024 17:34:20 +0800 Subject: [PATCH 2/3] fix qualifier --- .../handle_gapfill/range_predicate.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/iox_query/src/logical_optimizer/handle_gapfill/range_predicate.rs b/iox_query/src/logical_optimizer/handle_gapfill/range_predicate.rs index 017a759..bdc5ca9 100644 --- a/iox_query/src/logical_optimizer/handle_gapfill/range_predicate.rs +++ b/iox_query/src/logical_optimizer/handle_gapfill/range_predicate.rs @@ -45,11 +45,19 @@ impl TreeNodeVisitor for TimeRangeVisitor { } LogicalPlan::TableScan(t) => { let source_schema = t.source.schema(); + let qualifier = t.table_name.clone(); let df_schema = DFSchema::new_with_metadata( source_schema .fields() .iter() - .map(|f| DFField::from(f.clone())) + .map(|f| { + DFField::new( + Some(qualifier.clone()), + f.name(), + f.data_type().clone(), + f.is_nullable(), + ) + }) .collect(), source_schema.metadata().clone(), )?; From 86c12247fcca5ca9b6de329f107b973bd42e1de7 Mon Sep 17 00:00:00 2001 From: jiacai2050 Date: Tue, 5 Mar 2024 17:44:24 +0800 Subject: [PATCH 3/3] fix CR --- .../src/logical_optimizer/handle_gapfill/range_predicate.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iox_query/src/logical_optimizer/handle_gapfill/range_predicate.rs b/iox_query/src/logical_optimizer/handle_gapfill/range_predicate.rs index bdc5ca9..74fb70b 100644 --- a/iox_query/src/logical_optimizer/handle_gapfill/range_predicate.rs +++ b/iox_query/src/logical_optimizer/handle_gapfill/range_predicate.rs @@ -45,7 +45,7 @@ impl TreeNodeVisitor for TimeRangeVisitor { } LogicalPlan::TableScan(t) => { let source_schema = t.source.schema(); - let qualifier = t.table_name.clone(); + let qualifier = &t.table_name; let df_schema = DFSchema::new_with_metadata( source_schema .fields()