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

feat: enable metadata import/export through C data interface #3944

Merged
merged 6 commits into from
Mar 29, 2023

Conversation

wjones127
Copy link
Member

Which issue does this PR close?

Closes #478.

Rationale for this change

Metadata is used in extension types to communicate additional information. For example, the geoarrow specification uses field metadata to communicate extension types and coordinate systems for geospatial arrays.

What changes are included in this PR?

Adds metadata round tripping for fields and schemas.

Are there any user-facing changes?

Fields and schemas brought through the C data interface will now have their metadata preserved.

@github-actions github-actions bot added the arrow Changes to the arrow crate label Mar 25, 2023
@tustvold
Copy link
Contributor

I plan to review this carefully tomorrow

arrow-schema/src/ffi.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

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

What a peculiar interface, thank you for working through this, just some minor nits

arrow-schema/src/ffi.rs Outdated Show resolved Hide resolved
Comment on lines 170 to 171
let key_len = key.len() as i32;
let value_len = value.len() as i32;
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 worth checking this doesn't overflow?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't imagine this will ever come up as an issue. I'm also inferring from the fact that there's no conversion trait from the TryFrom associated error to ArrowError this isn't commonly handled elsewhere in the codebase.

Copy link
Contributor

@tustvold tustvold Mar 28, 2023

Choose a reason for hiding this comment

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

The codebase is full of overflow handling, take a look at the builders or take kernels or Array validation.

I'm keen that we are defensive here, because the implications of incorrect data is that we or the downstream reader go off reading arbitrary memory

Ok(HashMap::new())
} else {
let mut pos = 0;
let buffer: *const u8 = self.metadata as *const u8;
Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly not much we can do about this, but it occurs to me that this parsing code can very easily read into arbitrary memory

Copy link
Member Author

Choose a reason for hiding this comment

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

The one thing I can think of is we can verify the lengths are all >= 0. It doesn't guarantee we will detect buffer overflow but it will let us detect it some of the time 🤷

wjones127 and others added 4 commits March 27, 2023 18:35
Co-authored-by: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com>
@wjones127 wjones127 requested a review from tustvold March 29, 2023 02:43
@tustvold tustvold merged commit e919e99 into apache:master Mar 29, 2023
@tustvold
Copy link
Contributor

Thank you

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.

Exchange key-value metadata in the python FFI bridge
2 participants