Skip to content

Commit 10e00f2

Browse files
committed
revamped into a 3 step approach , (build up,phase 1 ,phase 2)
revised-version-1 updated normalization fn to use a hashmap cache instead of doing a n^2 loop remove extra vector allocations for hash insertions removed un-needed ut8 check removed normalization filter values before operating on them optimizations round 2 filter input arrays to values that are refrenced in current batch + other optimizations. PR currently is a speed up in most cases but I want to transition to a full buffer +offset & len as opposed to storing a vector of vectors cache values ptr reduced file size
1 parent 4115a93 commit 10e00f2

3 files changed

Lines changed: 840 additions & 2 deletions

File tree

‎datafusion/physical-plan/src/aggregates/group_values/mod.rs‎

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ use arrow::array::types::{
2323
TimestampMillisecondType, TimestampNanosecondType, TimestampSecondType,
2424
};
2525
use arrow::array::{ArrayRef, downcast_primitive};
26-
use arrow::datatypes::{DataType, SchemaRef, TimeUnit};
26+
27+
use arrow::datatypes::{
28+
DataType, Int8Type, Int16Type, Int32Type, Int64Type, SchemaRef, TimeUnit, UInt8Type,
29+
UInt16Type, UInt32Type, UInt64Type,
30+
};
2731
use datafusion_common::Result;
2832

2933
use datafusion_expr::EmitTo;
@@ -36,7 +40,9 @@ use datafusion_physical_expr::binary_map::OutputType;
3640
use multi_group_by::GroupValuesColumn;
3741
use row::GroupValuesRows;
3842

39-
pub(crate) use single_group_by::primitive::HashValue;
43+
pub(crate) use single_group_by::{
44+
dictionary::GroupValuesDictionary, primitive::HashValue,
45+
};
4046

4147
use crate::aggregates::{
4248
group_values::single_group_by::{
@@ -196,6 +202,39 @@ pub fn new_group_values(
196202
DataType::Boolean => {
197203
return Ok(Box::new(GroupValuesBoolean::new()));
198204
}
205+
DataType::Dictionary(key_type, value_type)
206+
if supported_single_dictionary_value(value_type) =>
207+
{
208+
return match key_type.as_ref() {
209+
DataType::Int8 => {
210+
Ok(Box::new(GroupValuesDictionary::<Int8Type>::new(value_type)))
211+
}
212+
DataType::Int16 => Ok(Box::new(
213+
GroupValuesDictionary::<Int16Type>::new(value_type),
214+
)),
215+
DataType::Int32 => Ok(Box::new(
216+
GroupValuesDictionary::<Int32Type>::new(value_type),
217+
)),
218+
DataType::Int64 => Ok(Box::new(
219+
GroupValuesDictionary::<Int64Type>::new(value_type),
220+
)),
221+
DataType::UInt8 => Ok(Box::new(
222+
GroupValuesDictionary::<UInt8Type>::new(value_type),
223+
)),
224+
DataType::UInt16 => Ok(Box::new(
225+
GroupValuesDictionary::<UInt16Type>::new(value_type),
226+
)),
227+
DataType::UInt32 => Ok(Box::new(
228+
GroupValuesDictionary::<UInt32Type>::new(value_type),
229+
)),
230+
DataType::UInt64 => Ok(Box::new(
231+
GroupValuesDictionary::<UInt64Type>::new(value_type),
232+
)),
233+
_ => Err(datafusion_common::DataFusionError::NotImplemented(
234+
format!("Unsupported dictionary key type: {key_type:?}"),
235+
)),
236+
};
237+
}
199238
_ => {}
200239
}
201240
}
@@ -210,3 +249,18 @@ pub fn new_group_values(
210249
Ok(Box::new(GroupValuesRows::try_new(schema)?))
211250
}
212251
}
252+
253+
fn supported_single_dictionary_value(t: &DataType) -> bool {
254+
match t {
255+
DataType::Utf8 | DataType::LargeUtf8 | DataType::Utf8View => true,
256+
DataType::List(field)
257+
if matches!(
258+
field.data_type(),
259+
DataType::Utf8 | DataType::Utf8View | DataType::LargeUtf8
260+
) =>
261+
{
262+
true
263+
}
264+
_ => false,
265+
}
266+
}

0 commit comments

Comments
 (0)