tustvold commented on code in PR #3212:
URL: https://github.com/apache/arrow-rs/pull/3212#discussion_r1033972417
##########
arrow/src/row/mod.rs:
##########
@@ -872,35 +980,59 @@ fn encode_column(
out: &mut Rows,
column: &ArrayRef,
opts: SortOptions,
- dictionary: Option<&[Option<&[u8]>]>,
+ encoder: &Encoder<'_>,
) {
- downcast_primitive_array! {
- column => fixed::encode(out, column, opts),
- DataType::Null => {}
- DataType::Boolean => fixed::encode(out, as_boolean_array(column),
opts),
- DataType::Binary => {
- variable::encode(out,
as_generic_binary_array::<i32>(column).iter(), opts)
+ match encoder {
+ Encoder::Stateless => {
+ downcast_primitive_array! {
+ column => fixed::encode(out, column, opts),
+ DataType::Null => {}
+ DataType::Boolean => fixed::encode(out,
as_boolean_array(column), opts),
+ DataType::Binary => {
+ variable::encode(out,
as_generic_binary_array::<i32>(column).iter(), opts)
+ }
+ DataType::LargeBinary => {
+ variable::encode(out,
as_generic_binary_array::<i64>(column).iter(), opts)
+ }
+ DataType::Utf8 => variable::encode(
+ out,
+ as_string_array(column).iter().map(|x| x.map(|x|
x.as_bytes())),
+ opts,
+ ),
+ DataType::LargeUtf8 => variable::encode(
+ out,
+ as_largestring_array(column)
+ .iter()
+ .map(|x| x.map(|x| x.as_bytes())),
+ opts,
+ ),
+ _ => unreachable!(),
+ }
}
- DataType::LargeBinary => {
- variable::encode(out,
as_generic_binary_array::<i64>(column).iter(), opts)
+ Encoder::Dictionary(dict) => {
+ downcast_dictionary_array! {
+ column => encode_dictionary(out, column, dict, opts),
+ _ => unreachable!()
+ }
}
- DataType::Utf8 => variable::encode(
- out,
- as_string_array(column).iter().map(|x| x.map(|x| x.as_bytes())),
- opts,
- ),
- DataType::LargeUtf8 => variable::encode(
- out,
- as_largestring_array(column)
- .iter()
- .map(|x| x.map(|x| x.as_bytes())),
- opts,
- ),
- DataType::Dictionary(_, _) => downcast_dictionary_array! {
- column => encode_dictionary(out, column, dictionary.unwrap(),
opts),
- _ => unreachable!()
+ Encoder::Struct(rows, null) => {
+ let array = as_struct_array(column.as_ref());
+ let null_sentinel = null_sentinel(opts);
+ out.offsets
+ .iter_mut()
+ .skip(1)
+ .enumerate()
+ .for_each(|(idx, offset)| {
+ let (row, sentinel) = match array.is_valid(idx) {
+ true => (rows.row(idx), 0x01),
+ false => (*null, null_sentinel),
+ };
+ let end_offset = *offset + 1 + row.as_ref().len();
+ out.buffer[*offset] = sentinel;
+ out.buffer[*offset +
1..end_offset].copy_from_slice(row.as_ref());
Review Comment:
> aren't accidentally compared with the contents of another field
The same way as normal, effectively this approach flattens the schema in a
depth first manner. Lists will need encoding in this way, that's still to come
:smile:
> Also I wonder why not encode the struct array directly into out rather
than copy it from another Rows?
Nulls, we need to not encode the values if the `StructArray` contains a
null. Otherwise you would potentially establish an ordering between nulls,
based on the "masked" values.
--
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]