From 43f87a65e6113d1bc4b714d9ce33744cf31b7c59 Mon Sep 17 00:00:00 2001 From: jayzhan211 Date: Wed, 2 Oct 2024 10:43:26 +0800 Subject: [PATCH 1/2] rm clone Signed-off-by: jayzhan211 --- datafusion/physical-plan/src/aggregates/row_hash.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/datafusion/physical-plan/src/aggregates/row_hash.rs b/datafusion/physical-plan/src/aggregates/row_hash.rs index a043905765ec..204a309fe209 100644 --- a/datafusion/physical-plan/src/aggregates/row_hash.rs +++ b/datafusion/physical-plan/src/aggregates/row_hash.rs @@ -38,7 +38,7 @@ use crate::{RecordBatchStream, SendableRecordBatchStream}; use arrow::array::*; use arrow::datatypes::SchemaRef; use arrow_schema::SortOptions; -use datafusion_common::{internal_datafusion_err, DataFusionError, Result}; +use datafusion_common::{internal_err, DataFusionError, Result}; use datafusion_execution::disk_manager::RefCountedTempFile; use datafusion_execution::memory_pool::proxy::VecAllocExt; use datafusion_execution::memory_pool::{MemoryConsumer, MemoryReservation}; @@ -1081,13 +1081,14 @@ impl GroupedHashAggregateStream { /// Transforms input batch to intermediate aggregate state, without grouping it fn transform_to_states(&self, batch: RecordBatch) -> Result { - let group_values = evaluate_group_by(&self.group_by, &batch)?; + let mut group_values = evaluate_group_by(&self.group_by, &batch)?; let input_values = evaluate_many(&self.aggregate_arguments, &batch)?; let filter_values = evaluate_optional(&self.filter_expressions, &batch)?; - let mut output = group_values.first().cloned().ok_or_else(|| { - internal_datafusion_err!("group_values expected to have at least one element") - })?; + if group_values.len() != 1 { + return internal_err!("group_values expected to have single element") + } + let mut output = group_values.swap_remove(0); let iter = self .accumulators From 38414bffa45d98008822335c28544df3a5e2c4e8 Mon Sep 17 00:00:00 2001 From: jayzhan211 Date: Wed, 2 Oct 2024 13:47:26 +0800 Subject: [PATCH 2/2] fmt Signed-off-by: jayzhan211 --- datafusion/physical-plan/src/aggregates/row_hash.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion/physical-plan/src/aggregates/row_hash.rs b/datafusion/physical-plan/src/aggregates/row_hash.rs index 204a309fe209..998f6184f321 100644 --- a/datafusion/physical-plan/src/aggregates/row_hash.rs +++ b/datafusion/physical-plan/src/aggregates/row_hash.rs @@ -1086,7 +1086,7 @@ impl GroupedHashAggregateStream { let filter_values = evaluate_optional(&self.filter_expressions, &batch)?; if group_values.len() != 1 { - return internal_err!("group_values expected to have single element") + return internal_err!("group_values expected to have single element"); } let mut output = group_values.swap_remove(0);