From fa428560b40134a4fb9151f5b78164a6797275d4 Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Wed, 21 Jun 2023 16:28:45 +1000 Subject: [PATCH] chore: little cleanup to reuse the `NUMERICS` list --- iox_query_influxql/src/plan/udaf.rs | 2 +- iox_query_influxql/src/plan/udf.rs | 34 ++++++++++++++--------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/iox_query_influxql/src/plan/udaf.rs b/iox_query_influxql/src/plan/udaf.rs index c7023a8a05..8d6d8b47ec 100644 --- a/iox_query_influxql/src/plan/udaf.rs +++ b/iox_query_influxql/src/plan/udaf.rs @@ -11,7 +11,7 @@ use std::sync::Arc; /// A list of the numeric types supported by InfluxQL that can be be used /// as input to user-defined aggregate functions. -static NUMERICS: &[DataType] = &[DataType::Int64, DataType::UInt64, DataType::Float64]; +pub(crate) static NUMERICS: &[DataType] = &[DataType::Int64, DataType::UInt64, DataType::Float64]; /// Name of the `MOVING_AVERAGE` user-defined aggregate function. pub(crate) const MOVING_AVERAGE_NAME: &str = "moving_average"; diff --git a/iox_query_influxql/src/plan/udf.rs b/iox_query_influxql/src/plan/udf.rs index c2183ce03e..8581ff1f03 100644 --- a/iox_query_influxql/src/plan/udf.rs +++ b/iox_query_influxql/src/plan/udf.rs @@ -6,6 +6,7 @@ //! rewritten at a later stage of planning, with more context available. use crate::plan::error; +use crate::plan::udaf::NUMERICS; use crate::plan::util_copy::find_exprs_in_exprs; use arrow::datatypes::DataType; use datafusion::logical_expr::{ @@ -57,12 +58,11 @@ static MOVING_AVERAGE: Lazy> = Lazy::new(|| { Arc::new(ScalarUDF::new( MOVING_AVERAGE_UDF_NAME, &Signature::one_of( - vec![ - TypeSignature::Exact(vec![DataType::Float64, DataType::Int64]), - TypeSignature::Exact(vec![DataType::Int64, DataType::Int64]), - TypeSignature::Exact(vec![DataType::UInt64, DataType::Int64]), - ], - Volatility::Volatile, + NUMERICS + .iter() + .map(|dt| TypeSignature::Exact(vec![dt.clone(), DataType::Int64])) + .collect(), + Volatility::Immutable, ), &return_type_fn, &stand_in_impl(MOVING_AVERAGE_UDF_NAME), @@ -82,12 +82,11 @@ static DIFFERENCE: Lazy> = Lazy::new(|| { Arc::new(ScalarUDF::new( DIFFERENCE_UDF_NAME, &Signature::one_of( - vec![ - TypeSignature::Exact(vec![DataType::Float64]), - TypeSignature::Exact(vec![DataType::Int64]), - TypeSignature::Exact(vec![DataType::UInt64]), - ], - Volatility::Volatile, + NUMERICS + .iter() + .map(|dt| TypeSignature::Exact(vec![dt.clone()])) + .collect(), + Volatility::Immutable, ), &return_type_fn, &stand_in_impl(DIFFERENCE_UDF_NAME), @@ -107,12 +106,11 @@ static NON_NEGATIVE_DIFFERENCE: Lazy> = Lazy::new(|| { Arc::new(ScalarUDF::new( NON_NEGATIVE_DIFFERENCE_UDF_NAME, &Signature::one_of( - vec![ - TypeSignature::Exact(vec![DataType::Float64]), - TypeSignature::Exact(vec![DataType::Int64]), - TypeSignature::Exact(vec![DataType::UInt64]), - ], - Volatility::Volatile, + NUMERICS + .iter() + .map(|dt| TypeSignature::Exact(vec![dt.clone()])) + .collect(), + Volatility::Immutable, ), &return_type_fn, &stand_in_impl(NON_NEGATIVE_DIFFERENCE_UDF_NAME),