Skip to content
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

Support StructArray in Row Format (#3159) #3212

Merged
merged 5 commits into from
Nov 29, 2022

Conversation

tustvold
Copy link
Contributor

Which issue does this PR close?

Part of #3159

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Nov 28, 2022
@tustvold tustvold requested a review from alamb November 28, 2022 17:36
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not fully understand how this encoding will avoid conflicts with other fields potentially as the length of an encoded Struct can be variable length as well

Otherwise I had some other comments, but I don't think any would prevent this PR from being merged

arrow/src/row/mod.rs Show resolved Hide resolved
@@ -307,6 +308,13 @@ mod variable;
///
/// Input Row Format
/// ```
///
/// ## Struct Encoding
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

#[derive(Debug)]
enum Codec {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracting this into Codec` is a nice generalization

Ok(Self::Struct(converter, owned))
}
_ => Err(ArrowError::NotYetImplemented(format!(
"not yet implemented: {:?}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"not yet implemented: {:?}",
"Row format support not yet implemented for: {:?}",

.iter()
.zip(lengths.iter_mut())
.for_each(|(slice, length)| *length += variable::encoded_len(slice)),
DataType::Utf8 => as_string_array(array)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing this list of types I think it is going to conflict with #3182

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, most definitely 😁

}
Codec::Struct(converter, null) => {
let v = as_struct_array(array);
let rows = converter.convert_columns(v.columns())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it true that this code converts the struct array to row format now and then the individual rows are copied over one by one into the resulting format?

In other words, the row format form of the struct array is copied?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup - we just flatten the schema, so a Struct{Int32, Int32}, Struct{Float32} is encoded similarly to Int32,Int32,Float32 albeit with additional nullability for the structs

};
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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the row format of Struct arrays can be variable length, how are we ensuring that the contents of one struct array aren't accidentally compared with the contents of another field (e.g. the COBs encoding approach for variable length strings).

Also I wonder why not encode the struct array directly into out rather than copy it from another Rows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 😄

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on adding a diagram to show this more clearly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 explanation makes sense -- I suggest you put it as a comment somewhere as it was not obvious to me while reading this PR.

@@ -1329,6 +1502,54 @@ mod tests {
assert_eq!(&cols[0], &a);
}

#[test]
fn test_struct() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be valuable to more than one level (aka a struct array with a struct array child)? Also, how about a struct array with another type?

@tustvold tustvold merged commit 733d32e into apache:master Nov 29, 2022
@ursabot
Copy link

ursabot commented Nov 29, 2022

Benchmark runs are scheduled for baseline = b2bfe9c and contender = 733d32e. 733d32e is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants