|
20 | 20 | use std::{collections::HashMap, sync::Arc};
|
21 | 21 |
|
22 | 22 | 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 | +}; |
24 | 27 | use arrow_cast::pretty::pretty_format_batches;
|
25 | 28 | use arrow_flight::flight_descriptor::DescriptorType;
|
26 | 29 | use arrow_flight::FlightDescriptor;
|
@@ -111,6 +114,22 @@ async fn test_dictionary_many() {
|
111 | 114 | .await;
|
112 | 115 | }
|
113 | 116 |
|
| 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 | + |
114 | 133 | #[tokio::test]
|
115 | 134 | async fn test_zero_batches_no_schema() {
|
116 | 135 | let stream = FlightDataEncoderBuilder::default().build(futures::stream::iter(vec![]));
|
@@ -450,16 +469,51 @@ fn make_dictionary_batch(num_rows: usize) -> RecordBatch {
|
450 | 469 | RecordBatch::try_from_iter(vec![("a", Arc::new(a) as ArrayRef)]).unwrap()
|
451 | 470 | }
|
452 | 471 |
|
| 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 | + |
453 | 507 | /// 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 |
455 | 509 | /// match the input.
|
456 | 510 | async fn roundtrip(input: Vec<RecordBatch>) {
|
457 | 511 | let expected_output = input.clone();
|
458 | 512 | roundtrip_with_encoder(FlightDataEncoderBuilder::default(), input, expected_output).await
|
459 | 513 | }
|
460 | 514 |
|
461 | 515 | /// 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 |
463 | 517 | /// match the expected input.
|
464 | 518 | ///
|
465 | 519 | /// When <https://github.com/apache/arrow-rs/issues/3389> is resolved,
|
|
0 commit comments