Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
Signed-off-by: jayzhan211 <[email protected]>
  • Loading branch information
jayzhan211 committed Oct 16, 2023
1 parent 9121b35 commit bc46e29
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 40 deletions.
26 changes: 0 additions & 26 deletions datafusion/expr/src/built_in_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ pub enum BuiltinScalarFunction {
ArrayReplaceAll,
/// array_slice
ArraySlice,
/// array_sum
ArraySum,
/// array_to_string
ArrayToString,
/// cardinality
Expand Down Expand Up @@ -399,7 +397,6 @@ impl BuiltinScalarFunction {
BuiltinScalarFunction::ArrayReplaceAll => Volatility::Immutable,
BuiltinScalarFunction::Flatten => Volatility::Immutable,
BuiltinScalarFunction::ArraySlice => Volatility::Immutable,
BuiltinScalarFunction::ArraySum => Volatility::Immutable,
BuiltinScalarFunction::ArrayToString => Volatility::Immutable,
BuiltinScalarFunction::Cardinality => Volatility::Immutable,
BuiltinScalarFunction::MakeArray => Volatility::Immutable,
Expand Down Expand Up @@ -593,27 +590,6 @@ impl BuiltinScalarFunction {
BuiltinScalarFunction::ArrayReplaceN => Ok(input_expr_types[0].clone()),
BuiltinScalarFunction::ArrayReplaceAll => Ok(input_expr_types[0].clone()),
BuiltinScalarFunction::ArraySlice => Ok(input_expr_types[0].clone()),
BuiltinScalarFunction::ArraySum => match &input_expr_types[0] {
DataType::List(field) => {
let data_type = field.data_type();
match data_type {
DataType::Int8 => Ok(Int8),
DataType::Int16 => Ok(Int16),
DataType::Int32 => Ok(Int32),
DataType::Int64 => Ok(Int64),
DataType::UInt8 => Ok(UInt8),
DataType::UInt16 => Ok(UInt16),
DataType::UInt32 => Ok(UInt32),
DataType::UInt64 => Ok(UInt64),
DataType::Float32 => Ok(Float32),
DataType::Float64 => Ok(Float64),
data_type => {
not_impl_err!("ArraySum does not support {data_type:?}")
}
}
}
_ => internal_err!("Onlt List is supported for ArraySum"),
},
BuiltinScalarFunction::ArrayToString => Ok(Utf8),
BuiltinScalarFunction::Cardinality => Ok(UInt64),
BuiltinScalarFunction::MakeArray => match input_expr_types.len() {
Expand Down Expand Up @@ -912,7 +888,6 @@ impl BuiltinScalarFunction {
Signature::any(3, self.volatility())
}
BuiltinScalarFunction::ArraySlice => Signature::any(3, self.volatility()),
BuiltinScalarFunction::ArraySum => Signature::any(1, self.volatility()),
BuiltinScalarFunction::ArrayToString => {
Signature::variadic_any(self.volatility())
}
Expand Down Expand Up @@ -1525,7 +1500,6 @@ fn aliases(func: &BuiltinScalarFunction) -> &'static [&'static str] {
&["array_replace_all", "list_replace_all"]
}
BuiltinScalarFunction::ArraySlice => &["array_slice", "list_slice"],
BuiltinScalarFunction::ArraySum => &["array_sum", "list_sum"],
BuiltinScalarFunction::ArrayToString => &[
"array_to_string",
"list_to_string",
Expand Down
6 changes: 0 additions & 6 deletions datafusion/expr/src/expr_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,6 @@ scalar_expr!(
array offset length,
"returns a slice of the array."
);
scalar_expr!(
ArraySum,
array_sum,
array,
"returns the sum of the array elements."
);
scalar_expr!(
ArrayToString,
array_to_string,
Expand Down
12 changes: 6 additions & 6 deletions datafusion/physical-expr/src/aggregate/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ impl<T: ArrowNumericType> Accumulator for SumAccumulator<T> {
// There are two kinds of input, PrimitiveArray and ListArray
// ListArray is for multiple-rows input, and PrimitiveArray is for single-row input
fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
// Wrap single-row input into ListArray
let list_values = if as_list_array(&values[0]).is_err() {
wrap_into_list_array(values[0].clone())
} else {
as_list_array(&values[0])?.to_owned()
// Wrap single-row input into multiple-rows input and use the same logic as multiple-rows input
let list_values = match as_list_array(&values[0]) {
Ok(arr) => arr.to_owned(),
Err(_) => wrap_into_list_array(values[0].clone()),
};

let row_number = list_values.len();
if self.sum.len() == 0 {

if self.sum.is_empty() {
self.sum.resize(row_number, None);
} else if self.sum.len() < row_number {
return internal_err!("SumAccumulator::update_batch only support consistent row number, got {} and {}", self.sum.len(), row_number);
Expand Down
1 change: 0 additions & 1 deletion datafusion/proto/src/logical_plan/from_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ impl From<&protobuf::ScalarFunction> for BuiltinScalarFunction {
ScalarFunction::ArrayReplaceN => Self::ArrayReplaceN,
ScalarFunction::ArrayReplaceAll => Self::ArrayReplaceAll,
ScalarFunction::ArraySlice => Self::ArraySlice,
ScalarFunction::ArraySum => Self::ArraySum,
ScalarFunction::ArrayToString => Self::ArrayToString,
ScalarFunction::Cardinality => Self::Cardinality,
ScalarFunction::Array => Self::MakeArray,
Expand Down
1 change: 0 additions & 1 deletion datafusion/proto/src/logical_plan/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,6 @@ impl TryFrom<&BuiltinScalarFunction> for protobuf::ScalarFunction {
BuiltinScalarFunction::ArrayReplaceN => Self::ArrayReplaceN,
BuiltinScalarFunction::ArrayReplaceAll => Self::ArrayReplaceAll,
BuiltinScalarFunction::ArraySlice => Self::ArraySlice,
BuiltinScalarFunction::ArraySum => Self::ArraySum,
BuiltinScalarFunction::ArrayToString => Self::ArrayToString,
BuiltinScalarFunction::Cardinality => Self::Cardinality,
BuiltinScalarFunction::MakeArray => Self::Array,
Expand Down

0 comments on commit bc46e29

Please sign in to comment.