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
add test for skip_values in DictionaryDecoder and fix it #2105
Changes from all 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 |
---|---|---|
|
@@ -346,6 +346,7 @@ where | |
// Keys will be validated on conversion to arrow | ||
let keys_slice = keys.spare_capacity_mut(range.start + len); | ||
let len = decoder.get_batch(&mut keys_slice[range.start..])?; | ||
*max_remaining_values -= len; | ||
Ok(len) | ||
} | ||
None => { | ||
|
@@ -368,7 +369,7 @@ where | |
dict_offsets, | ||
dict_values, | ||
)?; | ||
|
||
*max_remaining_values -= len; | ||
Ok(len) | ||
} | ||
} | ||
|
@@ -476,6 +477,68 @@ mod tests { | |
) | ||
} | ||
|
||
#[test] | ||
fn test_dictionary_preservation_skip() { | ||
let data_type = utf8_dictionary(); | ||
|
||
let data: Vec<_> = vec!["0", "1", "0", "1", "2", "1", "2"] | ||
.into_iter() | ||
.map(ByteArray::from) | ||
.collect(); | ||
let (dict, encoded) = encode_dictionary(&data); | ||
|
||
let column_desc = utf8_column(); | ||
let mut decoder = DictionaryDecoder::<i32, i32>::new(&column_desc); | ||
|
||
decoder | ||
.set_dict(dict, 3, Encoding::RLE_DICTIONARY, false) | ||
.unwrap(); | ||
|
||
decoder | ||
.set_data(Encoding::RLE_DICTIONARY, encoded, 7, Some(data.len())) | ||
.unwrap(); | ||
|
||
let mut output = DictionaryBuffer::<i32, i32>::default(); | ||
|
||
// read two skip one | ||
assert_eq!(decoder.read(&mut output, 0..2).unwrap(), 2); | ||
assert_eq!(decoder.skip_values(1).unwrap(), 1); | ||
|
||
assert!(matches!(output, DictionaryBuffer::Dict { .. })); | ||
|
||
// read two skip one | ||
assert_eq!(decoder.read(&mut output, 2..4).unwrap(), 2); | ||
assert_eq!(decoder.skip_values(1).unwrap(), 1); | ||
|
||
// read one and test on skip at the end | ||
assert_eq!(decoder.read(&mut output, 4..5).unwrap(), 1); | ||
assert_eq!(decoder.skip_values(4).unwrap(), 0); | ||
|
||
let valid = vec![true, true, true, true, true]; | ||
let valid_buffer = Buffer::from_iter(valid.iter().cloned()); | ||
output.pad_nulls(0, 5, 5, valid_buffer.as_slice()); | ||
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. @tustvold i found without 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. Yes, call |
||
|
||
assert!(matches!(output, DictionaryBuffer::Dict { .. })); | ||
|
||
let array = output.into_array(Some(valid_buffer), &data_type).unwrap(); | ||
assert_eq!(array.data_type(), &data_type); | ||
|
||
let array = cast(&array, &ArrowType::Utf8).unwrap(); | ||
let strings = array.as_any().downcast_ref::<StringArray>().unwrap(); | ||
assert_eq!(strings.len(), 5); | ||
|
||
assert_eq!( | ||
strings.iter().collect::<Vec<_>>(), | ||
vec![ | ||
Some("0"), | ||
Some("1"), | ||
Some("1"), | ||
Some("2"), | ||
Some("2"), | ||
] | ||
) | ||
} | ||
|
||
#[test] | ||
fn test_dictionary_fallback() { | ||
let data_type = utf8_dictionary(); | ||
|
@@ -599,7 +662,7 @@ mod tests { | |
.set_dict(encoded_dictionary, 4, Encoding::PLAIN_DICTIONARY, false) | ||
.unwrap(); | ||
|
||
for (encoding, page) in pages { | ||
for (encoding, page) in pages.clone() { | ||
let mut output = DictionaryBuffer::<i32, i32>::default(); | ||
decoder.set_data(encoding, page, 8, None).unwrap(); | ||
assert_eq!(decoder.read(&mut output, 0..1024).unwrap(), 0); | ||
|
@@ -612,5 +675,19 @@ mod tests { | |
assert_eq!(array.len(), 8); | ||
assert_eq!(array.null_count(), 8); | ||
} | ||
|
||
for (encoding, page) in pages { | ||
let mut output = DictionaryBuffer::<i32, i32>::default(); | ||
decoder.set_data(encoding, page, 8, None).unwrap(); | ||
assert_eq!(decoder.skip_values(1024).unwrap(), 0); | ||
|
||
output.pad_nulls(0, 0, 8, &[0]); | ||
let array = output | ||
.into_array(Some(Buffer::from(&[0])), &data_type) | ||
.unwrap(); | ||
|
||
assert_eq!(array.len(), 8); | ||
assert_eq!(array.null_count(), 8); | ||
} | ||
} | ||
} |
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.
miss this will fail at record skip count.