Skip to content

Commit 08802ff

Browse files
committed
Dictionary encoding: Optimize hash aggregation with i64 len prefixes
1 parent 610e02f commit 08802ff

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

  • datafusion/physical-plan/src/aggregates/group_values/single_group_by

datafusion/physical-plan/src/aggregates/group_values/single_group_by/dictionary.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,20 @@ macro_rules! decode_list {
4040
Some(raw_vector) => {
4141
let mut offset = 0;
4242
while offset < raw_vector.len() {
43-
let len = i32::from_ne_bytes(
44-
raw_vector[offset..offset + 4]
43+
let len = i64::from_ne_bytes(
44+
raw_vector[offset..offset + 8]
4545
.try_into()
46-
.expect("slice of length 4"),
46+
.expect("slice of length 8"),
4747
);
48-
offset += 4;
48+
offset += 8;
4949
if len == -1 {
5050
builder.values().append_null();
5151
} else {
5252
let s = std::str::from_utf8(
5353
&raw_vector[offset..offset + len as usize],
5454
)
5555
.map_err(|e| {
56-
datafusion_common::DataFusionError::Internal(format!(
57-
"Invalid utf8 in list element: {e}"
58-
))
56+
Internal(format!("Invalid utf8 in list element: {e}"))
5957
})?;
6058
builder.values().append_value(s);
6159
offset += len as usize;
@@ -75,9 +73,7 @@ macro_rules! decode_scalar_string {
7573
match raw_bytes {
7674
Some(raw_vector) => {
7775
let s = std::str::from_utf8(raw_vector).map_err(|e| {
78-
datafusion_common::DataFusionError::Internal(format!(
79-
"Invalid utf8 in GroupValuesDictionary: {e}"
80-
))
76+
Internal(format!("Invalid utf8 in GroupValuesDictionary: {e}"))
8177
})?;
8278
builder.append_value(s);
8379
}
@@ -163,10 +159,10 @@ impl<K: ArrowDictionaryKeyType + Send> GroupValuesDictionary<K> {
163159
for i in start..end {
164160
if child.is_null(i) {
165161
// acts as a marker for transform_into_array to write a null
166-
bytes.extend_from_slice(&(-1i32).to_ne_bytes());
162+
bytes.extend_from_slice(&(-1i64).to_ne_bytes());
167163
} else {
168164
let raw = Self::get_raw_bytes(child, i);
169-
bytes.extend_from_slice(&(raw.len() as i32).to_ne_bytes());
165+
bytes.extend_from_slice(&(raw.len() as i64).to_ne_bytes());
170166
bytes.extend_from_slice(&raw);
171167
}
172168
}

0 commit comments

Comments
 (0)