Skip to content

Commit ac96b5d

Browse files
committed
impl equal to.
1 parent ffcc1a2 commit ac96b5d

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

datafusion/physical-plan/src/aggregates/group_values/group_column.rs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,9 @@ impl ByteGroupValueViewBuilder {
445445
let value: &[u8] = arr.value(row).as_ref();
446446

447447
let value_len = value.len();
448-
let view = if value_len > 12 {
448+
let view = if value_len <= 12 {
449+
make_view(value, 0, 0)
450+
} else {
449451
// Ensure big enough block to hold the value firstly
450452
self.ensure_in_progress_big_enough(value_len);
451453

@@ -455,8 +457,6 @@ impl ByteGroupValueViewBuilder {
455457
self.in_progress.extend_from_slice(value);
456458

457459
make_view(value, block_id, offset)
458-
} else {
459-
make_view(value, 0, 0)
460460
};
461461

462462
// Append view
@@ -477,6 +477,48 @@ impl ByteGroupValueViewBuilder {
477477
self.completed.push(buffer);
478478
}
479479
}
480+
481+
fn equal_to_inner<B>(&self, lhs_row: usize, array: &ArrayRef, rhs_row: usize) -> bool
482+
where
483+
B: ByteViewType,
484+
{
485+
let array = array.as_byte_view::<B>();
486+
487+
// Check if nulls equal firstly
488+
let exist_null = self.nulls.is_null(lhs_row);
489+
let input_null = array.is_null(rhs_row);
490+
if let Some(result) = nulls_equal_to(exist_null, input_null) {
491+
return result;
492+
}
493+
494+
// Otherwise, we need to check their values
495+
let exist_view = self.views[lhs_row];
496+
let exist_view_len = exist_view as u32;
497+
498+
let input_view = array.views()[rhs_row];
499+
let input_view_len = exist_view as u32;
500+
501+
// The check logic
502+
// - Check len equality
503+
// - If non-inlined, check prefix and then check value in buffer
504+
// when needed
505+
// - If inlined, check inlined value
506+
if exist_view_len != input_view_len {
507+
return false;
508+
}
509+
510+
if exist_view_len > 12 {
511+
let exist_prefix = unsafe { GenericByteViewArray::<B>::inline_value(&exist_view, 4) };
512+
let input_prefix = unsafe { GenericByteViewArray::<B>::inline_value(&input_view, 4) };
513+
514+
if exist_prefix != input_prefix {
515+
return false;
516+
}
517+
518+
let exist_full: &[u8] = unsafe { array.value_unchecked(lhs_row).as_ref() };
519+
let input_full: &[u8] = unsafe { right.value_unchecked(right_idx).as_ref() };
520+
}
521+
}
480522
}
481523

482524
/// Determines if the nullability of the existing and new input array can be used

0 commit comments

Comments
 (0)