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

Add UnionFields (#3955) #3981

Merged
merged 4 commits into from
Mar 30, 2023
Merged

Add UnionFields (#3955) #3981

merged 4 commits into from
Mar 30, 2023

Conversation

tustvold
Copy link
Contributor

@tustvold tustvold commented Mar 30, 2023

Which issue does this PR close?

Part of #3955

Rationale for this change

  • Reduces cloning of Field Reduce Cloning of Field #3955
  • Adds an abstraction to allow improving ergonomics of interacting with Union datatypes
  • Reduces the size of DataType from 56 bytes to 24 bytes

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added arrow Changes to the arrow crate parquet Changes to the parquet crate labels Mar 30, 2023
}
}

impl UnionFields {
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 purposefully kept the size of this interface down as I don't feel we have very mature support for UnionArrays and therefore I didn't want to paint ourselves into a corner too much w.r.t what this abstraction looked like

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please add documentation that explains:

  1. what type_ids are (a link to the spec / docs)
  2. has an example of how to construct these things

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.

Reduces the size of DataType from 56 bytes to 24 bytes

🎉

I think given that the size of DataType is an important metric, we should also add a test that verifies it doesn't change by accident -- like https://github.com/apache/arrow-datafusion/blob/8e125d2ecf242b4f4b81f06839900dbb2037cc2a/datafusion/common/src/scalar.rs#L3728-L3738

}
}

impl UnionFields {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please add documentation that explains:

  1. what type_ids are (a link to the spec / docs)
  2. has an example of how to construct these things

}

/// Create a new [`UnionFields`] from a [`Fields`] and array of type_ids
pub fn new<F, T>(type_ids: T, fields: F) -> Self
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be fallible (to prevent repeated type ids, for example)?

Copy link
Contributor Author

@tustvold tustvold Mar 30, 2023

Choose a reason for hiding this comment

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

I honestly wasn't sure about this, the existing code doesn't handle this consistently. I'll file a ticket

Edit: #3982

self.0.iter().map(|(id, f)| (*id, f))
}

pub(crate) fn try_merge(&mut self, other: &Self) -> Result<(), ArrowError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add some docs about what this does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, should have called out in review, just moved some code here. Added docs in 07af4ff

@tustvold tustvold merged commit e5a1676 into apache:master Mar 30, 2023
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 parquet Changes to the parquet crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants