Skip to content

Commit c4d45c7

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

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

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

+49-11
Original file line numberDiff line numberDiff line change
@@ -1044,18 +1044,39 @@ 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
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+
//
1051+
// - exist not null, input not null; value not equal
1052+
// (non-inlined case + prefix not equal)
1053+
//
1054+
// - exist not null, input not null; value not equal
1055+
// (non-inlined case + value in `completed`)
1056+
//
1057+
// - exist not null, input not null; value equal
1058+
// (non-inlined case + value in `completed`)
1059+
//
1060+
// - exist not null, input not null; value not equal
1061+
// (non-inlined case + value in `in_progress`)
1062+
//
1063+
// - exist not null, input not null; value equal
1064+
// (non-inlined case + value in `in_progress`)
10491065

1050-
let mut builder = ByteViewGroupValueBuilder::<StringViewType>::new();
1066+
// Set the block size to 40 for ensuring some unlined values are in `in_progress`,
1067+
// and some are in `completed`, so both two branches in `value` function can be covered.
1068+
let mut builder =
1069+
ByteViewGroupValueBuilder::<StringViewType>::new().with_max_block_size(60);
10511070
let builder_array = Arc::new(StringViewArray::from(vec![
10521071
None,
10531072
None,
10541073
None,
10551074
Some("foo"),
1075+
Some("bazz"),
1076+
Some("foo"),
10561077
Some("bar"),
1057-
Some("this string is quite long"),
1058-
Some("baz"),
1078+
Some("I am a long string for test eq in completed"),
1079+
Some("I am a long string for test eq in progress"),
10591080
])) as ArrayRef;
10601081
builder.append_val(&builder_array, 0);
10611082
builder.append_val(&builder_array, 1);
@@ -1064,28 +1085,40 @@ mod tests {
10641085
builder.append_val(&builder_array, 4);
10651086
builder.append_val(&builder_array, 5);
10661087
builder.append_val(&builder_array, 6);
1088+
builder.append_val(&builder_array, 7);
1089+
builder.append_val(&builder_array, 8);
10671090

10681091
// Define input array
10691092
let (views, buffer, _nulls) = StringViewArray::from(vec![
10701093
Some("foo"),
1071-
Some("bar"), // set to null
1072-
Some("this string is quite long"), // set to null
1094+
Some("bar"), // set to null
10731095
None,
10741096
None,
1075-
Some("foo"),
10761097
Some("baz"),
1098+
Some("oof"),
1099+
Some("bar"),
1100+
Some("i am a long string for test eq in completed"),
1101+
Some("I am a long string for test eq in COMPLETED"),
1102+
Some("I am a long string for test eq in completed"),
1103+
Some("I am a long string for test eq in PROGRESS"),
1104+
Some("I am a long string for test eq in progress"),
10771105
])
10781106
.into_parts();
10791107

10801108
// explicitly build a boolean buffer where one of the null values also happens to match
1081-
let mut boolean_buffer_builder = BooleanBufferBuilder::new(6);
1109+
let mut boolean_buffer_builder = BooleanBufferBuilder::new(9);
10821110
boolean_buffer_builder.append(true);
10831111
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
10851112
boolean_buffer_builder.append(false);
10861113
boolean_buffer_builder.append(false);
10871114
boolean_buffer_builder.append(true);
10881115
boolean_buffer_builder.append(true);
1116+
boolean_buffer_builder.append(true);
1117+
boolean_buffer_builder.append(true);
1118+
boolean_buffer_builder.append(true);
1119+
boolean_buffer_builder.append(true);
1120+
boolean_buffer_builder.append(true);
1121+
boolean_buffer_builder.append(true);
10891122
let nulls = NullBuffer::new(boolean_buffer_builder.finish());
10901123
let input_array =
10911124
Arc::new(StringViewArray::new(views, buffer, Some(nulls))) as ArrayRef;
@@ -1098,6 +1131,11 @@ mod tests {
10981131
assert!(!builder.equal_to(4, &input_array, 4));
10991132
assert!(!builder.equal_to(5, &input_array, 5));
11001133
assert!(builder.equal_to(6, &input_array, 6));
1134+
assert!(!builder.equal_to(7, &input_array, 7));
1135+
assert!(!builder.equal_to(7, &input_array, 8));
1136+
assert!(builder.equal_to(7, &input_array, 9));
1137+
assert!(!builder.equal_to(8, &input_array, 10));
1138+
assert!(builder.equal_to(8, &input_array, 11));
11011139
}
11021140

11031141
#[test]
@@ -1149,7 +1187,7 @@ mod tests {
11491187

11501188
let input_array: ArrayRef = Arc::new(input_array);
11511189
let first_ones_to_append = 16; // For testing situation 1~5
1152-
let second_ones_to_append = 3; // For testing situation 6
1190+
let second_ones_to_append = 4; // For testing situation 6
11531191
let final_ones_to_append = input_array.len(); // For testing situation 7
11541192

11551193
// ####### Test situation 1~5 #######

0 commit comments

Comments
 (0)