Rich-T-kid commented on code in PR #11174:
URL: https://github.com/apache/arrow-rs/pull/11174#discussion_r4321680067
##########
arrow-select/src/coalesce.rs:
##########
@@ -2893,4 +3048,147 @@ mod tests {
"draining must release the accounted memory"
);
}
+
+ #[test]
+ fn test_push_batch_with_indices_splits_at_target_batch_size() {
+ let schema = Arc::new(Schema::new(vec![Field::new("c0",
DataType::Int32, false)]));
+ let array = Int32Array::from_iter_values(0..1000i32);
+ let batch = RecordBatch::try_new(Arc::clone(&schema),
vec![Arc::new(array)]).unwrap();
+ let indices = UInt32Array::from_iter_values((0..1000u32).step_by(3));
+ let target_batch_size = 100;
+
+ let mut coalescer = BatchCoalescer::new(Arc::clone(&schema),
target_batch_size);
+ coalescer
+ .push_batch_with_indices(batch.clone(), &indices)
+ .unwrap();
+ coalescer.finish_buffered_batch().unwrap();
+ let mut completed = vec![];
+ while let Some(batch) = coalescer.next_completed_batch() {
+ completed.push(batch);
+ }
+ for batch in &completed[..completed.len() - 1] {
+ assert_eq!(batch.num_rows(), target_batch_size);
+ }
+
+ let actual = concat_batches(&schema, completed.iter()).unwrap();
+ let expected = take_record_batch(&batch, &indices).unwrap();
+ assert_eq!(expected, actual);
+ }
+
+ #[test]
+ fn test_push_batch_with_indices_empty_is_noop() {
+ let schema = Arc::new(Schema::new(vec![Field::new("c0",
DataType::Int32, false)]));
+ let array = Int32Array::from_iter_values(0..4i32);
+ let batch = RecordBatch::try_new(Arc::clone(&schema),
vec![Arc::new(array)]).unwrap();
+ let indices = UInt32Array::from(Vec::<u32>::new());
+
+ let mut coalescer = BatchCoalescer::new(schema, 4096);
+ coalescer.push_batch_with_indices(batch, &indices).unwrap();
+ coalescer.finish_buffered_batch().unwrap();
+ assert!(coalescer.next_completed_batch().is_none());
+ }
+
+ #[test]
+ fn test_push_batch_with_indices_rejects_schema_mismatch() {
+ let schema = Arc::new(Schema::new(vec![
+ Field::new("c0", DataType::Int32, false),
+ Field::new("c1", DataType::Int32, false),
+ ]));
+ let mut coalescer = BatchCoalescer::new(schema, 100);
+ let batch = RecordBatch::try_new(
+ Arc::new(Schema::new(vec![Field::new("c0", DataType::Int32,
false)])),
+ vec![Arc::new(Int32Array::from_iter_values(0..5i32))],
+ )
+ .unwrap();
+ let indices = UInt32Array::from(vec![0u32, 1]);
+ let err = coalescer
+ .push_batch_with_indices(batch, &indices)
+ .unwrap_err()
+ .to_string();
+ assert!(
+ err.contains("Batch has 1 columns but BatchCoalescer expects 2"),
+ "unexpected error: {err}"
+ );
+ }
+
+ #[test]
+ fn test_push_batch_with_indices_rejects_oob_before_mutation() {
+ let schema = Arc::new(Schema::new(vec![
+ Field::new("c0", DataType::Int32, false),
+ Field::new("c1", DataType::Utf8View, false),
+ ]));
+ let batch = RecordBatch::try_new(
+ Arc::clone(&schema),
+ vec![
+ Arc::new(Int32Array::from_iter_values(0..16i32)),
+ Arc::new(StringViewArray::from(vec!["a"; 16])),
+ ],
+ )
+ .unwrap();
+ let indices = UInt32Array::from(vec![0u32, 1, 2, 3, 0, 1, 2, 99]);
Review Comment:
added in latest commit
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]