-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix offsets for Binary/Lists/LargeLists #727
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -577,8 +577,8 @@ mod tests { | |
builder::{Int32Builder, ListBuilder, StringBuilder}, | ||
cast::{as_primitive_array, as_string_array, as_struct_array}, | ||
types::UInt8Type, | ||
Array, DictionaryArray, Float32Array, Int64Array, NullArray, RecordBatchReader, | ||
StringArray, StructArray, UInt32Array, UInt8Array, | ||
Array, DictionaryArray, Float32Array, Int64Array, LargeListArray, ListArray, NullArray, | ||
RecordBatchReader, StringArray, StructArray, UInt32Array, UInt8Array, | ||
}; | ||
use arrow_schema::{Field as ArrowField, Schema as ArrowSchema}; | ||
use futures::StreamExt; | ||
|
@@ -1131,4 +1131,55 @@ mod tests { | |
&expected_large_list | ||
); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_list_array_with_offsets() { | ||
let arrow_schema = ArrowSchema::new(vec![ | ||
ArrowField::new( | ||
"l", | ||
DataType::List(Box::new(ArrowField::new("item", DataType::Int32, true))), | ||
false, | ||
), | ||
ArrowField::new( | ||
"ll", | ||
DataType::LargeList(Box::new(ArrowField::new("item", DataType::Int32, true))), | ||
false, | ||
), | ||
]); | ||
|
||
let store = ObjectStore::memory(); | ||
let path = Path::from("/lists"); | ||
|
||
let list_array = ListArray::from_iter_primitive::<Int32Type, _, _>(vec![ | ||
Some(vec![Some(1), Some(2)]), | ||
Some(vec![Some(3), Some(4)]), | ||
Some((0..1_000_000).map(|n| Some(n)).collect::<Vec<_>>()), | ||
]) | ||
.slice(1, 1); | ||
let large_list_array = LargeListArray::from_iter_primitive::<Int32Type, _, _>(vec![ | ||
Some(vec![Some(10), Some(11)]), | ||
Some(vec![Some(12), Some(13)]), | ||
Some((0..1_000_000).map(|n| Some(n)).collect::<Vec<_>>()), | ||
]) | ||
.slice(1, 1); | ||
|
||
let batch = RecordBatch::try_new( | ||
Arc::new(arrow_schema.clone()), | ||
vec![Arc::new(list_array), Arc::new(large_list_array)], | ||
) | ||
.unwrap(); | ||
|
||
let schema: Schema = (&arrow_schema).try_into().unwrap(); | ||
let mut file_writer = FileWriter::try_new(&store, &path, &schema).await.unwrap(); | ||
file_writer.write(&[&batch.clone()]).await.unwrap(); | ||
file_writer.finish().await.unwrap(); | ||
|
||
// Make sure the big array was not written to the file | ||
let file_size_bytes = store.size(&path).await.unwrap(); | ||
assert!(file_size_bytes < 1_000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems we just need to make 2000 values instead of 1M? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just writing an array that is so big that it will be obvious if the assert doesn't match (I think the actual file size is ~ 250 bytes) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, i mean 2000 elements is good enough for test. and it is faster in CI |
||
|
||
let reader = FileReader::try_new(&store, &path).await.unwrap(); | ||
let actual_batch = reader.read_batch(0, .., reader.schema()).await.unwrap(); | ||
assert_eq!(batch, actual_batch); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a test to actually write multiple arrays, wanna just make sure the cummulation of offsets is correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not directly, but
test_read_struct_of_list_arrays
creates multiple structs that contains lists andwrite_struct_array
should group them together.