Skip to content

Commit 68b0eba

Browse files
committed
improve unit test coverage for ByteViewGroupValueBuilder.
1 parent 023ed64 commit 68b0eba

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

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

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,18 +1044,32 @@ mod tests {
10441044
// - exist null, input null; values not equal
10451045
// - exist null, input null; values equal
10461046
// - exist not null, input null
1047-
// - exist not null, input not null; values not equal
1048-
// - exist not null, input not null; values equal
1049-
1050-
let mut builder = ByteViewGroupValueBuilder::<StringViewType>::new();
1047+
// - exist not null, input not null; value lens not equal
1048+
// - exist not null, input not null; value not equal(inlined case)
1049+
// - exist not null, input not null; value equal(inlined case)
1050+
// - exist not null, input not null; value not equal
1051+
// (non-inlined case + value in `completed`)
1052+
// - exist not null, input not null; value equal
1053+
// (non-inlined case + value in `completed`)
1054+
// - exist not null, input not null; value not equal
1055+
// (non-inlined case + value in `in_progress`)
1056+
// - exist not null, input not null; value equal
1057+
// (non-inlined case + value in `in_progress`)
1058+
1059+
// Set the block size to 40 for ensuring some unlined values are in `in_progress`,
1060+
// and some are in `completed`, so both two branches in `value` function can be covered.
1061+
let mut builder =
1062+
ByteViewGroupValueBuilder::<StringViewType>::new().with_max_block_size(60);
10511063
let builder_array = Arc::new(StringViewArray::from(vec![
10521064
None,
10531065
None,
10541066
None,
10551067
Some("foo"),
1068+
Some("bazz"),
1069+
Some("foo"),
10561070
Some("bar"),
1057-
Some("this string is quite long"),
1058-
Some("baz"),
1071+
Some("I am a long string for test eq in completed"),
1072+
Some("I am a long string for test eq in progress"),
10591073
])) as ArrayRef;
10601074
builder.append_val(&builder_array, 0);
10611075
builder.append_val(&builder_array, 1);
@@ -1064,28 +1078,38 @@ mod tests {
10641078
builder.append_val(&builder_array, 4);
10651079
builder.append_val(&builder_array, 5);
10661080
builder.append_val(&builder_array, 6);
1081+
builder.append_val(&builder_array, 7);
1082+
builder.append_val(&builder_array, 8);
10671083

10681084
// Define input array
10691085
let (views, buffer, _nulls) = StringViewArray::from(vec![
10701086
Some("foo"),
1071-
Some("bar"), // set to null
1072-
Some("this string is quite long"), // set to null
1087+
Some("bar"), // set to null
10731088
None,
10741089
None,
1075-
Some("foo"),
10761090
Some("baz"),
1091+
Some("oof"),
1092+
Some("bar"),
1093+
Some("I am a long string for test not eq in completed"),
1094+
Some("I am a long string for test eq in completed"),
1095+
Some("I am a long string for test not eq in progress"),
1096+
Some("I am a long string for test eq in progress"),
10771097
])
10781098
.into_parts();
10791099

10801100
// explicitly build a boolean buffer where one of the null values also happens to match
1081-
let mut boolean_buffer_builder = BooleanBufferBuilder::new(6);
1101+
let mut boolean_buffer_builder = BooleanBufferBuilder::new(9);
10821102
boolean_buffer_builder.append(true);
10831103
boolean_buffer_builder.append(false); // this sets Some("bar") to null above
1084-
boolean_buffer_builder.append(false); // this sets Some("thisstringisquitelong") to null above
10851104
boolean_buffer_builder.append(false);
10861105
boolean_buffer_builder.append(false);
10871106
boolean_buffer_builder.append(true);
10881107
boolean_buffer_builder.append(true);
1108+
boolean_buffer_builder.append(true);
1109+
boolean_buffer_builder.append(true);
1110+
boolean_buffer_builder.append(true);
1111+
boolean_buffer_builder.append(true);
1112+
boolean_buffer_builder.append(true);
10891113
let nulls = NullBuffer::new(boolean_buffer_builder.finish());
10901114
let input_array =
10911115
Arc::new(StringViewArray::new(views, buffer, Some(nulls))) as ArrayRef;
@@ -1098,6 +1122,10 @@ mod tests {
10981122
assert!(!builder.equal_to(4, &input_array, 4));
10991123
assert!(!builder.equal_to(5, &input_array, 5));
11001124
assert!(builder.equal_to(6, &input_array, 6));
1125+
assert!(!builder.equal_to(7, &input_array, 7));
1126+
assert!(builder.equal_to(7, &input_array, 8));
1127+
assert!(!builder.equal_to(8, &input_array, 9));
1128+
assert!(builder.equal_to(8, &input_array, 10));
11011129
}
11021130

11031131
#[test]
@@ -1149,7 +1177,7 @@ mod tests {
11491177

11501178
let input_array: ArrayRef = Arc::new(input_array);
11511179
let first_ones_to_append = 16; // For testing situation 1~5
1152-
let second_ones_to_append = 3; // For testing situation 6
1180+
let second_ones_to_append = 4; // For testing situation 6
11531181
let final_ones_to_append = input_array.len(); // For testing situation 7
11541182

11551183
// ####### Test situation 1~5 #######

0 commit comments

Comments
 (0)