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 Field Constructors for Complex Fields #3992

Merged
merged 3 commits into from
Mar 31, 2023

Conversation

tustvold
Copy link
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

Declaring nested schema is incredibly verbose, and for some types, especially MapArray and UnionArray, it isn't immediately obvious what constitutes a valid field.

What changes are included in this PR?

Adds various additional constructors to facilitate declaring fields of complex types.

Are there any user-facing changes?

@github-actions github-actions bot added arrow Changes to the arrow crate arrow-flight Changes to the arrow-flight crate parquet Changes to the parquet crate labels Mar 31, 2023
Self::new(
name,
DataType::Union(UnionFields::new(type_ids, fields), mode),
false, // Unions cannot be nullable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is potentially worth highlighting, these constructors allow us to help ensure schema invariants

@@ -145,6 +147,104 @@ impl Field {
}
}

/// Create a new [`Field`] with [`DataType::Dictionary`]
///
/// Use [`Self::new_dict`] for more advanced dictionary options
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IPC dictionary IDs being the most obvious example

@@ -7104,12 +7104,12 @@ mod tests {
fn test_cast_null_from_and_to_nested_type() {
// Cast null from and to map
let data_type = DataType::Map(
Arc::new(Field::new(
Arc::new(Field::new_struct(
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

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.

😍

arrow-schema/src/field.rs Outdated Show resolved Hide resolved
arrow-schema/src/field.rs Outdated Show resolved Hide resolved
arrow-schema/src/field.rs Show resolved Hide resolved
arrow-schema/src/field.rs Outdated Show resolved Hide resolved
arrow-schema/src/field.rs Outdated Show resolved Hide resolved
tustvold and others added 2 commits March 31, 2023 18:36
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
@tustvold tustvold merged commit ef5c58c into apache:master Mar 31, 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 arrow-flight Changes to the arrow-flight crate parquet Changes to the parquet crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants