From 2dfd8ee607863c46c5a1612bfb4da5326ba58f78 Mon Sep 17 00:00:00 2001 From: leiysky Date: Sat, 30 Apr 2022 23:37:10 +0800 Subject: [PATCH 1/2] decouple Function with DataField Signed-off-by: leiysky --- .../scalars/arithmetics/arithmetic_modulo.rs | 6 +-- .../scalars/arithmetics/binary_arithmetic.rs | 6 +-- .../scalars/arithmetics/unary_arithmetic.rs | 8 +--- .../src/scalars/comparisons/comparison.rs | 37 ++++++-------- .../functions/src/scalars/conditionals/if.rs | 48 ++++++++----------- .../src/scalars/conditionals/in_basic.rs | 23 ++++----- .../src/scalars/conditionals/is_not_null.rs | 4 +- .../src/scalars/conditionals/is_null.rs | 4 +- .../src/scalars/contexts/current_user.rs | 7 +-- .../src/scalars/contexts/database.rs | 7 +-- .../functions/src/scalars/contexts/version.rs | 5 +- .../src/scalars/dates/interval_function.rs | 9 +--- common/functions/src/scalars/dates/now.rs | 5 +- .../src/scalars/dates/number_function.rs | 20 +++----- .../src/scalars/dates/round_function.rs | 7 ++- .../src/scalars/dates/simple_date.rs | 4 +- .../functions/src/scalars/dates/week_date.rs | 10 ++-- .../functions/src/scalars/expressions/cast.rs | 6 +-- .../src/scalars/expressions/cast_with_type.rs | 9 ++-- common/functions/src/scalars/function.rs | 3 +- .../functions/src/scalars/function_adapter.rs | 19 +++----- .../src/scalars/function_monotonic.rs | 10 ++-- .../src/scalars/hashes/city64_with_seed.rs | 14 +++--- .../functions/src/scalars/hashes/hash_base.rs | 4 +- .../functions/src/scalars/hashes/sha2hash.rs | 12 ++--- common/functions/src/scalars/logics/and.rs | 2 +- common/functions/src/scalars/logics/logic.rs | 4 +- common/functions/src/scalars/logics/macros.rs | 6 +-- common/functions/src/scalars/logics/not.rs | 6 +-- common/functions/src/scalars/logics/or.rs | 2 +- common/functions/src/scalars/logics/xor.rs | 8 ++-- common/functions/src/scalars/maths/abs.rs | 22 ++++----- common/functions/src/scalars/maths/angle.rs | 4 +- common/functions/src/scalars/maths/ceil.rs | 4 +- common/functions/src/scalars/maths/exp.rs | 4 +- common/functions/src/scalars/maths/floor.rs | 4 +- common/functions/src/scalars/maths/log.rs | 6 +-- common/functions/src/scalars/maths/pi.rs | 2 +- common/functions/src/scalars/maths/pow.rs | 4 +- common/functions/src/scalars/maths/random.rs | 4 +- common/functions/src/scalars/maths/round.rs | 18 +++---- common/functions/src/scalars/maths/sign.rs | 11 ++--- common/functions/src/scalars/maths/sqrt.rs | 4 +- .../src/scalars/maths/trigonometric.rs | 18 +++---- common/functions/src/scalars/others/exists.rs | 8 ++-- common/functions/src/scalars/others/ignore.rs | 3 +- .../functions/src/scalars/others/inet_aton.rs | 4 +- .../functions/src/scalars/others/inet_ntoa.rs | 10 ++-- .../others/running_difference_function.rs | 12 ++--- common/functions/src/scalars/others/sleep.rs | 7 +-- .../functions/src/scalars/others/type_of.rs | 6 +-- .../scalars/semi_structureds/check_json.rs | 6 +-- .../src/scalars/semi_structureds/get.rs | 8 ++-- .../json_extract_path_text.rs | 8 ++-- .../scalars/semi_structureds/parse_json.rs | 8 ++-- common/functions/src/scalars/strings/bin.rs | 10 ++-- common/functions/src/scalars/strings/char_.rs | 3 +- .../functions/src/scalars/strings/concat.rs | 4 +- .../src/scalars/strings/concat_ws.rs | 28 +++++------ common/functions/src/scalars/strings/elt.rs | 20 ++++---- .../src/scalars/strings/export_set.rs | 14 +++--- common/functions/src/scalars/strings/field.rs | 6 +-- .../src/scalars/strings/find_in_set.rs | 6 +-- .../functions/src/scalars/strings/format.rs | 4 +- common/functions/src/scalars/strings/hex.rs | 10 ++-- .../functions/src/scalars/strings/insert.rs | 10 ++-- .../src/scalars/strings/leftright.rs | 6 +-- .../functions/src/scalars/strings/locate.rs | 8 ++-- common/functions/src/scalars/strings/oct.rs | 8 ++-- common/functions/src/scalars/strings/pad.rs | 8 ++-- .../src/scalars/strings/regexp_instr.rs | 25 ++++------ .../src/scalars/strings/regexp_like.rs | 8 ++-- .../src/scalars/strings/regexp_replace.rs | 24 ++++------ .../src/scalars/strings/regexp_substr.rs | 24 ++++------ .../functions/src/scalars/strings/repeat.rs | 8 ++-- .../functions/src/scalars/strings/replace.rs | 8 ++-- common/functions/src/scalars/strings/space.rs | 4 +- .../functions/src/scalars/strings/strcmp.rs | 6 +-- .../src/scalars/strings/string2number.rs | 6 +-- .../src/scalars/strings/string2string.rs | 6 +-- .../src/scalars/strings/substring.rs | 10 ++-- .../src/scalars/strings/substring_index.rs | 10 ++-- common/functions/src/scalars/strings/unhex.rs | 10 ++-- common/functions/src/scalars/tuples/tuple.rs | 10 ++-- .../src/scalars/uuids/uuid_creator.rs | 5 +- .../src/scalars/uuids/uuid_verifier.rs | 7 +-- .../src/plan_expression_monotonicity.rs | 31 +++++------- common/streams/src/stream_cast.rs | 11 ++--- query/src/common/expression_evaluator.rs | 41 +++------------- .../transforms/transform_cast_schema.rs | 12 ++--- .../transform_expression_executor.rs | 2 +- query/src/storages/index/range_filter.rs | 4 +- 92 files changed, 395 insertions(+), 522 deletions(-) diff --git a/common/functions/src/scalars/arithmetics/arithmetic_modulo.rs b/common/functions/src/scalars/arithmetics/arithmetic_modulo.rs index 56a5f748392a..43148a44d1af 100644 --- a/common/functions/src/scalars/arithmetics/arithmetic_modulo.rs +++ b/common/functions/src/scalars/arithmetics/arithmetic_modulo.rs @@ -81,11 +81,11 @@ where fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { - let lhs = columns[0].column(); - let rhs = columns[1].column(); + let lhs = &columns[0]; + let rhs = &columns[1]; match (lhs.is_const(), rhs.is_const()) { (false, true) => { let left: &::ColumnType = unsafe { Series::static_cast(lhs) }; diff --git a/common/functions/src/scalars/arithmetics/binary_arithmetic.rs b/common/functions/src/scalars/arithmetics/binary_arithmetic.rs index 14454b01422f..b9af18287278 100644 --- a/common/functions/src/scalars/arithmetics/binary_arithmetic.rs +++ b/common/functions/src/scalars/arithmetics/binary_arithmetic.rs @@ -77,12 +77,12 @@ where fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { let col = scalar_binary_op( - columns[0].column(), - columns[1].column(), + &columns[0], + &columns[1], self.func.clone(), &mut EvalContext::default(), )?; diff --git a/common/functions/src/scalars/arithmetics/unary_arithmetic.rs b/common/functions/src/scalars/arithmetics/unary_arithmetic.rs index 9b6b1b28fcfa..de59ff4ac76c 100644 --- a/common/functions/src/scalars/arithmetics/unary_arithmetic.rs +++ b/common/functions/src/scalars/arithmetics/unary_arithmetic.rs @@ -72,14 +72,10 @@ where fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { - let col = scalar_unary_op( - columns[0].column(), - self.func.clone(), - &mut EvalContext::default(), - )?; + let col = scalar_unary_op(&columns[0], self.func.clone(), &mut EvalContext::default())?; Ok(Arc::new(col)) } diff --git a/common/functions/src/scalars/comparisons/comparison.rs b/common/functions/src/scalars/comparisons/comparison.rs index d59c99d3f21f..04604269c39b 100644 --- a/common/functions/src/scalars/comparisons/comparison.rs +++ b/common/functions/src/scalars/comparisons/comparison.rs @@ -28,7 +28,7 @@ use num::traits::AsPrimitive; use super::utils::*; use crate::scalars::assert_string; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::primitive_simd_op_boolean; use crate::scalars::scalar_binary_op; use crate::scalars::ComparisonEqFunction; @@ -94,7 +94,7 @@ impl Function for ComparisonFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { let col = self.func.eval(&columns[0], &columns[1])?; @@ -236,7 +236,7 @@ pub trait ComparisonImpl: Sync + Send + Clone + 'static { } pub trait ComparisonExpression: Sync + Send { - fn eval(&self, l: &ColumnWithField, r: &ColumnWithField) -> Result; + fn eval(&self, l: &ColumnRef, r: &ColumnRef) -> Result; } pub struct ComparisonScalarImpl { @@ -261,13 +261,8 @@ where R: Scalar + Send + Sync + Clone, F: Fn(L::RefType<'_>, R::RefType<'_>, &mut EvalContext) -> bool + Send + Sync + Clone, { - fn eval(&self, l: &ColumnWithField, r: &ColumnWithField) -> Result { - scalar_binary_op( - l.column(), - r.column(), - self.func.clone(), - &mut EvalContext::default(), - ) + fn eval(&self, l: &ColumnRef, r: &ColumnRef) -> Result { + scalar_binary_op(l, r, self.func.clone(), &mut EvalContext::default()) } } @@ -298,17 +293,17 @@ where T: PrimitiveType + comparison::Simd8 + Send + Sync + Clone, F: Fn(T::Simd, T::Simd) -> u8 + Send + Sync + Clone, { - fn eval(&self, l: &ColumnWithField, r: &ColumnWithField) -> Result { - let lhs = if self.need_cast && l.data_type() != &self.least_supertype { - cast_column_field(l, &self.least_supertype)? + fn eval(&self, l: &ColumnRef, r: &ColumnRef) -> Result { + let lhs = if self.need_cast && l.data_type() != self.least_supertype { + cast_column(l, &self.least_supertype)? } else { - l.column().clone() + l.clone() }; - let rhs = if self.need_cast && r.data_type() != &self.least_supertype { - cast_column_field(r, &self.least_supertype)? + let rhs = if self.need_cast && r.data_type() != self.least_supertype { + cast_column(r, &self.least_supertype)? } else { - r.column().clone() + r.clone() }; primitive_simd_op_boolean::(&lhs, &rhs, self.func.clone()) } @@ -327,9 +322,7 @@ impl ComparisonBooleanImpl { } impl ComparisonExpression for ComparisonBooleanImpl { - fn eval(&self, l: &ColumnWithField, r: &ColumnWithField) -> Result { - let lhs = l.column(); - let rhs = r.column(); + fn eval(&self, lhs: &ColumnRef, rhs: &ColumnRef) -> Result { let res = match (lhs.is_const(), rhs.is_const()) { (false, false) => { let lhs: &BooleanColumn = Series::check_get(lhs)?; @@ -369,9 +362,7 @@ impl ComparisonStringImpl { } impl ComparisonExpression for ComparisonStringImpl { - fn eval(&self, l: &ColumnWithField, r: &ColumnWithField) -> Result { - let lhs = l.column(); - let rhs = r.column(); + fn eval(&self, lhs: &ColumnRef, rhs: &ColumnRef) -> Result { let res = match rhs.is_const() { true => { let lhs: &StringColumn = Series::check_get(lhs)?; diff --git a/common/functions/src/scalars/conditionals/if.rs b/common/functions/src/scalars/conditionals/if.rs index 91325f319f95..753f9a2e8e9c 100644 --- a/common/functions/src/scalars/conditionals/if.rs +++ b/common/functions/src/scalars/conditionals/if.rs @@ -20,7 +20,7 @@ use common_datavalues::type_coercion::aggregate_types; use common_datavalues::with_match_scalar_type; use common_exception::Result; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; @@ -53,18 +53,14 @@ impl IfFunction { } // handle cond is const or nullable or null column - fn eval_cond_const( - &self, - cond_col: &ColumnRef, - columns: &ColumnsWithField, - ) -> Result { + fn eval_cond_const(&self, cond_col: &ColumnRef, columns: &[ColumnRef]) -> Result { debug_assert!(cond_col.is_const()); // whether nullable or not, we can use viewer to make it let cond_viewer = bool::try_create_viewer(cond_col)?; if cond_viewer.value_at(0) { - return Ok(columns[0].column().clone()); + return Ok(columns[0].clone()); } else { - return Ok(columns[1].column().clone()); + return Ok(columns[1].clone()); } } @@ -75,18 +71,18 @@ impl IfFunction { fn eval_const( &self, cond_col: &BooleanColumn, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - debug_assert!(columns[0].column().is_const() || columns[1].column().is_const()); - let (lhs_col, rhs_col, reverse) = if columns[0].column().is_const() { + debug_assert!(columns[0].is_const() || columns[1].is_const()); + let (lhs_col, rhs_col, reverse) = if columns[0].is_const() { (&columns[0], &columns[1], false) } else { (&columns[1], &columns[0], true) }; - let lhs = cast_column_field(lhs_col, &self.least_supertype)?; - let rhs = cast_column_field(rhs_col, &self.least_supertype)?; + let lhs = cast_column(lhs_col, &self.least_supertype)?; + let rhs = cast_column(rhs_col, &self.least_supertype)?; let type_id = remove_nullable(&lhs.data_type()).data_type_id(); @@ -110,7 +106,7 @@ impl IfFunction { } } return Ok(builder.build(input_rows)); - }else { + } else { for (predicate, (row, r_val)) in iter { if predicate { builder.append(l_val, true); @@ -179,14 +175,14 @@ impl IfFunction { fn eval_nullable( &self, cond_col: &BooleanColumn, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { let lhs_col = &columns[0]; let rhs_col = &columns[1]; - let lhs = cast_column_field(lhs_col, &self.least_supertype)?; - let rhs = cast_column_field(rhs_col, &self.least_supertype)?; + let lhs = cast_column(lhs_col, &self.least_supertype)?; + let rhs = cast_column(rhs_col, &self.least_supertype)?; let type_id = remove_nullable(&self.least_supertype).data_type_id(); @@ -213,16 +209,12 @@ impl IfFunction { } // handle when both are not nullable or const - fn eval_generic( - &self, - cond_col: &BooleanColumn, - columns: &ColumnsWithField, - ) -> Result { + fn eval_generic(&self, cond_col: &BooleanColumn, columns: &[ColumnRef]) -> Result { let lhs_col = &columns[0]; let rhs_col = &columns[1]; - let lhs = cast_column_field(lhs_col, &self.least_supertype)?; - let rhs = cast_column_field(rhs_col, &self.least_supertype)?; + let lhs = cast_column(lhs_col, &self.least_supertype)?; + let rhs = cast_column(rhs_col, &self.least_supertype)?; debug_assert!(!self.least_supertype.is_nullable()); let type_id = self.least_supertype.data_type_id(); @@ -257,10 +249,10 @@ impl Function for IfFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let cond_col = columns[0].column(); + let cond_col = &columns[0]; let cond_col = DataBlock::cast_to_nonull_boolean(cond_col)?; // 1. fast path for cond nullable or const or null column @@ -271,13 +263,13 @@ impl Function for IfFunction { let cond_col = Series::check_get_scalar::(&cond_col)?; // 2. handle when lhs / rhs is const - if columns[1].column().is_const() || columns[2].column().is_const() { + if columns[1].is_const() || columns[2].is_const() { return self.eval_const(cond_col, &columns[1..], input_rows); } // 3. handle nullable column let whether_nullable = |col: &ColumnRef| col.is_nullable() || col.data_type().is_null(); - if whether_nullable(columns[1].column()) || whether_nullable(columns[2].column()) { + if whether_nullable(&columns[1]) || whether_nullable(&columns[2]) { return self.eval_nullable(cond_col, &columns[1..], input_rows); } diff --git a/common/functions/src/scalars/conditionals/in_basic.rs b/common/functions/src/scalars/conditionals/in_basic.rs index 3bd7fe771e19..6cdd8332b3ae 100644 --- a/common/functions/src/scalars/conditionals/in_basic.rs +++ b/common/functions/src/scalars/conditionals/in_basic.rs @@ -21,7 +21,7 @@ use common_exception::ErrorCode; use common_exception::Result; use ordered_float::OrderedFloat; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; @@ -63,7 +63,7 @@ macro_rules! scalar_contains { let mut builder: ColumnBuilder = ColumnBuilder::with_capacity($ROWS); let mut vals_set = HashSet::with_capacity($ROWS - 1); for col in &$COLUMNS[1..] { - let col = cast_column_field(col, &$CAST_TYPE)?; + let col = cast_column(col, &$CAST_TYPE)?; let col_viewer = $T::try_create_viewer(&col)?; if col_viewer.valid_at(0) { let val = col_viewer.value_at(0).to_owned_scalar(); @@ -85,7 +85,7 @@ macro_rules! float_contains { let mut builder: ColumnBuilder = ColumnBuilder::with_capacity($ROWS); let mut vals_set = HashSet::with_capacity($ROWS - 1); for col in &$COLUMNS[1..] { - let col = cast_column_field(col, &$CAST_TYPE)?; + let col = cast_column(col, &$CAST_TYPE)?; let col_viewer = $T::try_create_viewer(&col)?; if col_viewer.valid_at(0) { let val = col_viewer.value_at(0); @@ -117,7 +117,7 @@ impl Function for InFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { if self.is_null { @@ -125,20 +125,15 @@ impl Function for InFunction { return Ok(col); } - let types: Vec = columns.iter().map(|col| col.column().data_type()).collect(); + let types: Vec = columns.iter().map(|col| col.data_type()).collect(); - let least_super_dt = if columns[0] - .field() - .data_type() - .data_type_id() - .is_date_or_date_time() - { + let least_super_dt = if columns[0].data_type().data_type_id().is_date_or_date_time() { match columns[1..] .iter() - .map(|column| column.field().data_type().data_type_id()) + .map(|column| column.data_type().data_type_id()) .all(|t| t.is_string() || t.is_date_or_date_time()) { - true => columns[0].field().data_type().clone(), + true => columns[0].data_type().clone(), false => { return Result::Err(ErrorCode::BadDataValueType("test")); } @@ -148,7 +143,7 @@ impl Function for InFunction { }; let least_super_type_id = remove_nullable(&least_super_dt).data_type_id(); - let input_col = cast_column_field(&columns[0], &least_super_dt)?; + let input_col = cast_column(&columns[0], &least_super_dt)?; match least_super_type_id { TypeID::Boolean => { diff --git a/common/functions/src/scalars/conditionals/is_not_null.rs b/common/functions/src/scalars/conditionals/is_not_null.rs index 57dca15598ab..7321a1b44e51 100644 --- a/common/functions/src/scalars/conditionals/is_not_null.rs +++ b/common/functions/src/scalars/conditionals/is_not_null.rs @@ -61,10 +61,10 @@ impl Function for IsNotNullFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let (all_null, validity) = columns[0].column().validity(); + let (all_null, validity) = columns[0].validity(); if all_null { return Ok(ConstColumn::new(Series::from_data(vec![false]), input_rows).arc()); } diff --git a/common/functions/src/scalars/conditionals/is_null.rs b/common/functions/src/scalars/conditionals/is_null.rs index 52dd6d101401..026eeef528fc 100644 --- a/common/functions/src/scalars/conditionals/is_null.rs +++ b/common/functions/src/scalars/conditionals/is_null.rs @@ -61,10 +61,10 @@ impl Function for IsNullFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let (all_null, validity) = columns[0].column().validity(); + let (all_null, validity) = columns[0].validity(); if all_null { return Ok(ConstColumn::new(Series::from_data(vec![true]), input_rows).arc()); } diff --git a/common/functions/src/scalars/contexts/current_user.rs b/common/functions/src/scalars/contexts/current_user.rs index c19721286eb7..8539ebaf1bca 100644 --- a/common/functions/src/scalars/contexts/current_user.rs +++ b/common/functions/src/scalars/contexts/current_user.rs @@ -14,6 +14,7 @@ use std::fmt; +use common_datavalues::ColumnRef; use common_datavalues::DataTypeImpl; use common_datavalues::StringType; use common_exception::Result; @@ -52,10 +53,10 @@ impl Function for CurrentUserFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, - ) -> Result { - Ok(columns[0].column().clone()) + ) -> Result { + Ok(columns[0].clone()) } } diff --git a/common/functions/src/scalars/contexts/database.rs b/common/functions/src/scalars/contexts/database.rs index 2d8811798fc1..308a1752c374 100644 --- a/common/functions/src/scalars/contexts/database.rs +++ b/common/functions/src/scalars/contexts/database.rs @@ -14,6 +14,7 @@ use std::fmt; +use common_datavalues::ColumnRef; use common_datavalues::DataTypeImpl; use common_datavalues::StringType; use common_exception::Result; @@ -53,10 +54,10 @@ impl Function for DatabaseFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, - ) -> Result { - Ok(columns[0].column().clone()) + ) -> Result { + Ok(columns[0].clone()) } } diff --git a/common/functions/src/scalars/contexts/version.rs b/common/functions/src/scalars/contexts/version.rs index 10c1e59f6308..f03d05c881c1 100644 --- a/common/functions/src/scalars/contexts/version.rs +++ b/common/functions/src/scalars/contexts/version.rs @@ -14,6 +14,7 @@ use std::fmt; +use common_datavalues::ColumnRef; use common_datavalues::DataTypeImpl; use common_datavalues::StringType; use common_exception::Result; @@ -56,10 +57,10 @@ impl Function for VersionFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { - Ok(columns[0].column().clone()) + Ok(columns[0].clone()) } } diff --git a/common/functions/src/scalars/dates/interval_function.rs b/common/functions/src/scalars/dates/interval_function.rs index 72bc4244a646..d6b6f22c0275 100644 --- a/common/functions/src/scalars/dates/interval_function.rs +++ b/common/functions/src/scalars/dates/interval_function.rs @@ -142,17 +142,12 @@ where fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { // Todo(zhyass): define the ctx out of the eval. let mut ctx = EvalContext::new(self.factor, self.precision, None); - let col = scalar_binary_op( - columns[0].column(), - columns[1].column(), - self.func.clone(), - &mut ctx, - )?; + let col = scalar_binary_op(&columns[0], &columns[1], self.func.clone(), &mut ctx)?; let col = Arc::new(col).arc(); let x = col.clone(); if O::get_type_id() == TypeID::Date { diff --git a/common/functions/src/scalars/dates/now.rs b/common/functions/src/scalars/dates/now.rs index 9c01d15c1f70..50c7d88d8bbe 100644 --- a/common/functions/src/scalars/dates/now.rs +++ b/common/functions/src/scalars/dates/now.rs @@ -43,6 +43,7 @@ impl NowFunction { .features(FunctionFeatures::default()) } } + impl Function for NowFunction { fn name(&self) -> &str { self.display_name.as_str() @@ -55,9 +56,9 @@ impl Function for NowFunction { fn eval( &self, _func_ctx: FunctionContext, - _columns: &common_datavalues::ColumnsWithField, + _columns: &[ColumnRef], input_rows: usize, - ) -> Result { + ) -> Result { let utc: DateTime = Utc::now(); let value = utc.timestamp_micros(); let column = Series::from_data(&[value]); diff --git a/common/functions/src/scalars/dates/number_function.rs b/common/functions/src/scalars/dates/number_function.rs index fc6b071d4b65..2fe4152979bd 100644 --- a/common/functions/src/scalars/dates/number_function.rs +++ b/common/functions/src/scalars/dates/number_function.rs @@ -357,10 +357,10 @@ where fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, - ) -> Result { - let type_id = columns[0].field().data_type().data_type_id(); + ) -> Result { + let type_id = columns[0].data_type().data_type_id(); let number_array = match type_id { TypeID::Date => { @@ -368,11 +368,8 @@ where let date_time = Utc.timestamp(v as i64 * 24 * 3600, 0_u32); T::to_number(date_time) }; - let col = scalar_unary_op::( - columns[0].column(), - func, - &mut EvalContext::default(), - )?; + let col = + scalar_unary_op::(&columns[0], func, &mut EvalContext::default())?; Ok(col.arc()) } TypeID::Timestamp => { @@ -380,11 +377,8 @@ where let date_time = Utc.timestamp(v / 1_000_000, 0_u32); T::to_number(date_time) }; - let col = scalar_unary_op::( - columns[0].column(), - func, - &mut EvalContext::default(), - )?; + let col = + scalar_unary_op::(&columns[0], func, &mut EvalContext::default())?; Ok(col.arc()) } other => Result::Err(ErrorCode::IllegalDataType(format!( diff --git a/common/functions/src/scalars/dates/round_function.rs b/common/functions/src/scalars/dates/round_function.rs index 0066077f0db8..d32a7113c59d 100644 --- a/common/functions/src/scalars/dates/round_function.rs +++ b/common/functions/src/scalars/dates/round_function.rs @@ -74,12 +74,11 @@ impl Function for RoundFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, - ) -> Result { + ) -> Result { let func = |val: i64, _ctx: &mut EvalContext| self.execute(val); - let col = - scalar_unary_op::(columns[0].column(), func, &mut EvalContext::default())?; + let col = scalar_unary_op::(&columns[0], func, &mut EvalContext::default())?; for micros in col.iter() { let _ = check_timestamp(*micros)?; } diff --git a/common/functions/src/scalars/dates/simple_date.rs b/common/functions/src/scalars/dates/simple_date.rs index 557d85d96c85..f4eace5e3af2 100644 --- a/common/functions/src/scalars/dates/simple_date.rs +++ b/common/functions/src/scalars/dates/simple_date.rs @@ -107,9 +107,9 @@ where T: NoArgDateFunction + Clone + Sync + Send + 'static fn eval( &self, _func_ctx: FunctionContext, - _columns: &common_datavalues::ColumnsWithField, + _columns: &[ColumnRef], input_rows: usize, - ) -> Result { + ) -> Result { let value = T::execute(); let column = Series::from_data(&[value as i32]); Ok(Arc::new(ConstColumn::new(column, input_rows))) diff --git a/common/functions/src/scalars/dates/week_date.rs b/common/functions/src/scalars/dates/week_date.rs index 044f6f893afc..0d2bafa66e7a 100644 --- a/common/functions/src/scalars/dates/week_date.rs +++ b/common/functions/src/scalars/dates/week_date.rs @@ -125,19 +125,19 @@ where fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { let mut mode = 0; if columns.len() > 1 { - if input_rows != 1 && !columns[1].column().is_const() { + if input_rows != 1 && !columns[1].is_const() { return Err(ErrorCode::BadArguments( "Expected constant column for the second argument, a constant mode from 0-9" .to_string(), )); } - let week_mode = columns[1].column().get_u64(0)?; + let week_mode = columns[1].get_u64(0)?; if !(0..=9).contains(&week_mode) { return Err(ErrorCode::BadArguments(format!( "The parameter:{} range is abnormal, it should be between 0-9", @@ -149,7 +149,7 @@ where match columns[0].data_type().data_type_id() { TypeID::Date => { - let col: &Int32Column = Series::check_get(columns[0].column())?; + let col: &Int32Column = Series::check_get(&columns[0])?; let iter = col.scalar_iter().map(|v| { let date_time = Utc.timestamp(v as i64 * 24 * 3600, 0_u32); T::to_number(date_time, mode) @@ -162,7 +162,7 @@ where Ok(col) } TypeID::Timestamp => { - let col: &Int64Column = Series::check_get(columns[0].column())?; + let col: &Int64Column = Series::check_get(&columns[0])?; let iter = col.scalar_iter().map(|v| { let date_time = Utc.timestamp(v / 1_000_000, 0_u32); T::to_number(date_time, mode) diff --git a/common/functions/src/scalars/expressions/cast.rs b/common/functions/src/scalars/expressions/cast.rs index cd28f25fd84a..c64125259fe9 100644 --- a/common/functions/src/scalars/expressions/cast.rs +++ b/common/functions/src/scalars/expressions/cast.rs @@ -17,7 +17,7 @@ use std::fmt; use common_datavalues::prelude::*; use common_exception::Result; -use super::cast_with_type::cast_column_field; +use super::cast_with_type::cast_column; use crate::scalars::function::Function; use crate::scalars::FunctionContext; @@ -70,10 +70,10 @@ impl Function for CastFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { - cast_column_field(&columns[0], &self.cast_type) + cast_column(&columns[0], &self.cast_type) } } diff --git a/common/functions/src/scalars/expressions/cast_with_type.rs b/common/functions/src/scalars/expressions/cast_with_type.rs index 40260535116d..334f794c36d9 100644 --- a/common/functions/src/scalars/expressions/cast_with_type.rs +++ b/common/functions/src/scalars/expressions/cast_with_type.rs @@ -62,13 +62,10 @@ impl CastOptions { } } -pub fn cast_column_field( - column_with_field: &ColumnWithField, - data_type: &DataTypeImpl, -) -> Result { +pub fn cast_column(column: &ColumnRef, data_type: &DataTypeImpl) -> Result { cast_with_type( - column_with_field.column(), - column_with_field.data_type(), + column, + &column.data_type(), data_type, &DEFAULT_CAST_OPTIONS, ) diff --git a/common/functions/src/scalars/function.rs b/common/functions/src/scalars/function.rs index 7e33f67845d8..0bfbe03e88f2 100644 --- a/common/functions/src/scalars/function.rs +++ b/common/functions/src/scalars/function.rs @@ -15,7 +15,6 @@ use std::fmt; use common_datavalues::ColumnRef; -use common_datavalues::ColumnsWithField; use common_datavalues::DataTypeImpl; use common_exception::Result; use dyn_clone::DynClone; @@ -57,7 +56,7 @@ pub trait Function: fmt::Display + Sync + Send + DynClone { fn eval( &self, _func_ctx: FunctionContext, - _columns: &ColumnsWithField, + _columns: &[ColumnRef], _input_rows: usize, ) -> Result; diff --git a/common/functions/src/scalars/function_adapter.rs b/common/functions/src/scalars/function_adapter.rs index 1e227ee4f1af..550124709e1c 100644 --- a/common/functions/src/scalars/function_adapter.rs +++ b/common/functions/src/scalars/function_adapter.rs @@ -22,10 +22,7 @@ use common_datavalues::remove_nullable; use common_datavalues::wrap_nullable; use common_datavalues::Column; use common_datavalues::ColumnRef; -use common_datavalues::ColumnWithField; -use common_datavalues::ColumnsWithField; use common_datavalues::ConstColumn; -use common_datavalues::DataField; use common_datavalues::DataType; use common_datavalues::DataTypeImpl; use common_datavalues::NullColumn; @@ -103,7 +100,7 @@ impl Function for FunctionAdapter { fn eval( &self, func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { if self.inner.is_none() { @@ -117,14 +114,13 @@ impl Function for FunctionAdapter { // is there nullable constant? Did not consider this case // unwrap constant - if self.passthrough_constant() && columns.iter().all(|v| v.column().is_const()) { + if self.passthrough_constant() && columns.iter().all(|v| v.is_const()) { let columns = columns .iter() - .map(|v| { - let c = v.column(); + .map(|c| { let c: &ConstColumn = unsafe { Series::static_cast(c) }; - ColumnWithField::new(c.inner().clone(), v.field().clone()) + c.inner().clone() }) .collect::>(); @@ -145,7 +141,7 @@ impl Function for FunctionAdapter { let mut input = Vec::with_capacity(columns.len()); for v in columns.iter() { - let (is_all_null, valid) = v.column().validity(); + let (is_all_null, valid) = v.validity(); if is_all_null { // If only null, return null directly. let inner_type = remove_nullable(&inner.return_type()); @@ -157,10 +153,7 @@ impl Function for FunctionAdapter { } validity = combine_validities_2(validity.clone(), valid.cloned()); - let ty = remove_nullable(v.data_type()); - let f = v.field(); - let col = Series::remove_nullable(v.column()); - let col = ColumnWithField::new(col, DataField::new(f.name(), ty)); + let col = Series::remove_nullable(v); input.push(col); } diff --git a/common/functions/src/scalars/function_monotonic.rs b/common/functions/src/scalars/function_monotonic.rs index 43e302d1ad85..2e05e560baa9 100644 --- a/common/functions/src/scalars/function_monotonic.rs +++ b/common/functions/src/scalars/function_monotonic.rs @@ -16,7 +16,7 @@ use common_datavalues::prelude::*; use common_exception::ErrorCode; use common_exception::Result; -use super::cast_column_field; +use super::cast_column; #[derive(Clone)] pub struct Monotonicity { @@ -34,9 +34,9 @@ pub struct Monotonicity { // Is the Monotonicity from constant value pub is_constant: bool, - pub left: Option, + pub left: Option, - pub right: Option, + pub right: Option, } impl Monotonicity { @@ -102,7 +102,7 @@ impl Monotonicity { }; if let (Some(max), Some(min)) = (max, min) { - let col = cast_column_field(&min, &f64::to_data_type())?; + let col = cast_column(&min, &f64::to_data_type())?; let min_val = col.get_f64(0)?; if min_val >= 0.0 { @@ -113,7 +113,7 @@ impl Monotonicity { return Ok(-1); } - let col = cast_column_field(&max, &f64::to_data_type())?; + let col = cast_column(&max, &f64::to_data_type())?; let max_val = col.get_f64(0)?; if max_val <= 0.0 { diff --git a/common/functions/src/scalars/hashes/city64_with_seed.rs b/common/functions/src/scalars/hashes/city64_with_seed.rs index f82953741c45..2d5de9935bad 100644 --- a/common/functions/src/scalars/hashes/city64_with_seed.rs +++ b/common/functions/src/scalars/hashes/city64_with_seed.rs @@ -24,7 +24,7 @@ use common_exception::Result; use naive_cityhash::cityhash64_with_seed; use super::hash_base::DFHash; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; @@ -115,20 +115,20 @@ impl Function for City64WithSeedFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, - ) -> Result { - let column = columns[0].column(); + ) -> Result { + let column = &columns[0]; let physical_data_type = columns[0].data_type().data_type_id().to_physical_type(); - let const_col: Result<&ConstColumn> = Series::check_get(columns[1].column()); + let const_col: Result<&ConstColumn> = Series::check_get(&columns[1]); if let Ok(col) = const_col { let seed = col.get_u64(0)?; let mut hasher = CityHasher64::with_seed(seed); let result_col = with_match_scalar_types_error!(physical_data_type, |$S| { - let data_col: &<$S as Scalar>::ColumnType = Series::check_get(column)?; + let data_col: &<$S as Scalar>::ColumnType = Series::check_get(&column)?; let iter = data_col.iter().map(|v| { v.hash(&mut hasher); hasher.finish() @@ -137,7 +137,7 @@ impl Function for City64WithSeedFunction { }); Ok(Arc::new(result_col)) } else { - let seed_col = cast_column_field(&columns[1], &UInt64Type::arc())?; + let seed_col = cast_column(&columns[1], &UInt64Type::arc())?; let seed_viewer = u64::try_create_viewer(&seed_col)?; let result_col = with_match_scalar_types_error!(physical_data_type, |$S| { diff --git a/common/functions/src/scalars/hashes/hash_base.rs b/common/functions/src/scalars/hashes/hash_base.rs index 38fb2b5d2139..e5b4076c6cee 100644 --- a/common/functions/src/scalars/hashes/hash_base.rs +++ b/common/functions/src/scalars/hashes/hash_base.rs @@ -87,11 +87,11 @@ where fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { with_match_scalar_types_error!(columns[0].data_type().data_type_id().to_physical_type(), |$S| { - let col = scalar_unary_op::<$S, R, _>(columns[0].column(), hash_func::, &mut EvalContext::default())?; + let col = scalar_unary_op::<$S, R, _>(&columns[0], hash_func::, &mut EvalContext::default())?; Ok(Arc::new(col)) }) } diff --git a/common/functions/src/scalars/hashes/sha2hash.rs b/common/functions/src/scalars/hashes/sha2hash.rs index 07a128224651..f7204a69ab48 100644 --- a/common/functions/src/scalars/hashes/sha2hash.rs +++ b/common/functions/src/scalars/hashes/sha2hash.rs @@ -22,7 +22,7 @@ use common_exception::ErrorCode; use common_exception::Result; use sha2::Digest; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; @@ -72,11 +72,11 @@ impl Function for Sha2HashFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, - ) -> Result { - let col_viewer = Vu8::try_create_viewer(columns[0].column())?; - let const_col: Result<&ConstColumn> = Series::check_get(columns[1].column()); + ) -> Result { + let col_viewer = Vu8::try_create_viewer(&columns[0])?; + let const_col: Result<&ConstColumn> = Series::check_get(&columns[1]); if let Ok(col) = const_col { let l = col.get_u64(0)?; @@ -124,7 +124,7 @@ impl Function for Sha2HashFunction { Ok(Arc::new(col)) } else { - let l = cast_column_field(&columns[1], &UInt16Type::arc())?; + let l = cast_column(&columns[1], &UInt16Type::arc())?; let l_viewer = u16::try_create_viewer(&l)?; let mut col_builder = MutableStringColumn::with_capacity(l.len()); diff --git a/common/functions/src/scalars/logics/and.rs b/common/functions/src/scalars/logics/and.rs index bfa8f895d14e..9bc561d44743 100644 --- a/common/functions/src/scalars/logics/and.rs +++ b/common/functions/src/scalars/logics/and.rs @@ -20,7 +20,7 @@ use super::logic::LogicFunctionImpl; use super::logic::LogicOperator; use crate::calcute; use crate::impl_logic_expression; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; diff --git a/common/functions/src/scalars/logics/logic.rs b/common/functions/src/scalars/logics/logic.rs index df970b4dd82e..9e7116ebf352 100644 --- a/common/functions/src/scalars/logics/logic.rs +++ b/common/functions/src/scalars/logics/logic.rs @@ -53,7 +53,7 @@ pub struct LogicFunctionImpl { } pub trait LogicExpression: Sync + Send { - fn eval(columns: &ColumnsWithField, input_rows: usize, nullable: bool) -> Result; + fn eval(columns: &[ColumnRef], input_rows: usize, nullable: bool) -> Result; } impl LogicFunctionImpl @@ -98,7 +98,7 @@ where F: LogicExpression + Clone fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { F::eval(columns, input_rows, self.nullable) diff --git a/common/functions/src/scalars/logics/macros.rs b/common/functions/src/scalars/logics/macros.rs index 082bea777e78..45656289d8ab 100644 --- a/common/functions/src/scalars/logics/macros.rs +++ b/common/functions/src/scalars/logics/macros.rs @@ -28,15 +28,15 @@ macro_rules! impl_logic_expression { pub struct $name; impl LogicExpression for $name { - fn eval(columns: &ColumnsWithField, input_rows: usize, nullable: bool) -> Result { + fn eval(columns: &[ColumnRef], input_rows: usize, nullable: bool) -> Result { let dt = if nullable { NullableType::arc(BooleanType::arc()) } else { BooleanType::arc() }; - let lhs = cast_column_field(&columns[0], &dt)?; - let rhs = cast_column_field(&columns[1], &dt)?; + let lhs = cast_column(&columns[0], &dt)?; + let rhs = cast_column(&columns[1], &dt)?; if nullable { let lhs_viewer = bool::try_create_viewer(&lhs)?; diff --git a/common/functions/src/scalars/logics/not.rs b/common/functions/src/scalars/logics/not.rs index 46659a07a86f..8f6904139861 100644 --- a/common/functions/src/scalars/logics/not.rs +++ b/common/functions/src/scalars/logics/not.rs @@ -18,7 +18,7 @@ use common_exception::Result; use super::logic::LogicExpression; use super::logic::LogicFunctionImpl; use super::logic::LogicOperator; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -27,8 +27,8 @@ use crate::scalars::FunctionFeatures; pub struct LogicNotExpression; impl LogicExpression for LogicNotExpression { - fn eval(columns: &ColumnsWithField, input_rows: usize, _nullable: bool) -> Result { - let col = cast_column_field(&columns[0], &BooleanType::arc())?; + fn eval(columns: &[ColumnRef], input_rows: usize, _nullable: bool) -> Result { + let col = cast_column(&columns[0], &BooleanType::arc())?; let col_viewer = bool::try_create_viewer(&col)?; diff --git a/common/functions/src/scalars/logics/or.rs b/common/functions/src/scalars/logics/or.rs index 5518e3c43677..227bb0ffe4b9 100644 --- a/common/functions/src/scalars/logics/or.rs +++ b/common/functions/src/scalars/logics/or.rs @@ -20,7 +20,7 @@ use super::logic::LogicFunctionImpl; use super::logic::LogicOperator; use crate::calcute; use crate::impl_logic_expression; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; diff --git a/common/functions/src/scalars/logics/xor.rs b/common/functions/src/scalars/logics/xor.rs index 9970743ab6a1..513656532889 100644 --- a/common/functions/src/scalars/logics/xor.rs +++ b/common/functions/src/scalars/logics/xor.rs @@ -19,7 +19,7 @@ use super::logic::LogicExpression; use super::logic::LogicFunctionImpl; use super::logic::LogicOperator; use crate::calcute; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -28,9 +28,9 @@ use crate::scalars::FunctionFeatures; pub struct LogicXorExpression; impl LogicExpression for LogicXorExpression { - fn eval(columns: &ColumnsWithField, input_rows: usize, _nullable: bool) -> Result { - let lhs = cast_column_field(&columns[0], &BooleanType::arc())?; - let rhs = cast_column_field(&columns[1], &BooleanType::arc())?; + fn eval(columns: &[ColumnRef], input_rows: usize, _nullable: bool) -> Result { + let lhs = cast_column(&columns[0], &BooleanType::arc())?; + let rhs = cast_column(&columns[1], &BooleanType::arc())?; let lhs_viewer = bool::try_create_viewer(&lhs)?; let rhs_viewer = bool::try_create_viewer(&rhs)?; diff --git a/common/functions/src/scalars/maths/abs.rs b/common/functions/src/scalars/maths/abs.rs index 9d7c06de51f6..41fa4efcd7ec 100644 --- a/common/functions/src/scalars/maths/abs.rs +++ b/common/functions/src/scalars/maths/abs.rs @@ -78,11 +78,7 @@ macro_rules! impl_abs_function { } $super::abs(s) as $target }; - let col = scalar_unary_op::<$type, $target, _>( - $column.column(), - func, - &mut EvalContext::default(), - )?; + let col = scalar_unary_op::<$type, $target, _>($column, func, &mut EvalContext::default())?; Ok(col.arc()) }}; } @@ -99,17 +95,17 @@ impl Function for AbsFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { match columns[0].data_type().data_type_id() { - TypeID::Int8 => impl_abs_function!(columns[0], i8, i64, u8), - TypeID::Int16 => impl_abs_function!(columns[0], i16, i64, u16), - TypeID::Int32 => impl_abs_function!(columns[0], i32, i64, u32), - TypeID::Int64 => impl_abs_function!(columns[0], i64, i64, u64), - TypeID::Float32 => impl_abs_function!(columns[0], f32, f64, f32), - TypeID::Float64 => impl_abs_function!(columns[0], f64, f64, f64), - _ => Ok(columns[0].column().clone()), + TypeID::Int8 => impl_abs_function!(&columns[0], i8, i64, u8), + TypeID::Int16 => impl_abs_function!(&columns[0], i16, i64, u16), + TypeID::Int32 => impl_abs_function!(&columns[0], i32, i64, u32), + TypeID::Int64 => impl_abs_function!(&columns[0], i64, i64, u64), + TypeID::Float32 => impl_abs_function!(&columns[0], f32, f64, f32), + TypeID::Float64 => impl_abs_function!(&columns[0], f64, f64, f64), + _ => Ok(columns[0].clone()), } } diff --git a/common/functions/src/scalars/maths/angle.rs b/common/functions/src/scalars/maths/angle.rs index be33b4b435a6..a889138206aa 100644 --- a/common/functions/src/scalars/maths/angle.rs +++ b/common/functions/src/scalars/maths/angle.rs @@ -69,12 +69,12 @@ where T: AngleConvertFunction + Clone + Sync + Send + 'static fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { let mut ctx = EvalContext::default(); with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), T::convert, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], T::convert, &mut ctx)?; Ok(col.arc()) },{ unreachable!() diff --git a/common/functions/src/scalars/maths/ceil.rs b/common/functions/src/scalars/maths/ceil.rs index 59c4161ed3fd..6199ce80c775 100644 --- a/common/functions/src/scalars/maths/ceil.rs +++ b/common/functions/src/scalars/maths/ceil.rs @@ -69,12 +69,12 @@ impl Function for CeilFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { let mut ctx = EvalContext::default(); with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(),ceil::<$S>, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0],ceil::<$S>, &mut ctx)?; Ok(col.arc()) },{ unreachable!() diff --git a/common/functions/src/scalars/maths/exp.rs b/common/functions/src/scalars/maths/exp.rs index 0f8ef437900c..79b4b2e404c9 100644 --- a/common/functions/src/scalars/maths/exp.rs +++ b/common/functions/src/scalars/maths/exp.rs @@ -63,12 +63,12 @@ impl Function for ExpFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { let mut ctx = EvalContext::default(); with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), exp::<$S>, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], exp::<$S>, &mut ctx)?; Ok(col.arc()) },{ unreachable!() diff --git a/common/functions/src/scalars/maths/floor.rs b/common/functions/src/scalars/maths/floor.rs index 3a0101dc7f82..4060ee083097 100644 --- a/common/functions/src/scalars/maths/floor.rs +++ b/common/functions/src/scalars/maths/floor.rs @@ -69,12 +69,12 @@ impl Function for FloorFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { let mut ctx = EvalContext::default(); with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), floor::<$S>, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], floor::<$S>, &mut ctx)?; Ok(col.arc()) },{ unreachable!() diff --git a/common/functions/src/scalars/maths/log.rs b/common/functions/src/scalars/maths/log.rs index 7eaa9ff0754e..db88fa787f29 100644 --- a/common/functions/src/scalars/maths/log.rs +++ b/common/functions/src/scalars/maths/log.rs @@ -114,13 +114,13 @@ impl Function for GenericLogFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { let mut ctx = EvalContext::default(); if columns.len() == 1 { with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), Self::log, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], Self::log, &mut ctx)?; Ok(Arc::new(col)) },{ unreachable!() @@ -128,7 +128,7 @@ impl Function for GenericLogFunction { } else { with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { with_match_primitive_type_id!(columns[1].data_type().data_type_id(), |$T| { - let col = scalar_binary_op::<$S, $T, f64, _>(columns[0].column(), columns[1].column(), Self::log_with_base, &mut ctx)?; + let col = scalar_binary_op::<$S, $T, f64, _>(&columns[0], &columns[1], Self::log_with_base, &mut ctx)?; Ok(Arc::new(col)) },{ unreachable!() diff --git a/common/functions/src/scalars/maths/pi.rs b/common/functions/src/scalars/maths/pi.rs index 166a0e19f984..e7a2d4cd332f 100644 --- a/common/functions/src/scalars/maths/pi.rs +++ b/common/functions/src/scalars/maths/pi.rs @@ -53,7 +53,7 @@ impl Function for PiFunction { fn eval( &self, _func_ctx: FunctionContext, - _columns: &ColumnsWithField, + _columns: &[ColumnRef], input_rows: usize, ) -> Result { Ok(ConstColumn::new(Series::from_data(vec![PI]), input_rows).arc()) diff --git a/common/functions/src/scalars/maths/pow.rs b/common/functions/src/scalars/maths/pow.rs index 62afc35d9bee..c26169fad6f1 100644 --- a/common/functions/src/scalars/maths/pow.rs +++ b/common/functions/src/scalars/maths/pow.rs @@ -71,12 +71,12 @@ impl Function for PowFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { with_match_primitive_type_id!(columns[1].data_type().data_type_id(), |$T| { - let col = scalar_binary_op::<$S, $T, f64, _>(columns[0].column(), columns[1].column(), scalar_pow, &mut EvalContext::default())?; + let col = scalar_binary_op::<$S, $T, f64, _>(&columns[0], &columns[1], scalar_pow, &mut EvalContext::default())?; Ok(Arc::new(col)) },{ unreachable!() diff --git a/common/functions/src/scalars/maths/random.rs b/common/functions/src/scalars/maths/random.rs index a5a5a39660e9..8bbc37f7ad3c 100644 --- a/common/functions/src/scalars/maths/random.rs +++ b/common/functions/src/scalars/maths/random.rs @@ -62,7 +62,7 @@ impl Function for RandomFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { match columns.len() { @@ -76,7 +76,7 @@ impl Function for RandomFunction { _ => { let mut ctx = EvalContext::default(); with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$T| { - let col = scalar_unary_op::<$T, f64, _>(columns[0].column(), rand_seed, &mut ctx)?; + let col = scalar_unary_op::<$T, f64, _>(&columns[0], rand_seed, &mut ctx)?; Ok(Arc::new(col)) },{ unreachable!() diff --git a/common/functions/src/scalars/maths/round.rs b/common/functions/src/scalars/maths/round.rs index c87c0cfb6708..5ed9afb0d85d 100644 --- a/common/functions/src/scalars/maths/round.rs +++ b/common/functions/src/scalars/maths/round.rs @@ -92,7 +92,7 @@ impl Function for RoundingFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { match IS_TRUNC { @@ -102,12 +102,12 @@ impl Function for RoundingFunction { } } -fn eval_round(columns: &ColumnsWithField) -> Result { +fn eval_round(columns: &[ColumnRef]) -> Result { let mut ctx = EvalContext::default(); match columns.len() { 1 => { with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), round, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], round, &mut ctx)?; Ok(Arc::new(col)) },{ unreachable!() @@ -118,8 +118,8 @@ fn eval_round(columns: &ColumnsWithField) -> Result { with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { with_match_primitive_type_id!(columns[1].data_type().data_type_id(), |$T| { let col = scalar_binary_op::<$S, $T, f64, _>( - columns[0].column(), - columns[1].column(), + &columns[0], + &columns[1], round_to, &mut ctx )?; @@ -134,12 +134,12 @@ fn eval_round(columns: &ColumnsWithField) -> Result { } } -fn eval_trunc(columns: &ColumnsWithField) -> Result { +fn eval_trunc(columns: &[ColumnRef]) -> Result { let mut ctx = EvalContext::default(); match columns.len() { 1 => { with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), trunc, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], trunc, &mut ctx)?; Ok(Arc::new(col)) },{ unreachable!() @@ -150,8 +150,8 @@ fn eval_trunc(columns: &ColumnsWithField) -> Result { with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { with_match_primitive_type_id!(columns[1].data_type().data_type_id(), |$T| { let col = scalar_binary_op::<$S, $T, f64, _>( - columns[0].column(), - columns[1].column(), + &columns[0], + &columns[1], trunc_to, &mut ctx, )?; diff --git a/common/functions/src/scalars/maths/sign.rs b/common/functions/src/scalars/maths/sign.rs index 91857e5a6828..c1472d30ba4b 100644 --- a/common/functions/src/scalars/maths/sign.rs +++ b/common/functions/src/scalars/maths/sign.rs @@ -18,7 +18,6 @@ use std::sync::Arc; use common_datavalues::prelude::*; use common_datavalues::with_match_primitive_type_id; -use common_datavalues::ColumnWithField; use common_exception::Result; use crate::scalars::function_common::assert_numeric; @@ -74,12 +73,12 @@ impl Function for SignFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { let mut ctx = EvalContext::default(); with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { - let col = scalar_unary_op::<$S, i8, _>(columns[0].column(), sign::<$S>, &mut ctx)?; + let col = scalar_unary_op::<$S, i8, _>(&columns[0], sign::<$S>, &mut ctx)?; Ok(Arc::new(col)) },{ unreachable!() @@ -93,9 +92,9 @@ impl Function for SignFunction { } // check whether the left/right boundary is numeric or not. - let is_boundary_numeric = |boundary: Option| -> bool { - if let Some(column_field) = boundary { - column_field.data_type().data_type_id().is_numeric() + let is_boundary_numeric = |boundary: Option| -> bool { + if let Some(column) = boundary { + column.data_type().data_type_id().is_numeric() } else { false } diff --git a/common/functions/src/scalars/maths/sqrt.rs b/common/functions/src/scalars/maths/sqrt.rs index ceee534da3ca..6b532d784213 100644 --- a/common/functions/src/scalars/maths/sqrt.rs +++ b/common/functions/src/scalars/maths/sqrt.rs @@ -63,12 +63,12 @@ impl Function for SqrtFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { let mut ctx = EvalContext::default(); with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), sqrt::<$S>, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], sqrt::<$S>, &mut ctx)?; Ok(col.arc()) },{ unreachable!() diff --git a/common/functions/src/scalars/maths/trigonometric.rs b/common/functions/src/scalars/maths/trigonometric.rs index 9f9ce7d67829..1abcf0a2133b 100644 --- a/common/functions/src/scalars/maths/trigonometric.rs +++ b/common/functions/src/scalars/maths/trigonometric.rs @@ -80,7 +80,7 @@ impl Function for TrigonometricFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { let mut ctx = EvalContext::default(); @@ -90,38 +90,38 @@ impl Function for TrigonometricFunction { match self.t { Trigonometric::COS => { let func = |v: $S, _ctx: &mut EvalContext| AsPrimitive::::as_(v).cos(); - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), func, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], func, &mut ctx)?; Ok(Arc::new(col)) }, Trigonometric::SIN => { let func = |v: $S, _ctx: &mut EvalContext| AsPrimitive::::as_(v).sin(); - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), func, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], func, &mut ctx)?; Ok(Arc::new(col)) }, Trigonometric::COT => { let func = |v: $S, _ctx: &mut EvalContext| 1.0 / AsPrimitive::::as_(v).tan(); - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), func, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], func, &mut ctx)?; Ok(Arc::new(col)) }, Trigonometric::TAN => { let func = |v: $S, _ctx: &mut EvalContext| AsPrimitive::::as_(v).tan(); - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), func, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], func, &mut ctx)?; Ok(Arc::new(col)) }, // the range [0, pi] or NaN if the number is outside the range Trigonometric::ACOS => { let func = |v: $S, _ctx: &mut EvalContext| AsPrimitive::::as_(v).acos(); - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), func, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], func, &mut ctx)?; Ok(Arc::new(col)) }, Trigonometric::ASIN => { let func = |v: $S, _ctx: &mut EvalContext| AsPrimitive::::as_(v).asin(); - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), func, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], func, &mut ctx)?; Ok(Arc::new(col)) }, Trigonometric::ATAN => { let func = |v: $S, _ctx: &mut EvalContext| AsPrimitive::::as_(v).atan(); - let col = scalar_unary_op::<$S, f64, _>(columns[0].column(), func, &mut ctx)?; + let col = scalar_unary_op::<$S, f64, _>(&columns[0], func, &mut ctx)?; Ok(Arc::new(col)) }, _ => unreachable!(), @@ -135,7 +135,7 @@ impl Function for TrigonometricFunction { _ => { with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { with_match_primitive_type_id!(columns[1].data_type().data_type_id(), |$T| { - let col = scalar_binary_op::<$S, $T, f64, _>(columns[0].column(), columns[1].column(), scalar_atan2,&mut EvalContext::default())?; + let col = scalar_binary_op::<$S, $T, f64, _>(&columns[0], &columns[1], scalar_atan2,&mut EvalContext::default())?; Ok(Arc::new(col)) }, { unreachable!() diff --git a/common/functions/src/scalars/others/exists.rs b/common/functions/src/scalars/others/exists.rs index 39079fa7dcd4..675476b87a85 100644 --- a/common/functions/src/scalars/others/exists.rs +++ b/common/functions/src/scalars/others/exists.rs @@ -49,11 +49,11 @@ impl Function for ExistsFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, - ) -> Result { - if columns[0].column().is_const() || columns[0].column().len() == 1 { - let value = columns[0].column().get(0); + ) -> Result { + if columns[0].is_const() || columns[0].len() == 1 { + let value = columns[0].get(0); match value { DataValue::Array(v) => { let c = Series::from_data(vec![!v.is_empty()]); diff --git a/common/functions/src/scalars/others/ignore.rs b/common/functions/src/scalars/others/ignore.rs index 4ccc9c0d2ed8..406b60becfd3 100644 --- a/common/functions/src/scalars/others/ignore.rs +++ b/common/functions/src/scalars/others/ignore.rs @@ -17,7 +17,6 @@ use std::str; use common_datavalues::BooleanType; use common_datavalues::ColumnRef; -use common_datavalues::ColumnsWithField; use common_datavalues::DataType; use common_datavalues::DataTypeImpl; use common_datavalues::DataValue; @@ -72,7 +71,7 @@ impl Function for IgnoreFunction { fn eval( &self, _func_ctx: FunctionContext, - _columns: &ColumnsWithField, + _columns: &[ColumnRef], input_rows: usize, ) -> Result { let return_type = BooleanType::arc(); diff --git a/common/functions/src/scalars/others/inet_aton.rs b/common/functions/src/scalars/others/inet_aton.rs index 269dd4f413f3..685ef1250f33 100644 --- a/common/functions/src/scalars/others/inet_aton.rs +++ b/common/functions/src/scalars/others/inet_aton.rs @@ -68,10 +68,10 @@ impl Function for InetAtonFunctionImpl Result { - let viewer = Vu8::try_create_viewer(columns[0].column())?; + let viewer = Vu8::try_create_viewer(&columns[0])?; let viewer_iter = viewer.iter(); if SUPPRESS_PARSE_ERROR { diff --git a/common/functions/src/scalars/others/inet_ntoa.rs b/common/functions/src/scalars/others/inet_ntoa.rs index e134e22aa00a..341b70ae16ef 100644 --- a/common/functions/src/scalars/others/inet_ntoa.rs +++ b/common/functions/src/scalars/others/inet_ntoa.rs @@ -71,7 +71,7 @@ impl Function for InetNtoaFunctionImpl Result { if SUPPRESS_CAST_ERROR { @@ -82,8 +82,8 @@ impl Function for InetNtoaFunctionImpl Function for InetNtoaFunctionImpl Result { - let dt = remove_nullable(columns[0].data_type()); - let col = columns[0].column(); + let dt = remove_nullable(&columns[0].data_type()); + let col = &columns[0]; match dt.data_type_id() { TypeID::Int8 => compute_i8(col, input_rows), TypeID::UInt8 => compute_u8(col, input_rows), @@ -107,10 +107,8 @@ impl Function for RunningDifferenceFunction { TypeID::Float64 => compute_f64(col, input_rows), _ => Result::Err(ErrorCode::IllegalDataType( - format!( - "Argument for function running_difference must have numeric type.: While processing running_difference({})", - columns[0].field().name(), - ))) + "Argument for function running_difference must have numeric type.: While processing running_difference", + )) } } } diff --git a/common/functions/src/scalars/others/sleep.rs b/common/functions/src/scalars/others/sleep.rs index ca66b8d70748..c260cb9b632f 100644 --- a/common/functions/src/scalars/others/sleep.rs +++ b/common/functions/src/scalars/others/sleep.rs @@ -15,6 +15,7 @@ use std::fmt; use std::time::Duration; +use common_datavalues::ColumnRef; use common_datavalues::DataType; use common_datavalues::DataTypeImpl; use common_datavalues::DataValue; @@ -59,10 +60,10 @@ impl Function for SleepFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, - ) -> Result { - let c = columns[0].column(); + ) -> Result { + let c = &columns[0]; if c.len() != 1 { return Err(ErrorCode::BadArguments(format!( "The argument of function {} must be constant.", diff --git a/common/functions/src/scalars/others/type_of.rs b/common/functions/src/scalars/others/type_of.rs index b23541e2ef82..149acddf12be 100644 --- a/common/functions/src/scalars/others/type_of.rs +++ b/common/functions/src/scalars/others/type_of.rs @@ -56,10 +56,10 @@ impl Function for TypeOfFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, - ) -> Result { - let non_null_type = remove_nullable(columns[0].data_type()); + ) -> Result { + let non_null_type = remove_nullable(&columns[0].data_type()); let type_name = format_data_type_sql(&non_null_type); let value = DataValue::String(type_name.as_bytes().to_vec()); let data_type = StringType::arc(); diff --git a/common/functions/src/scalars/semi_structureds/check_json.rs b/common/functions/src/scalars/semi_structureds/check_json.rs index 51ff70d199cb..6a08478966c3 100644 --- a/common/functions/src/scalars/semi_structureds/check_json.rs +++ b/common/functions/src/scalars/semi_structureds/check_json.rs @@ -54,11 +54,11 @@ impl Function for CheckJsonFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let data_type = columns[0].field().data_type(); - let column = columns[0].column(); + let data_type = columns[0].data_type(); + let column = &columns[0]; let mut builder = NullableColumnBuilder::::with_capacity(input_rows); diff --git a/common/functions/src/scalars/semi_structureds/get.rs b/common/functions/src/scalars/semi_structureds/get.rs index 29a786fa67eb..727e40f14829 100644 --- a/common/functions/src/scalars/semi_structureds/get.rs +++ b/common/functions/src/scalars/semi_structureds/get.rs @@ -86,16 +86,16 @@ impl Function fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { let path_keys = if BY_PATH { - parse_path_keys(columns[1].column())? + parse_path_keys(&columns[1])? } else { - build_path_keys(columns[1].column())? + build_path_keys(&columns[1])? }; - extract_value_by_path(columns[0].column(), path_keys, input_rows, IGNORE_CASE) + extract_value_by_path(&columns[0], path_keys, input_rows, IGNORE_CASE) } } diff --git a/common/functions/src/scalars/semi_structureds/json_extract_path_text.rs b/common/functions/src/scalars/semi_structureds/json_extract_path_text.rs index f195808395d1..0147fea1ddf5 100644 --- a/common/functions/src/scalars/semi_structureds/json_extract_path_text.rs +++ b/common/functions/src/scalars/semi_structureds/json_extract_path_text.rs @@ -67,12 +67,12 @@ impl Function for JsonExtractPathTextFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let path_keys = parse_path_keys(columns[1].column())?; + let path_keys = parse_path_keys(&columns[1])?; - let data_type = columns[0].field().data_type(); + let data_type = columns[0].data_type(); if !data_type.data_type_id().is_string() && !data_type.data_type_id().is_variant() { let mut builder = NullableColumnBuilder::::with_capacity(input_rows); for _ in 0..input_rows { @@ -83,7 +83,7 @@ impl Function for JsonExtractPathTextFunction { let mut builder = ColumnBuilder::::with_capacity(input_rows); let serializer = data_type.create_serializer(); - match serializer.serialize_json_object(columns[0].column(), None) { + match serializer.serialize_json_object(&columns[0], None) { Ok(values) => { for v in values { builder.append(&VariantValue::from(v)); diff --git a/common/functions/src/scalars/semi_structureds/parse_json.rs b/common/functions/src/scalars/semi_structureds/parse_json.rs index a72e4538efa5..44930361bb62 100644 --- a/common/functions/src/scalars/semi_structureds/parse_json.rs +++ b/common/functions/src/scalars/semi_structureds/parse_json.rs @@ -83,15 +83,15 @@ impl Function for ParseJsonFunctionImpl Result { - let data_type = columns[0].field().data_type(); + let data_type = columns[0].data_type(); if data_type.data_type_id() == TypeID::Null { return NullType::arc().create_constant_column(&DataValue::Null, input_rows); } - let column = columns[0].column(); + let column = &columns[0]; if SUPPRESS_PARSE_ERROR { let mut builder = NullableColumnBuilder::::with_capacity(input_rows); if data_type.data_type_id().is_numeric() @@ -123,7 +123,7 @@ impl Function for ParseJsonFunctionImpl::with_capacity(input_rows); if data_type.data_type_id().is_numeric() diff --git a/common/functions/src/scalars/strings/bin.rs b/common/functions/src/scalars/strings/bin.rs index 24b9613c3d3f..d4af6aefc683 100644 --- a/common/functions/src/scalars/strings/bin.rs +++ b/common/functions/src/scalars/strings/bin.rs @@ -19,7 +19,7 @@ use common_exception::ErrorCode; use common_exception::Result; use crate::scalars::assert_numeric; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; @@ -56,28 +56,28 @@ impl Function for BinFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { let mut builder: ColumnBuilder = ColumnBuilder::with_capacity(input_rows); match columns[0].data_type().data_type_id() { TypeID::UInt8 | TypeID::UInt16 | TypeID::UInt32 | TypeID::UInt64 => { - let col = cast_column_field(&columns[0], &UInt64Type::arc())?; + let col = cast_column(&columns[0], &UInt64Type::arc())?; let col = col.as_any().downcast_ref::().unwrap(); for val in col.iter() { builder.append(format!("{:b}", val).as_bytes()); } } TypeID::Int8 | TypeID::Int16 | TypeID::Int32 | TypeID::Int64 => { - let col = cast_column_field(&columns[0], &Int64Type::arc())?; + let col = cast_column(&columns[0], &Int64Type::arc())?; let col = col.as_any().downcast_ref::().unwrap(); for val in col.iter() { builder.append(format!("{:b}", val).as_bytes()); } } TypeID::Float32 | TypeID::Float64 => { - let col = cast_column_field(&columns[0], &Float64Type::arc())?; + let col = cast_column(&columns[0], &Float64Type::arc())?; let col = col.as_any().downcast_ref::().unwrap(); for val in col.iter() { let val = if val.ge(&0f64) { diff --git a/common/functions/src/scalars/strings/char_.rs b/common/functions/src/scalars/strings/char_.rs index 61adbe05bca2..989c7c6ad840 100644 --- a/common/functions/src/scalars/strings/char_.rs +++ b/common/functions/src/scalars/strings/char_.rs @@ -60,7 +60,7 @@ impl Function for CharFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { let column_count = columns.len(); @@ -72,7 +72,6 @@ impl Function for CharFunction { let u8_type = u8::to_data_type(); for (i, column) in columns.iter().enumerate() { - let column = column.column(); let column = default_column_cast(column, &u8_type)?; match column.is_const() { diff --git a/common/functions/src/scalars/strings/concat.rs b/common/functions/src/scalars/strings/concat.rs index 3bad4091b8f9..bd6ae6620209 100644 --- a/common/functions/src/scalars/strings/concat.rs +++ b/common/functions/src/scalars/strings/concat.rs @@ -59,12 +59,12 @@ impl Function for ConcatFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { let viewers = columns .iter() - .map(|c| Vu8::try_create_viewer(c.column())) + .map(|c| Vu8::try_create_viewer(c)) .collect::>>()?; let mut values: Vec = Vec::with_capacity(input_rows * columns.len()); diff --git a/common/functions/src/scalars/strings/concat_ws.rs b/common/functions/src/scalars/strings/concat_ws.rs index cecf1f6d7b8f..88d9fa887a43 100644 --- a/common/functions/src/scalars/strings/concat_ws.rs +++ b/common/functions/src/scalars/strings/concat_ws.rs @@ -65,12 +65,12 @@ impl ConcatWsFunction { fn concat_column_with_constant_seperator( sep: &[u8], - columns: &[ColumnWithField], + columns: &[ColumnRef], rows: usize, ) -> Result { let viewers = columns .iter() - .map(|column| Vu8::try_create_viewer(column.column())) + .map(|column| Vu8::try_create_viewer(&column)) .collect::>>()?; let mut builder = MutableStringColumn::with_capacity(rows); @@ -92,14 +92,14 @@ impl ConcatWsFunction { } fn concat_column_nonull( - sep_column: &ColumnWithField, - columns: &[ColumnWithField], + sep_column: &ColumnRef, + columns: &[ColumnRef], rows: usize, ) -> Result { - let sep_c = Series::check_get_scalar::(sep_column.column())?; + let sep_c = Series::check_get_scalar::(&sep_column)?; let viewers = columns .iter() - .map(|column| Vu8::try_create_viewer(column.column())) + .map(|column| Vu8::try_create_viewer(&column)) .collect::>>()?; let mut builder = MutableStringColumn::with_capacity(rows); @@ -122,14 +122,14 @@ impl ConcatWsFunction { } fn concat_column_null( - sep_column: &ColumnWithField, - columns: &[ColumnWithField], + sep_column: &ColumnRef, + columns: &[ColumnRef], rows: usize, ) -> Result { - let sep_viewer = Vu8::try_create_viewer(sep_column.column())?; + let sep_viewer = Vu8::try_create_viewer(&sep_column)?; let viewers = columns .iter() - .map(|column| Vu8::try_create_viewer(column.column())) + .map(|column| Vu8::try_create_viewer(&column)) .collect::>>()?; let mut builder = NullableColumnBuilder::::with_capacity(rows); @@ -171,7 +171,7 @@ impl Function for ConcatWsFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { if self.result_type.is_null() { @@ -181,14 +181,14 @@ impl Function for ConcatWsFunction { let seperator = &columns[0]; // remove other null columns - let cols: Vec = columns[1..] + let cols: Vec = columns[1..] .iter() .filter(|c| !c.data_type().is_null()) .cloned() .collect(); - let viewer = Vu8::try_create_viewer(columns[0].column())?; - if seperator.column().is_const() { + let viewer = Vu8::try_create_viewer(&columns[0])?; + if seperator.is_const() { if viewer.null_at(0) { return Ok(NullColumn::new(input_rows).arc()); } diff --git a/common/functions/src/scalars/strings/elt.rs b/common/functions/src/scalars/strings/elt.rs index 28a031b18f33..89314867e29e 100644 --- a/common/functions/src/scalars/strings/elt.rs +++ b/common/functions/src/scalars/strings/elt.rs @@ -86,7 +86,7 @@ impl Function for EltFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { if self.result_type.is_null() { @@ -111,25 +111,21 @@ fn check_range(index: usize, cols: usize) -> Result<()> { Ok(()) } -fn execute_impl( - columns: &ColumnsWithField, - input_rows: usize, - nullable: bool, -) -> Result +fn execute_impl(columns: &[ColumnRef], input_rows: usize, nullable: bool) -> Result where S: Scalar + AsPrimitive, for<'a> S: Scalar = S>, { - let viewer = S::try_create_viewer(columns[0].column())?; + let viewer = S::try_create_viewer(&columns[0])?; let cols = columns.len() - 1; - if columns[0].column().is_const() { + if columns[0].is_const() { if viewer.null_at(0) { return Ok(NullColumn::new(input_rows).arc()); } let index: usize = viewer.value_at(0).as_(); check_range(index, cols)?; - let dest_column = columns[index].column(); + let dest_column = &columns[index]; return match (nullable, dest_column.data_type().can_inside_nullable()) { (true, true) => Ok(NullableColumn::wrap_inner( @@ -142,11 +138,11 @@ where let viewers = columns[1..] .iter() - .map(|column| Vu8::try_create_viewer(column.column())) + .map(|column| Vu8::try_create_viewer(column)) .collect::>>()?; match nullable { false => { - let index_c = Series::check_get_scalar::(columns[0].column())?; + let index_c = Series::check_get_scalar::(&columns[0])?; let mut builder = MutableStringColumn::with_capacity(input_rows); for (row, index) in index_c.scalar_iter().enumerate() { let index: usize = index.as_(); @@ -157,7 +153,7 @@ where } true => { - let index_viewer = u8::try_create_viewer(columns[0].column())?; + let index_viewer = u8::try_create_viewer(&columns[0])?; let mut builder = NullableColumnBuilder::::with_capacity(input_rows); for row in 0..input_rows { diff --git a/common/functions/src/scalars/strings/export_set.rs b/common/functions/src/scalars/strings/export_set.rs index 4ca96eb340ce..3df5f2040d1d 100644 --- a/common/functions/src/scalars/strings/export_set.rs +++ b/common/functions/src/scalars/strings/export_set.rs @@ -73,17 +73,17 @@ impl Function for ExportSetFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { let sep_col = if columns.len() >= 4 { - columns[3].column().clone() + columns[3].clone() } else { ConstColumn::new(Series::from_data(vec![","]), input_rows).arc() }; let number_bits_column = if columns.len() >= 5 { - columns[4].column().clone() + columns[4].clone() } else { ConstColumn::new(Series::from_data(vec![64u64]), input_rows).arc() }; @@ -97,8 +97,8 @@ impl Function for ExportSetFunction { )?; let bits_column = cast_with_type( - columns[0].column(), - &columns[0].column().data_type(), + &columns[0], + &columns[0].data_type(), &t, &DEFAULT_CAST_OPTIONS, )?; @@ -116,8 +116,8 @@ impl Function for ExportSetFunction { let n = std::cmp::min(n, 64) as usize; let s = sep_col.get_string(0)?; - let on_viewer = Vu8::try_create_viewer(columns[1].column())?; - let off_viewer = Vu8::try_create_viewer(columns[2].column())?; + let on_viewer = Vu8::try_create_viewer(&columns[1])?; + let off_viewer = Vu8::try_create_viewer(&columns[2])?; let sep_viewer = Vu8::try_create_viewer(&sep_col)?; let values_capacity = diff --git a/common/functions/src/scalars/strings/field.rs b/common/functions/src/scalars/strings/field.rs index 99c2c3ad3b59..6904058e269e 100644 --- a/common/functions/src/scalars/strings/field.rs +++ b/common/functions/src/scalars/strings/field.rs @@ -59,15 +59,15 @@ impl Function for FieldFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let basic_viewer = Vu8::try_create_viewer(columns[0].column())?; + let basic_viewer = Vu8::try_create_viewer(&columns[0])?; let viewers = columns .iter() .skip(1) - .map(|c| Vu8::try_create_viewer(c.column())) + .map(|c| Vu8::try_create_viewer(c)) .collect::>>()?; let mut values = Vec::with_capacity(input_rows); diff --git a/common/functions/src/scalars/strings/find_in_set.rs b/common/functions/src/scalars/strings/find_in_set.rs index ae35aae32662..f7d251e9b697 100644 --- a/common/functions/src/scalars/strings/find_in_set.rs +++ b/common/functions/src/scalars/strings/find_in_set.rs @@ -57,12 +57,12 @@ impl Function for FindInSetFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { let col = scalar_binary_op::( - columns[0].column(), - columns[1].column(), + &columns[0], + &columns[1], find_in_set, &mut EvalContext::default(), )?; diff --git a/common/functions/src/scalars/strings/format.rs b/common/functions/src/scalars/strings/format.rs index e3f714f3a721..12b2964a37f1 100644 --- a/common/functions/src/scalars/strings/format.rs +++ b/common/functions/src/scalars/strings/format.rs @@ -74,12 +74,12 @@ impl Function for FormatFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$F| { with_match_primitive_type_id!(columns[1].data_type().data_type_id(), |$N| { - let col = scalar_binary_op::<$F, $N, Vu8, _>(columns[0].column(), columns[1].column(), format_en_us,&mut EvalContext::default())?; + let col = scalar_binary_op::<$F, $N, Vu8, _>(&columns[0], &columns[1], format_en_us,&mut EvalContext::default())?; Ok(col.arc()) },{ unreachable!() diff --git a/common/functions/src/scalars/strings/hex.rs b/common/functions/src/scalars/strings/hex.rs index 58b8997fe971..9c82f4253c66 100644 --- a/common/functions/src/scalars/strings/hex.rs +++ b/common/functions/src/scalars/strings/hex.rs @@ -20,7 +20,7 @@ use common_datavalues::prelude::*; use common_exception::ErrorCode; use common_exception::Result; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; @@ -63,18 +63,18 @@ impl Function for HexFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { match columns[0].data_type().data_type_id() { TypeID::UInt8 | TypeID::UInt16 | TypeID::UInt32 | TypeID::UInt64 => { - let col = cast_column_field(&columns[0], &UInt64Type::arc())?; + let col = cast_column(&columns[0], &UInt64Type::arc())?; let col = col.as_any().downcast_ref::().unwrap(); let iter = col.iter().map(|val| format!("{:x}", val).into_bytes()); Ok(Arc::new(StringColumn::from_owned_iterator(iter))) } TypeID::Int8 | TypeID::Int16 | TypeID::Int32 | TypeID::Int64 => { - let col = cast_column_field(&columns[0], &Int64Type::arc())?; + let col = cast_column(&columns[0], &Int64Type::arc())?; let col = col.as_any().downcast_ref::().unwrap(); let iter = col.iter().map(|val| match val.cmp(&0) { Ordering::Less => format!("-{:x}", val.unsigned_abs()).into_bytes(), @@ -83,7 +83,7 @@ impl Function for HexFunction { Ok(Arc::new(StringColumn::from_owned_iterator(iter))) } TypeID::String => { - let col = cast_column_field(&columns[0], &StringType::arc())?; + let col = cast_column(&columns[0], &StringType::arc())?; let col = col.as_any().downcast_ref::().unwrap(); let iter = col.iter().map(|val| { let mut buffer = vec![0u8; val.len() * 2]; diff --git a/common/functions/src/scalars/strings/insert.rs b/common/functions/src/scalars/strings/insert.rs index 6046b5df88ff..f219d9ee87ac 100644 --- a/common/functions/src/scalars/strings/insert.rs +++ b/common/functions/src/scalars/strings/insert.rs @@ -86,11 +86,11 @@ impl Function for InsertFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let s_viewer = Vu8::try_create_viewer(columns[0].column())?; - let ss_viewer = Vu8::try_create_viewer(columns[3].column())?; + let s_viewer = Vu8::try_create_viewer(&columns[0])?; + let ss_viewer = Vu8::try_create_viewer(&columns[3])?; let mut values = Vec::with_capacity(s_viewer.value_at(0).len() * input_rows); let mut offsets = Vec::with_capacity(input_rows + 1); @@ -98,8 +98,8 @@ impl Function for InsertFunction { with_match_primitive_type_id!(columns[1].data_type().data_type_id(), |$S| { with_match_primitive_type_id!(columns[2].data_type().data_type_id(), |$T| { - let p_viewer = $S::try_create_viewer(columns[1].column())?; - let l_viewer = $T::try_create_viewer(columns[2].column())?; + let p_viewer = $S::try_create_viewer(&columns[1])?; + let l_viewer = $T::try_create_viewer(&columns[2])?; for row in 0..input_rows { apply_insert( diff --git a/common/functions/src/scalars/strings/leftright.rs b/common/functions/src/scalars/strings/leftright.rs index ee642db72dae..e2bd1b427fa8 100644 --- a/common/functions/src/scalars/strings/leftright.rs +++ b/common/functions/src/scalars/strings/leftright.rs @@ -84,13 +84,13 @@ impl Function for LeftRightFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { match IS_LEFT { true => { with_match_primitive_type_id!(columns[1].data_type().data_type_id(), |$S| { - let col = scalar_binary_op_ref::(columns[0].column(), columns[1].column(), left, &mut EvalContext::default())?; + let col = scalar_binary_op_ref::(&columns[0], &columns[1], left, &mut EvalContext::default())?; Ok(Arc::new(col)) },{ unreachable!() @@ -98,7 +98,7 @@ impl Function for LeftRightFunction { } false => { with_match_primitive_type_id!(columns[1].data_type().data_type_id(), |$S| { - let col = scalar_binary_op_ref::(columns[0].column(), columns[1].column(), right, &mut EvalContext::default())?; + let col = scalar_binary_op_ref::(&columns[0], &columns[1], right, &mut EvalContext::default())?; Ok(Arc::new(col)) },{ unreachable!() diff --git a/common/functions/src/scalars/strings/locate.rs b/common/functions/src/scalars/strings/locate.rs index 9a97c568a7be..45ba4069a503 100644 --- a/common/functions/src/scalars/strings/locate.rs +++ b/common/functions/src/scalars/strings/locate.rs @@ -74,18 +74,18 @@ impl Function for LocatingFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { let (ss_column, s_column) = if T == FUNC_INSTR { - (columns[1].column(), columns[0].column()) + (&columns[1], &columns[0]) } else { - (columns[0].column(), columns[1].column()) + (&columns[0], &columns[1]) }; // TODO, improve the performance using matching macros. let p_column = if T == FUNC_LOCATE && columns.len() == 3 { - default_column_cast(columns[2].column(), &u64::to_data_type())? + default_column_cast(&columns[2], &u64::to_data_type())? } else { ConstColumn::new(Series::from_data(vec![1u64]), input_rows).arc() }; diff --git a/common/functions/src/scalars/strings/oct.rs b/common/functions/src/scalars/strings/oct.rs index 07e1a1e969f3..bd3144d65d7b 100644 --- a/common/functions/src/scalars/strings/oct.rs +++ b/common/functions/src/scalars/strings/oct.rs @@ -19,7 +19,7 @@ use common_datavalues::prelude::*; use common_exception::Result; use crate::scalars::assert_numeric; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; @@ -82,21 +82,21 @@ impl Function for OctFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { let mut builder: ColumnBuilder = ColumnBuilder::with_capacity(input_rows); match columns[0].data_type().data_type_id() { TypeID::UInt8 | TypeID::UInt16 | TypeID::UInt32 | TypeID::UInt64 => { - let col = cast_column_field(&columns[0], &UInt64Type::arc())?; + let col = cast_column(&columns[0], &UInt64Type::arc())?; let col = col.as_any().downcast_ref::().unwrap(); for val in col.iter() { builder.append(val.oct_string().as_bytes()); } } _ => { - let col = cast_column_field(&columns[0], &Int64Type::arc())?; + let col = cast_column(&columns[0], &Int64Type::arc())?; let col = col.as_any().downcast_ref::().unwrap(); for val in col.iter() { builder.append(val.oct_string().as_bytes()); diff --git a/common/functions/src/scalars/strings/pad.rs b/common/functions/src/scalars/strings/pad.rs index f1dcb8951675..e951dcaba3b3 100644 --- a/common/functions/src/scalars/strings/pad.rs +++ b/common/functions/src/scalars/strings/pad.rs @@ -124,16 +124,16 @@ impl Function for PadFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let col1 = Vu8::try_create_viewer(columns[0].column())?; - let col3 = Vu8::try_create_viewer(columns[2].column())?; + let col1 = Vu8::try_create_viewer(&columns[0])?; + let col3 = Vu8::try_create_viewer(&columns[2])?; let mut t = T::default(); let mut builder = MutableStringColumn::with_capacity(input_rows); with_match_primitive_type_id!(columns[1].data_type().data_type_id(), |$S| { - let col2 = $S::try_create_viewer(columns[1].column())?; + let col2 = $S::try_create_viewer(&columns[1])?; col1.iter() .zip(col2.iter()) .zip(col3.iter()) diff --git a/common/functions/src/scalars/strings/regexp_instr.rs b/common/functions/src/scalars/strings/regexp_instr.rs index 3a45b8b42f6e..4b6558c0f6f1 100644 --- a/common/functions/src/scalars/strings/regexp_instr.rs +++ b/common/functions/src/scalars/strings/regexp_instr.rs @@ -23,7 +23,7 @@ use regex::bytes::Match; use regex::bytes::Regex; use crate::scalars::assert_string; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::strings::regexp_like::build_regexp_from_pattern; use crate::scalars::Function; use crate::scalars::FunctionContext; @@ -81,10 +81,10 @@ impl Function for RegexpInStrFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let has_null = columns.iter().any(|col| col.column().is_null()); + let has_null = columns.iter().any(|col| col.is_null()); if has_null { return Ok(NullColumn::new(input_rows).arc()); } @@ -96,24 +96,17 @@ impl Function for RegexpInStrFunction { for i in 2..columns.len() { match i { - 2 => pos = cast_column_field(&columns[2], &NullableType::arc(Int64Type::arc()))?, - 3 => { - occurrence = - cast_column_field(&columns[3], &NullableType::arc(Int64Type::arc()))? - } + 2 => pos = cast_column(&columns[2], &NullableType::arc(Int64Type::arc()))?, + 3 => occurrence = cast_column(&columns[3], &NullableType::arc(Int64Type::arc()))?, 4 => { - return_option = - cast_column_field(&columns[4], &NullableType::arc(Int64Type::arc()))? - } - _ => { - match_type = - cast_column_field(&columns[5], &NullableType::arc(StringType::arc()))? + return_option = cast_column(&columns[4], &NullableType::arc(Int64Type::arc()))? } + _ => match_type = cast_column(&columns[5], &NullableType::arc(StringType::arc()))?, } } - let source = columns[0].column(); - let pat = columns[1].column(); + let source = &columns[0]; + let pat = &columns[1]; if pat.is_const() && match_type.is_const() { let pat_value = pat.get_string(0)?; diff --git a/common/functions/src/scalars/strings/regexp_like.rs b/common/functions/src/scalars/strings/regexp_like.rs index cf1d199a35a2..00283ec1a443 100644 --- a/common/functions/src/scalars/strings/regexp_like.rs +++ b/common/functions/src/scalars/strings/regexp_like.rs @@ -68,14 +68,14 @@ impl Function for RegexpLikeFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let lhs = columns[0].column(); - let rhs = columns[1].column(); + let lhs = &columns[0]; + let rhs = &columns[1]; let mut match_type = &ConstColumn::new(Series::from_data(vec![""]), input_rows).arc(); if columns.len() == 3 { - match_type = columns[2].column(); + match_type = &columns[2]; } if rhs.is_const() && match_type.is_const() { diff --git a/common/functions/src/scalars/strings/regexp_replace.rs b/common/functions/src/scalars/strings/regexp_replace.rs index 18b0e9ec5c81..6b1ef01571e0 100644 --- a/common/functions/src/scalars/strings/regexp_replace.rs +++ b/common/functions/src/scalars/strings/regexp_replace.rs @@ -22,7 +22,7 @@ use common_exception::Result; use regex::bytes::Regex; use crate::scalars::assert_string; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::strings::regexp_instr::regexp_match_result; use crate::scalars::strings::regexp_instr::validate_regexp_arguments; use crate::scalars::strings::regexp_like::build_regexp_from_pattern; @@ -82,10 +82,10 @@ impl Function for RegexpReplaceFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let has_null = columns.iter().any(|col| col.column().is_null()); + let has_null = columns.iter().any(|col| col.is_null()); if has_null { return Ok(NullColumn::new(input_rows).arc()); } @@ -96,21 +96,15 @@ impl Function for RegexpReplaceFunction { for i in 3..columns.len() { match i { - 3 => pos = cast_column_field(&columns[3], &NullableType::arc(Int64Type::arc()))?, - 4 => { - occurrence = - cast_column_field(&columns[4], &NullableType::arc(Int64Type::arc()))? - } - _ => { - match_type = - cast_column_field(&columns[5], &NullableType::arc(StringType::arc()))? - } + 3 => pos = cast_column(&columns[3], &NullableType::arc(Int64Type::arc()))?, + 4 => occurrence = cast_column(&columns[4], &NullableType::arc(Int64Type::arc()))?, + _ => match_type = cast_column(&columns[5], &NullableType::arc(StringType::arc()))?, } } - let source = columns[0].column(); - let pat = columns[1].column(); - let repl = columns[2].column(); + let source = &columns[0]; + let pat = &columns[1]; + let repl = &columns[2]; if pat.is_const() && match_type.is_const() { let pat_value = pat.get_string(0)?; diff --git a/common/functions/src/scalars/strings/regexp_substr.rs b/common/functions/src/scalars/strings/regexp_substr.rs index 56ddb7253fcc..bdc967cc81f6 100644 --- a/common/functions/src/scalars/strings/regexp_substr.rs +++ b/common/functions/src/scalars/strings/regexp_substr.rs @@ -22,7 +22,7 @@ use common_exception::Result; use regex::bytes::Regex; use crate::scalars::assert_string; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::strings::regexp_instr::regexp_match_result; use crate::scalars::strings::regexp_instr::validate_regexp_arguments; use crate::scalars::strings::regexp_like::build_regexp_from_pattern; @@ -82,10 +82,10 @@ impl Function for RegexpSubStrFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let has_null = columns.iter().any(|col| col.column().is_null()); + let has_null = columns.iter().any(|col| col.is_null()); if has_null { return Ok(NullColumn::new(input_rows).arc()); } @@ -96,29 +96,23 @@ impl Function for RegexpSubStrFunction { for i in 2..columns.len() { match i { - 2 => pos = cast_column_field(&columns[2], &NullableType::arc(Int64Type::arc()))?, - 3 => { - occurrence = - cast_column_field(&columns[3], &NullableType::arc(Int64Type::arc()))? - } - _ => { - match_type = - cast_column_field(&columns[4], &NullableType::arc(StringType::arc()))? - } + 2 => pos = cast_column(&columns[2], &NullableType::arc(Int64Type::arc()))?, + 3 => occurrence = cast_column(&columns[3], &NullableType::arc(Int64Type::arc()))?, + _ => match_type = cast_column(&columns[4], &NullableType::arc(StringType::arc()))?, } } - let pat = columns[1].column(); + let pat = &columns[1]; if pat.is_const() && match_type.is_const() { let pat_value = pat.get_string(0)?; let mt_value = match_type.get_string(0)?; - let columns = [columns[0].column(), &pos, &occurrence]; + let columns = [&columns[0], &pos, &occurrence]; return self.a_regexp_substr_binary_scalar(&columns, &pat_value, &mt_value, input_rows); } - let columns = [columns[0].column(), pat, &pos, &occurrence, &match_type]; + let columns = [&columns[0], pat, &pos, &occurrence, &match_type]; self.a_regexp_substr_binary(&columns, input_rows) } diff --git a/common/functions/src/scalars/strings/repeat.rs b/common/functions/src/scalars/strings/repeat.rs index 518fc421c9bd..bb88686f7c7c 100644 --- a/common/functions/src/scalars/strings/repeat.rs +++ b/common/functions/src/scalars/strings/repeat.rs @@ -18,7 +18,7 @@ use common_datavalues::prelude::*; use common_exception::ErrorCode; use common_exception::Result; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; @@ -70,12 +70,12 @@ impl Function for RepeatFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let col1_viewer = Vu8::try_create_viewer(columns[0].column())?; + let col1_viewer = Vu8::try_create_viewer(&columns[0])?; - let col2 = cast_column_field(&columns[1], &UInt64Type::arc())?; + let col2 = cast_column(&columns[1], &UInt64Type::arc())?; let col2_viewer = u64::try_create_viewer(&col2)?; let mut builder = ColumnBuilder::::with_capacity(input_rows); diff --git a/common/functions/src/scalars/strings/replace.rs b/common/functions/src/scalars/strings/replace.rs index e78f19aea2ed..735bb2aca054 100644 --- a/common/functions/src/scalars/strings/replace.rs +++ b/common/functions/src/scalars/strings/replace.rs @@ -77,12 +77,12 @@ impl Function for ReplaceFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let view0 = Vu8::try_create_viewer(columns[0].column())?; - let view1 = Vu8::try_create_viewer(columns[1].column())?; - let view2 = Vu8::try_create_viewer(columns[2].column())?; + let view0 = Vu8::try_create_viewer(&columns[0])?; + let view1 = Vu8::try_create_viewer(&columns[1])?; + let view2 = Vu8::try_create_viewer(&columns[2])?; let mut values = Vec::with_capacity(view0.value_at(0).len() * input_rows); let mut offsets = Vec::with_capacity(input_rows + 1); diff --git a/common/functions/src/scalars/strings/space.rs b/common/functions/src/scalars/strings/space.rs index a75fd021e542..bd1ccc144ae7 100644 --- a/common/functions/src/scalars/strings/space.rs +++ b/common/functions/src/scalars/strings/space.rs @@ -60,13 +60,13 @@ impl Function for SpaceFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { let mut ctx = EvalContext::default(); with_match_primitive_type_id!(columns[0].data_type().data_type_id(), |$S| { let func = |n: $S, _ctx: &mut EvalContext| -> Vu8 { vec![32u8; n.as_()] }; - let col = scalar_unary_op::<$S, Vu8, _>(columns[0].column(), func, &mut ctx)?; + let col = scalar_unary_op::<$S, Vu8, _>(&columns[0], func, &mut ctx)?; Ok(Arc::new(col)) },{ unreachable!() diff --git a/common/functions/src/scalars/strings/strcmp.rs b/common/functions/src/scalars/strings/strcmp.rs index cdf14773d08a..7bcb1bb8ad8b 100644 --- a/common/functions/src/scalars/strings/strcmp.rs +++ b/common/functions/src/scalars/strings/strcmp.rs @@ -60,12 +60,12 @@ impl Function for StrcmpFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, ) -> Result { let col = scalar_binary_op::( - columns[0].column(), - columns[1].column(), + &columns[0], + &columns[1], strcmp, &mut EvalContext::default(), )?; diff --git a/common/functions/src/scalars/strings/string2number.rs b/common/functions/src/scalars/strings/string2number.rs index af68bd23b6ef..8c112a8a89ff 100644 --- a/common/functions/src/scalars/strings/string2number.rs +++ b/common/functions/src/scalars/strings/string2number.rs @@ -86,11 +86,11 @@ where fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, - ) -> Result { + ) -> Result { let mut op = T::default(); - let column: &StringColumn = Series::check_get(columns[0].column())?; + let column: &StringColumn = Series::check_get(&columns[0])?; let mut array = Vec::with_capacity(input_rows); for x in column.iter() { let r = op.apply(x); diff --git a/common/functions/src/scalars/strings/string2string.rs b/common/functions/src/scalars/strings/string2string.rs index d8721a7eb11d..70ca3da6c1ba 100644 --- a/common/functions/src/scalars/strings/string2string.rs +++ b/common/functions/src/scalars/strings/string2string.rs @@ -70,11 +70,11 @@ impl Function for String2StringFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, - ) -> Result { + ) -> Result { let mut op = T::default(); - let column: &StringColumn = Series::check_get(columns[0].column())?; + let column: &StringColumn = Series::check_get(&columns[0])?; let estimate_bytes = op.estimate_bytes(column); let col = StringColumn::try_transform(column, estimate_bytes, |val, buffer| { op.try_apply(val, buffer) diff --git a/common/functions/src/scalars/strings/substring.rs b/common/functions/src/scalars/strings/substring.rs index 3f43e2a76f79..6b7f72095864 100644 --- a/common/functions/src/scalars/strings/substring.rs +++ b/common/functions/src/scalars/strings/substring.rs @@ -20,7 +20,7 @@ use common_exception::Result; use itertools::izip; use crate::scalars::assert_string; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; @@ -78,19 +78,19 @@ impl Function for SubstringFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let s_column = cast_column_field(&columns[0], &StringType::arc())?; + let s_column = cast_column(&columns[0], &StringType::arc())?; let s_viewer = Vu8::try_create_viewer(&s_column)?; - let p_column = cast_column_field(&columns[1], &Int64Type::arc())?; + let p_column = cast_column(&columns[1], &Int64Type::arc())?; let p_viewer = i64::try_create_viewer(&p_column)?; let mut builder = ColumnBuilder::::with_capacity(input_rows); if columns.len() > 2 { - let p2_column = cast_column_field(&columns[2], &UInt64Type::arc())?; + let p2_column = cast_column(&columns[2], &UInt64Type::arc())?; let p2_viewer = u64::try_create_viewer(&p2_column)?; let iter = izip!(s_viewer, p_viewer, p2_viewer); diff --git a/common/functions/src/scalars/strings/substring_index.rs b/common/functions/src/scalars/strings/substring_index.rs index 4efa9013f2bb..4fd651c752a5 100644 --- a/common/functions/src/scalars/strings/substring_index.rs +++ b/common/functions/src/scalars/strings/substring_index.rs @@ -19,7 +19,7 @@ use common_exception::ErrorCode; use common_exception::Result; use itertools::izip; -use crate::scalars::cast_column_field; +use crate::scalars::cast_column; use crate::scalars::Function; use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; @@ -73,16 +73,16 @@ impl Function for SubstringIndexFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { - let s_column = cast_column_field(&columns[0], &StringType::arc())?; + let s_column = cast_column(&columns[0], &StringType::arc())?; let s_viewer = Vu8::try_create_viewer(&s_column)?; - let d_column = cast_column_field(&columns[1], &StringType::arc())?; + let d_column = cast_column(&columns[1], &StringType::arc())?; let d_viewer = Vu8::try_create_viewer(&d_column)?; - let c_column = cast_column_field(&columns[2], &Int64Type::arc())?; + let c_column = cast_column(&columns[2], &Int64Type::arc())?; let c_viewer = i64::try_create_viewer(&c_column)?; let iter = izip!(s_viewer, d_viewer, c_viewer); diff --git a/common/functions/src/scalars/strings/unhex.rs b/common/functions/src/scalars/strings/unhex.rs index d5e774b7d5ed..c6843c8fcb92 100644 --- a/common/functions/src/scalars/strings/unhex.rs +++ b/common/functions/src/scalars/strings/unhex.rs @@ -55,16 +55,12 @@ impl Function for UnhexFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &ColumnsWithField, + columns: &[ColumnRef], input_rows: usize, ) -> Result { const BUFFER_SIZE: usize = 32; - let col = columns[0] - .column() - .as_any() - .downcast_ref::() - .unwrap(); + let col = columns[0].as_any().downcast_ref::().unwrap(); let mut builder: ColumnBuilder = ColumnBuilder::with_capacity(input_rows); @@ -81,7 +77,7 @@ impl Function for UnhexFunction { "{} can not unhex because: {}", String::from_utf8_lossy(val), err - ))) + ))); } } } else { diff --git a/common/functions/src/scalars/tuples/tuple.rs b/common/functions/src/scalars/tuples/tuple.rs index 7a846809d793..2cda28497faf 100644 --- a/common/functions/src/scalars/tuples/tuple.rs +++ b/common/functions/src/scalars/tuples/tuple.rs @@ -15,6 +15,7 @@ use std::fmt; use std::sync::Arc; +use common_datavalues::ColumnRef; use common_datavalues::DataTypeImpl; use common_datavalues::StructColumn; use common_datavalues::StructType; @@ -70,13 +71,10 @@ impl Function for TupleFunction { fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, - ) -> Result { - let cols = columns - .iter() - .map(|v| v.column().clone()) - .collect::>(); + ) -> Result { + let cols = columns.iter().map(|v| v.clone()).collect::>(); let arr: StructColumn = StructColumn::from_data(cols, self.result_type.clone()); Ok(Arc::new(arr)) } diff --git a/common/functions/src/scalars/uuids/uuid_creator.rs b/common/functions/src/scalars/uuids/uuid_creator.rs index 4e9b99f6c892..708ab73c8e49 100644 --- a/common/functions/src/scalars/uuids/uuid_creator.rs +++ b/common/functions/src/scalars/uuids/uuid_creator.rs @@ -16,6 +16,7 @@ use std::fmt; use std::marker::PhantomData; use common_datavalues::Column; +use common_datavalues::ColumnRef; use common_datavalues::ConstColumn; use common_datavalues::DataTypeImpl; use common_datavalues::NewColumn; @@ -96,9 +97,9 @@ where T: UUIDCreator + Clone + Sync + Send + 'static fn eval( &self, _func_ctx: FunctionContext, - _columns: &common_datavalues::ColumnsWithField, + _columns: &[ColumnRef], input_rows: usize, - ) -> Result { + ) -> Result { let uuid = T::create(); let col = StringColumn::new_from_slice(vec![uuid.to_string()]); diff --git a/common/functions/src/scalars/uuids/uuid_verifier.rs b/common/functions/src/scalars/uuids/uuid_verifier.rs index 0e815bb23343..923a30ee4bc1 100644 --- a/common/functions/src/scalars/uuids/uuid_verifier.rs +++ b/common/functions/src/scalars/uuids/uuid_verifier.rs @@ -19,6 +19,7 @@ use std::sync::Arc; use common_datavalues::BooleanColumn; use common_datavalues::BooleanType; +use common_datavalues::ColumnRef; use common_datavalues::DataType; use common_datavalues::DataTypeImpl; use common_datavalues::Scalar; @@ -122,11 +123,11 @@ where T: UUIDVerifier + Clone + Sync + Send + 'static fn eval( &self, _func_ctx: FunctionContext, - columns: &common_datavalues::ColumnsWithField, + columns: &[ColumnRef], _input_rows: usize, - ) -> Result { + ) -> Result { let result_column = if columns[0].data_type().data_type_id() == TypeID::String { - let viewer = Vu8::try_create_viewer(columns[0].column())?; + let viewer = Vu8::try_create_viewer(&columns[0])?; BooleanColumn::from_iterator(viewer.iter().map(|uuid_bytes| { if let Ok(uuid_str) = str::from_utf8(uuid_bytes) { if let Ok(uuid) = Uuid::parse_str(uuid_str) { diff --git a/common/planners/src/plan_expression_monotonicity.rs b/common/planners/src/plan_expression_monotonicity.rs index 043d57a47768..629b9d330e8b 100644 --- a/common/planners/src/plan_expression_monotonicity.rs +++ b/common/planners/src/plan_expression_monotonicity.rs @@ -15,7 +15,6 @@ use std::collections::HashMap; use common_datavalues::prelude::*; -use common_datavalues::DataField; use common_datavalues::DataSchemaRef; use common_exception::ErrorCode; use common_exception::Result; @@ -89,9 +88,8 @@ impl ExpressionMonotonicityVisitor { fn try_calculate_boundary( func: &dyn Function, - result_type: &DataTypeImpl, - args: Vec>, - ) -> Result> { + args: Vec>, + ) -> Result> { if args.iter().any(|col| col.is_none()) { Ok(None) } else { @@ -101,9 +99,7 @@ impl ExpressionMonotonicityVisitor { .collect::>(); // TODO(veeupup): whether we need to pass function context here? let col = func.eval(FunctionContext::default(), &input_columns, 1)?; - let data_field = DataField::new("dummy", result_type.clone()); - let data_column_field = ColumnWithField::new(col, data_field); - Ok(Some(data_column_field)) + Ok(Some(col)) } } @@ -119,7 +115,7 @@ impl ExpressionMonotonicityVisitor { return Err(ErrorCode::LogicalError(format!( "Expected {} arguments, actual {}.", args_size, index - ))) + ))); } Some((arg_type, monotonic)) => { left_vec.push(monotonic.left.clone()); @@ -156,8 +152,8 @@ impl ExpressionMonotonicityVisitor { ))); } - monotonic.left = Self::try_calculate_boundary(func.as_ref(), &return_type, left_vec)?; - monotonic.right = Self::try_calculate_boundary(func.as_ref(), &return_type, right_vec)?; + monotonic.left = Self::try_calculate_boundary(func.as_ref(), left_vec)?; + monotonic.right = Self::try_calculate_boundary(func.as_ref(), right_vec)?; self.stack.push((return_type, monotonic)); Ok(self) @@ -236,28 +232,23 @@ impl ExpressionVisitor for ExpressionMonotonicityVisitor { is_monotonic: true, is_positive: true, is_constant: false, - left: left.clone(), - right: right.clone(), + left: left.clone().map(|c| c.column().clone()), + right: right.clone().map(|c| c.column().clone()), }; self.stack.push((return_type.clone(), monotonic)); Ok(self) } Expression::Literal { - value, - column_name, - data_type, + value, data_type, .. } => { - let name = column_name.clone().unwrap_or(format!("{}", value)); - let data_field = DataField::new(&name, data_type.clone()); let col = data_type.create_constant_column(value, 1)?; - let data_column_field = ColumnWithField::new(col, data_field); let monotonic = Monotonicity { is_monotonic: true, is_positive: true, is_constant: true, - left: Some(data_column_field.clone()), - right: Some(data_column_field), + left: Some(col.clone()), + right: Some(col), }; self.stack.push((data_type.clone(), monotonic)); diff --git a/common/streams/src/stream_cast.rs b/common/streams/src/stream_cast.rs index 08f2e794200f..76e24210f1a8 100644 --- a/common/streams/src/stream_cast.rs +++ b/common/streams/src/stream_cast.rs @@ -49,16 +49,11 @@ impl CastStream { fn cast(&self, data_block: &DataBlock) -> Result { let rows = data_block.num_rows(); - let iter = self - .functions - .iter() - .zip(data_block.schema().fields()) - .zip(data_block.columns()); + let iter = self.functions.iter().zip(data_block.columns()); let mut columns = Vec::with_capacity(data_block.num_columns()); - for ((cast_func, input_field), column) in iter { - let column = ColumnWithField::new(column.clone(), input_field.clone()); + for (cast_func, column) in iter { // TODO(veeupup): we nned to use the real function context here - columns.push(cast_func.eval(self.func_ctx.clone(), &[column], rows)?); + columns.push(cast_func.eval(self.func_ctx.clone(), &[column.clone()], rows)?); } Ok(DataBlock::create(self.output_schema.clone(), columns)) diff --git a/query/src/common/expression_evaluator.rs b/query/src/common/expression_evaluator.rs index 8fb76f83c142..794d4b9390c5 100644 --- a/query/src/common/expression_evaluator.rs +++ b/query/src/common/expression_evaluator.rs @@ -14,8 +14,6 @@ use common_datablocks::DataBlock; use common_datavalues::ColumnRef; -use common_datavalues::ColumnWithField; -use common_datavalues::DataField; use common_datavalues::DataType; use common_datavalues::DataTypeImpl; use common_exception::ErrorCode; @@ -54,10 +52,7 @@ impl ExpressionEvaluator { let arg_types2: Vec<&DataTypeImpl> = arg_types.iter().collect(); let func = FunctionFactory::instance().get(op, &arg_types2)?; - let columns = [ColumnWithField::new( - result.clone(), - DataField::new("", result.data_type()), - )]; + let columns = [result.clone()]; func.eval(func_ctx, &columns, block.num_rows()) } @@ -69,16 +64,7 @@ impl ExpressionEvaluator { let arg_types2: Vec<&DataTypeImpl> = arg_types.iter().collect(); let func = FunctionFactory::instance().get(op, &arg_types2)?; - let columns = [ - ColumnWithField::new( - left_result.clone(), - DataField::new("", left_result.data_type()), - ), - ColumnWithField::new( - right_result.clone(), - DataField::new("", right_result.data_type()), - ), - ]; + let columns = [left_result.clone(), right_result.clone()]; func.eval(func_ctx, &columns, block.num_rows()) } @@ -92,13 +78,8 @@ impl ExpressionEvaluator { let arg_types2: Vec<&DataTypeImpl> = arg_types.iter().collect(); let func = FunctionFactory::instance().get(op, &arg_types2)?; - let columns: Vec = results - .into_iter() - .map(|col| { - ColumnWithField::new(col.clone(), DataField::new("", col.data_type())) - }) - .collect(); - func.eval(func_ctx, &columns, block.num_rows()) + + func.eval(func_ctx, &results, block.num_rows()) } Expression::AggregateFunction { .. } => Err(ErrorCode::LogicalError( @@ -122,10 +103,7 @@ impl ExpressionEvaluator { CastFunction::create(&func_name, &type_name) }?; - let columns = [ColumnWithField::new( - result.clone(), - DataField::new("", result.data_type()), - )]; + let columns = [result.clone()]; func.eval(func_ctx, &columns, block.num_rows()) } @@ -153,13 +131,8 @@ impl ExpressionEvaluator { let func_name = "get_path"; let func = FunctionFactory::instance().get(func_name, &arg_types2)?; - let columns: Vec = results - .into_iter() - .map(|col| { - ColumnWithField::new(col.clone(), DataField::new("", col.data_type())) - }) - .collect(); - func.eval(func_ctx, &columns, block.num_rows()) + + func.eval(func_ctx, &results, block.num_rows()) } Expression::Wildcard => Err(ErrorCode::LogicalError("Unsupported wildcard expression")), diff --git a/query/src/pipelines/new/processors/transforms/transform_cast_schema.rs b/query/src/pipelines/new/processors/transforms/transform_cast_schema.rs index 8590a02c3dda..6f181e5639fd 100644 --- a/query/src/pipelines/new/processors/transforms/transform_cast_schema.rs +++ b/query/src/pipelines/new/processors/transforms/transform_cast_schema.rs @@ -15,7 +15,6 @@ use std::sync::Arc; use common_datablocks::DataBlock; -use common_datavalues::ColumnWithField; use common_datavalues::DataSchemaRef; use common_exception::Result; use common_functions::scalars::Function; @@ -56,15 +55,10 @@ impl Transform for TransformCastSchema { fn transform(&mut self, data: DataBlock) -> Result { let rows = data.num_rows(); - let iter = self - .functions - .iter() - .zip(data.schema().fields()) - .zip(data.columns()); + let iter = self.functions.iter().zip(data.columns()); let mut columns = Vec::with_capacity(data.num_columns()); - for ((cast_func, input_field), column) in iter { - let column = ColumnWithField::new(column.clone(), input_field.clone()); - columns.push(cast_func.eval(self.func_ctx.clone(), &[column], rows)?); + for (cast_func, column) in iter { + columns.push(cast_func.eval(self.func_ctx.clone(), &[column.clone()], rows)?); } Ok(DataBlock::create(self.output_schema.clone(), columns)) } diff --git a/query/src/pipelines/transforms/transform_expression_executor.rs b/query/src/pipelines/transforms/transform_expression_executor.rs index 1d7c56e280e7..8a59dfca961b 100644 --- a/query/src/pipelines/transforms/transform_expression_executor.rs +++ b/query/src/pipelines/transforms/transform_expression_executor.rs @@ -190,7 +190,7 @@ impl ExpressionExecutor { let column = column_map.get(arg.as_str()).cloned().ok_or_else(|| { ErrorCode::LogicalError("Arguments must be prepared before function transform") })?; - arg_columns.push(column); + arg_columns.push(column.column().clone()); } let tz = self.ctx.get_settings().get_timezone()?; diff --git a/query/src/storages/index/range_filter.rs b/query/src/storages/index/range_filter.rs index 01a0e4570667..b74d1db7999d 100644 --- a/query/src/storages/index/range_filter.rs +++ b/query/src/storages/index/range_filter.rs @@ -252,7 +252,7 @@ impl StatColumn { return Ok(None); } - let column_with_field_opt = match self.stat_type { + let column = match self.stat_type { StatType::Min => { if monotonicity.is_positive { monotonicity.left @@ -270,7 +270,7 @@ impl StatColumn { _ => unreachable!(), }; - Ok(column_with_field_opt.map(|v| v.column().slice(0, 1))) + Ok(column.map(|v| v.slice(0, 1))) } } From 8d0bed283effd0bc97544da62b138544b3c85d43 Mon Sep 17 00:00:00 2001 From: leiysky Date: Sun, 1 May 2022 00:26:52 +0800 Subject: [PATCH 2/2] fix clippy Signed-off-by: leiysky --- .../functions/src/scalars/conditionals/if.rs | 4 +- .../src/scalars/conditionals/in_basic.rs | 2 +- .../functions/src/scalars/strings/concat.rs | 2 +- .../src/scalars/strings/concat_ws.rs | 10 ++--- common/functions/src/scalars/strings/elt.rs | 2 +- common/functions/src/scalars/strings/field.rs | 2 +- common/functions/src/scalars/tuples/tuple.rs | 2 +- .../it/scalars/dates/interval_function.rs | 20 ++++++++-- .../functions/tests/it/scalars/expressions.rs | 8 ++-- .../tests/it/scalars/scalar_function_test.rs | 14 +++---- .../src/plan_expression_monotonicity.rs | 14 +++---- .../tests/it/plan_expression_monotonicity.rs | 40 ++++++++----------- .../optimizers/optimizer_top_n_push_down.rs | 4 +- query/src/storages/index/range_filter.rs | 6 +-- 14 files changed, 67 insertions(+), 63 deletions(-) diff --git a/common/functions/src/scalars/conditionals/if.rs b/common/functions/src/scalars/conditionals/if.rs index 753f9a2e8e9c..124969e926cb 100644 --- a/common/functions/src/scalars/conditionals/if.rs +++ b/common/functions/src/scalars/conditionals/if.rs @@ -58,9 +58,9 @@ impl IfFunction { // whether nullable or not, we can use viewer to make it let cond_viewer = bool::try_create_viewer(cond_col)?; if cond_viewer.value_at(0) { - return Ok(columns[0].clone()); + Ok(columns[0].clone()) } else { - return Ok(columns[1].clone()); + Ok(columns[1].clone()) } } diff --git a/common/functions/src/scalars/conditionals/in_basic.rs b/common/functions/src/scalars/conditionals/in_basic.rs index 6cdd8332b3ae..67a10cdf60f1 100644 --- a/common/functions/src/scalars/conditionals/in_basic.rs +++ b/common/functions/src/scalars/conditionals/in_basic.rs @@ -133,7 +133,7 @@ impl Function for InFunction { .map(|column| column.data_type().data_type_id()) .all(|t| t.is_string() || t.is_date_or_date_time()) { - true => columns[0].data_type().clone(), + true => columns[0].data_type(), false => { return Result::Err(ErrorCode::BadDataValueType("test")); } diff --git a/common/functions/src/scalars/strings/concat.rs b/common/functions/src/scalars/strings/concat.rs index bd6ae6620209..6ad4b4b58b1a 100644 --- a/common/functions/src/scalars/strings/concat.rs +++ b/common/functions/src/scalars/strings/concat.rs @@ -64,7 +64,7 @@ impl Function for ConcatFunction { ) -> Result { let viewers = columns .iter() - .map(|c| Vu8::try_create_viewer(c)) + .map(Vu8::try_create_viewer) .collect::>>()?; let mut values: Vec = Vec::with_capacity(input_rows * columns.len()); diff --git a/common/functions/src/scalars/strings/concat_ws.rs b/common/functions/src/scalars/strings/concat_ws.rs index 88d9fa887a43..db20561d4d8f 100644 --- a/common/functions/src/scalars/strings/concat_ws.rs +++ b/common/functions/src/scalars/strings/concat_ws.rs @@ -70,7 +70,7 @@ impl ConcatWsFunction { ) -> Result { let viewers = columns .iter() - .map(|column| Vu8::try_create_viewer(&column)) + .map(Vu8::try_create_viewer) .collect::>>()?; let mut builder = MutableStringColumn::with_capacity(rows); @@ -96,10 +96,10 @@ impl ConcatWsFunction { columns: &[ColumnRef], rows: usize, ) -> Result { - let sep_c = Series::check_get_scalar::(&sep_column)?; + let sep_c = Series::check_get_scalar::(sep_column)?; let viewers = columns .iter() - .map(|column| Vu8::try_create_viewer(&column)) + .map(Vu8::try_create_viewer) .collect::>>()?; let mut builder = MutableStringColumn::with_capacity(rows); @@ -126,10 +126,10 @@ impl ConcatWsFunction { columns: &[ColumnRef], rows: usize, ) -> Result { - let sep_viewer = Vu8::try_create_viewer(&sep_column)?; + let sep_viewer = Vu8::try_create_viewer(sep_column)?; let viewers = columns .iter() - .map(|column| Vu8::try_create_viewer(&column)) + .map(Vu8::try_create_viewer) .collect::>>()?; let mut builder = NullableColumnBuilder::::with_capacity(rows); diff --git a/common/functions/src/scalars/strings/elt.rs b/common/functions/src/scalars/strings/elt.rs index 89314867e29e..ca830dfdacdb 100644 --- a/common/functions/src/scalars/strings/elt.rs +++ b/common/functions/src/scalars/strings/elt.rs @@ -138,7 +138,7 @@ where let viewers = columns[1..] .iter() - .map(|column| Vu8::try_create_viewer(column)) + .map(Vu8::try_create_viewer) .collect::>>()?; match nullable { false => { diff --git a/common/functions/src/scalars/strings/field.rs b/common/functions/src/scalars/strings/field.rs index 6904058e269e..817a1ed0b6f1 100644 --- a/common/functions/src/scalars/strings/field.rs +++ b/common/functions/src/scalars/strings/field.rs @@ -67,7 +67,7 @@ impl Function for FieldFunction { let viewers = columns .iter() .skip(1) - .map(|c| Vu8::try_create_viewer(c)) + .map(Vu8::try_create_viewer) .collect::>>()?; let mut values = Vec::with_capacity(input_rows); diff --git a/common/functions/src/scalars/tuples/tuple.rs b/common/functions/src/scalars/tuples/tuple.rs index 2cda28497faf..ea62ae272f25 100644 --- a/common/functions/src/scalars/tuples/tuple.rs +++ b/common/functions/src/scalars/tuples/tuple.rs @@ -74,7 +74,7 @@ impl Function for TupleFunction { columns: &[ColumnRef], _input_rows: usize, ) -> Result { - let cols = columns.iter().map(|v| v.clone()).collect::>(); + let cols = columns.to_vec(); let arr: StructColumn = StructColumn::from_data(cols, self.result_type.clone()); Ok(Arc::new(arr)) } diff --git a/common/functions/tests/it/scalars/dates/interval_function.rs b/common/functions/tests/it/scalars/dates/interval_function.rs index a02d01a9743a..b697603630f7 100644 --- a/common/functions/tests/it/scalars/dates/interval_function.rs +++ b/common/functions/tests/it/scalars/dates/interval_function.rs @@ -90,7 +90,10 @@ fn test_add_months() -> Result<()> { AddMonthsFunction::try_create_func("addMonths", 1, &[&DateType::arc(), arg])?; let col = add_months.eval( FunctionContext::default(), - &[column("date"), column(field)], + &[ + column("date").column().clone(), + column(field).column().clone(), + ], 1, )?; assert_eq!(col.len(), 1); @@ -119,7 +122,10 @@ fn test_add_months() -> Result<()> { AddMonthsFunction::try_create_func("addMonths", 1, &[&TimestampType::arc(0), arg])?; let col = add_months.eval( FunctionContext::default(), - &[column("datetime"), column(field)], + &[ + column("datetime").column().clone(), + column(field).column().clone(), + ], 1, )?; assert_eq!(col.len(), 1); @@ -206,7 +212,10 @@ fn test_add_subtract_seconds() -> Result<()> { AddTimesFunction::try_create_func("addSeconds", 1, &[&TimestampType::arc(0), arg])?; let col = add_seconds.eval( FunctionContext::default(), - &[column("datetime"), column(field)], + &[ + column("datetime").column().clone(), + column(field).column().clone(), + ], 1, )?; assert_eq!(col.len(), 1); @@ -237,7 +246,10 @@ fn test_add_subtract_seconds() -> Result<()> { ])?; let col = add_seconds.eval( FunctionContext::default(), - &[column("datetime"), column(field)], + &[ + column("datetime").column().clone(), + column(field).column().clone(), + ], 1, )?; assert_eq!(col.len(), 1); diff --git a/common/functions/tests/it/scalars/expressions.rs b/common/functions/tests/it/scalars/expressions.rs index d4132759ccbd..9e3fd746183c 100644 --- a/common/functions/tests/it/scalars/expressions.rs +++ b/common/functions/tests/it/scalars/expressions.rs @@ -270,7 +270,7 @@ fn test_cast_variant_function() -> Result<()> { name: "cast-float64-to-variant-passed", columns: vec![ColumnWithField::new( Series::from_data(vec![0.12345678912121212f64, - 12.345678912,]), + 12.345678912, ]), DataField::new("dummy_1", Float64Type::arc()), )], expect: Series::from_data(vec![ @@ -298,9 +298,10 @@ fn test_cast_variant_function() -> Result<()> { ]; for (test_func, test) in tests { + let arguments: Vec = test.columns.iter().map(|c| c.column().clone()).collect(); match test_func.eval( FunctionContext::default(), - &test.columns, + &arguments, test.columns[0].column().len(), ) { Ok(v) => { @@ -595,9 +596,10 @@ fn test_variant_cast_function() -> Result<()> { ]; for (test_func, test) in tests { + let arguments: Vec = test.columns.iter().map(|c| c.column().clone()).collect(); match test_func.eval( FunctionContext::default(), - &test.columns, + &arguments, test.columns[0].column().len(), ) { Ok(v) => { diff --git a/common/functions/tests/it/scalars/scalar_function_test.rs b/common/functions/tests/it/scalars/scalar_function_test.rs index 7d3b35f33921..339e127a42e3 100644 --- a/common/functions/tests/it/scalars/scalar_function_test.rs +++ b/common/functions/tests/it/scalars/scalar_function_test.rs @@ -70,7 +70,8 @@ pub fn test_scalar_functions_with_type( rows_size = c.column().len(); } - match test_eval_with_type(op, rows_size, &test.columns, &arguments_type) { + let arguments: Vec = test.columns.iter().map(|c| c.column().clone()).collect(); + match test_eval_with_type(op, rows_size, &arguments, &arguments_type) { Ok(v) => { let v = v.convert_full_column(); @@ -91,16 +92,11 @@ pub fn test_eval(op: &str, columns: &[ColumnRef]) -> Result { let mut arguments = Vec::with_capacity(columns.len()); let mut arguments_type = Vec::with_capacity(columns.len()); - for (index, arg_column) in columns.iter().enumerate() { - let f = ColumnWithField::new( - arg_column.clone(), - DataField::new(&format!("dummy_{}", index), arg_column.data_type()), - ); - + for arg_column in columns.iter() { arguments_type.push(arg_column.data_type()); rows_size = arg_column.len(); - arguments.push(f); + arguments.push(arg_column.clone()); } let mut types = Vec::with_capacity(columns.len()); @@ -115,7 +111,7 @@ pub fn test_eval(op: &str, columns: &[ColumnRef]) -> Result { pub fn test_eval_with_type( op: &str, rows_size: usize, - arguments: &[ColumnWithField], + arguments: &[ColumnRef], arguments_type: &[&DataTypeImpl], ) -> Result { let func = FunctionFactory::instance().get(op, arguments_type)?; diff --git a/common/planners/src/plan_expression_monotonicity.rs b/common/planners/src/plan_expression_monotonicity.rs index 629b9d330e8b..93216eca546c 100644 --- a/common/planners/src/plan_expression_monotonicity.rs +++ b/common/planners/src/plan_expression_monotonicity.rs @@ -53,7 +53,7 @@ pub struct ExpressionMonotonicityVisitor { // HashMap // variable_left: the variable range left. // variable_right: the variable range right. - variables: HashMap, Option)>, + variables: HashMap, Option)>, stack: Vec<(DataTypeImpl, Monotonicity)>, @@ -63,7 +63,7 @@ pub struct ExpressionMonotonicityVisitor { impl ExpressionMonotonicityVisitor { fn create( input_schema: DataSchemaRef, - variables: HashMap, Option)>, + variables: HashMap, Option)>, single_point: bool, ) -> Self { Self { @@ -164,7 +164,7 @@ impl ExpressionMonotonicityVisitor { pub fn check_expression( schema: DataSchemaRef, expr: &Expression, - variables: HashMap, Option)>, + variables: HashMap, Option)>, single_point: bool, ) -> Monotonicity { let visitor = Self::create(schema, variables, single_point); @@ -179,8 +179,8 @@ impl ExpressionMonotonicityVisitor { pub fn extract_sort_column( schema: DataSchemaRef, sort_expr: &Expression, - left: Option, - right: Option, + left: Option, + right: Option, column_name: &str, ) -> Result { if let Expression::Sort { @@ -232,8 +232,8 @@ impl ExpressionVisitor for ExpressionMonotonicityVisitor { is_monotonic: true, is_positive: true, is_constant: false, - left: left.clone().map(|c| c.column().clone()), - right: right.clone().map(|c| c.column().clone()), + left: left.clone(), + right: right.clone(), }; self.stack.push((return_type.clone(), monotonic)); diff --git a/common/planners/tests/it/plan_expression_monotonicity.rs b/common/planners/tests/it/plan_expression_monotonicity.rs index 0959df22ef8f..2470d10acec9 100644 --- a/common/planners/tests/it/plan_expression_monotonicity.rs +++ b/common/planners/tests/it/plan_expression_monotonicity.rs @@ -23,38 +23,32 @@ struct Test { name: &'static str, expr: Expression, column: &'static str, - left: Option, - right: Option, + left: Option, + right: Option, expect_mono: Monotonicity, } -fn create_f64(d: f64) -> Option { - let data_field = DataField::new("x", f64::to_data_type()); - let col = data_field - .data_type() +fn create_f64(d: f64) -> Option { + let col = f64::to_data_type() .create_constant_column(&DataValue::Float64(d), 1) .unwrap(); - Some(ColumnWithField::new(col, data_field)) + Some(col) } -fn create_u8(d: u8) -> Option { - let data_field = DataField::new("x", u8::to_data_type()); - let col = data_field - .data_type() +fn create_u8(d: u8) -> Option { + let col = u8::to_data_type() .create_constant_column(&DataValue::UInt64(d as u64), 1) .unwrap(); - Some(ColumnWithField::new(col, data_field)) + Some(col) } -fn create_datetime(d: i64) -> Option { - let data_field = DataField::new("x", TimestampType::arc(0)); - let col = data_field - .data_type() +fn create_datetime(d: i64) -> Option { + let col = TimestampType::arc(0) .create_constant_column(&DataValue::Int64(d), 1) .unwrap(); - Some(ColumnWithField::new(col, data_field)) + Some(col) } fn verify_test(t: Test) -> Result<()> { @@ -69,8 +63,8 @@ fn verify_test(t: Test) -> Result<()> { let mut single_point = false; if t.left.is_some() && t.right.is_some() { - let left = t.left.unwrap().column().get_checked(0)?; - let right = t.right.unwrap().column().get_checked(0)?; + let left = t.left.unwrap().get_checked(0)?; + let right = t.right.unwrap().get_checked(0)?; if left == right { single_point = true; } @@ -108,16 +102,16 @@ fn verify_test(t: Test) -> Result<()> { if expected_left.is_none() { assert!(left.is_none(), "{} left", t.name); } else { - let left_val = left.unwrap().column().get_checked(0)?; - let expected_left_val = expected_left.unwrap().column().get_checked(0)?; + let left_val = left.unwrap().get_checked(0)?; + let expected_left_val = expected_left.unwrap().get_checked(0)?; assert!(left_val == expected_left_val, "{}", t.name); } if expected_right.is_none() { assert!(right.is_none(), "{} right", t.name); } else { - let right_val = right.unwrap().column().get_checked(0)?; - let expected_right_val = expected_right.unwrap().column().get_checked(0)?; + let right_val = right.unwrap().get_checked(0)?; + let expected_right_val = expected_right.unwrap().get_checked(0)?; assert!(right_val == expected_right_val, "{}", t.name); } } diff --git a/query/src/optimizers/optimizer_top_n_push_down.rs b/query/src/optimizers/optimizer_top_n_push_down.rs index 174f94405b2c..d1d1faa6b480 100644 --- a/query/src/optimizers/optimizer_top_n_push_down.rs +++ b/query/src/optimizers/optimizer_top_n_push_down.rs @@ -175,8 +175,8 @@ impl TopNPushDownImpl { match ExpressionMonotonicityVisitor::extract_sort_column( schema.clone(), expr, - left, - right, + left.map(|c| c.column().clone()), + right.map(|c| c.column().clone()), column_name, ) { Ok(new_expr) => Ok(new_expr), diff --git a/query/src/storages/index/range_filter.rs b/query/src/storages/index/range_filter.rs index b74d1db7999d..c0fe472cc867 100644 --- a/query/src/storages/index/range_filter.rs +++ b/query/src/storages/index/range_filter.rs @@ -235,10 +235,10 @@ impl StatColumn { } let min_col = v.data_type().create_constant_column(&stat.min, 1)?; - let variable_left = Some(ColumnWithField::new(min_col, v.clone())); + let variable_left = Some(min_col); let max_col = v.data_type().create_constant_column(&stat.max, 1)?; - let variable_right = Some(ColumnWithField::new(max_col, v.clone())); + let variable_right = Some(max_col); variables.insert(v.name().clone(), (variable_left, variable_right)); } @@ -307,7 +307,7 @@ impl<'a> VerifiableExprBuilder<'a> { (0, 0) => { return Err(ErrorCode::UnknownException( "Constant expression donot need to be handled", - )) + )); } (_, 0) => (vec![exprs[0].clone(), exprs[1].clone()], vec![lhs_cols], op), (0, _) => {