Skip to content

Commit 51c1b4b

Browse files
authored
Add tests for Arrow Flight support for StringViewArray and BinaryViewArray (#5601)
* Add tests to send view types with flight * make clippy happy
1 parent 9fda7ea commit 51c1b4b

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

arrow-flight/tests/encode_decode.rs

+57-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
use std::{collections::HashMap, sync::Arc};
2121

2222
use arrow_array::types::Int32Type;
23-
use arrow_array::{ArrayRef, DictionaryArray, Float64Array, RecordBatch, UInt8Array};
23+
use arrow_array::{
24+
ArrayRef, BinaryViewArray, DictionaryArray, Float64Array, RecordBatch, StringViewArray,
25+
UInt8Array,
26+
};
2427
use arrow_cast::pretty::pretty_format_batches;
2528
use arrow_flight::flight_descriptor::DescriptorType;
2629
use arrow_flight::FlightDescriptor;
@@ -111,6 +114,22 @@ async fn test_dictionary_many() {
111114
.await;
112115
}
113116

117+
#[tokio::test]
118+
async fn test_view_types_one() {
119+
roundtrip(vec![make_view_batches(5)]).await;
120+
}
121+
122+
#[tokio::test]
123+
async fn test_view_types_many() {
124+
roundtrip(vec![
125+
make_view_batches(5),
126+
make_view_batches(9),
127+
make_view_batches(5),
128+
make_view_batches(5),
129+
])
130+
.await;
131+
}
132+
114133
#[tokio::test]
115134
async fn test_zero_batches_no_schema() {
116135
let stream = FlightDataEncoderBuilder::default().build(futures::stream::iter(vec![]));
@@ -450,16 +469,51 @@ fn make_dictionary_batch(num_rows: usize) -> RecordBatch {
450469
RecordBatch::try_from_iter(vec![("a", Arc::new(a) as ArrayRef)]).unwrap()
451470
}
452471

472+
fn make_view_batches(num_rows: usize) -> RecordBatch {
473+
const LONG_TEST_STRING: &str =
474+
"This is a long string to make sure binary view array handles it";
475+
let schema = Schema::new(vec![
476+
Field::new("field1", DataType::BinaryView, true),
477+
Field::new("field2", DataType::Utf8View, true),
478+
]);
479+
480+
let string_view_values: Vec<Option<&str>> = (0..num_rows)
481+
.map(|i| match i % 3 {
482+
0 => None,
483+
1 => Some("foo"),
484+
2 => Some(LONG_TEST_STRING),
485+
_ => unreachable!(),
486+
})
487+
.collect();
488+
489+
let bin_view_values: Vec<Option<&[u8]>> = (0..num_rows)
490+
.map(|i| match i % 3 {
491+
0 => None,
492+
1 => Some("bar".as_bytes()),
493+
2 => Some(LONG_TEST_STRING.as_bytes()),
494+
_ => unreachable!(),
495+
})
496+
.collect();
497+
498+
let binary_array = BinaryViewArray::from_iter(bin_view_values);
499+
let utf8_array = StringViewArray::from_iter(string_view_values);
500+
RecordBatch::try_new(
501+
Arc::new(schema.clone()),
502+
vec![Arc::new(binary_array), Arc::new(utf8_array)],
503+
)
504+
.unwrap()
505+
}
506+
453507
/// Encodes input as a FlightData stream, and then decodes it using
454-
/// FlightRecordBatchStream and valides the decoded record batches
508+
/// FlightRecordBatchStream and validates the decoded record batches
455509
/// match the input.
456510
async fn roundtrip(input: Vec<RecordBatch>) {
457511
let expected_output = input.clone();
458512
roundtrip_with_encoder(FlightDataEncoderBuilder::default(), input, expected_output).await
459513
}
460514

461515
/// Encodes input as a FlightData stream, and then decodes it using
462-
/// FlightRecordBatchStream and valides the decoded record batches
516+
/// FlightRecordBatchStream and validates the decoded record batches
463517
/// match the expected input.
464518
///
465519
/// When <https://github.com/apache/arrow-rs/issues/3389> is resolved,

0 commit comments

Comments
 (0)