-
Notifications
You must be signed in to change notification settings - Fork 22
Add Parquet variant shredding support #328
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one or more | ||
| // contributor license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright ownership. | ||
| // The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| // (the "License"); you may not use this file except in compliance with | ||
| // the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| namespace Apache.Arrow.Operations.Shredding | ||
| { | ||
| /// <summary> | ||
| /// Options controlling how <see cref="ShredSchemaInferer"/> infers a shredding schema. | ||
| /// </summary> | ||
| public sealed class ShredOptions | ||
| { | ||
| /// <summary> | ||
| /// Maximum nesting depth for shredded objects and arrays. | ||
| /// 0 means only top-level fields are shredded. | ||
| /// Default is 3. | ||
| /// </summary> | ||
| public int MaxDepth { get; set; } = 3; | ||
|
|
||
| /// <summary> | ||
| /// Minimum fraction of values (0.0–1.0) in which a field must appear | ||
| /// to be considered for shredding. Fields appearing less frequently | ||
| /// than this threshold are left in the binary residual. | ||
| /// Default is 0.5 (50%). | ||
| /// </summary> | ||
| public double MinFieldFrequency { get; set; } = 0.5; | ||
|
|
||
| /// <summary> | ||
| /// Minimum fraction of non-null values (0.0–1.0) for a field that must | ||
| /// share the same type for the field to be shredded as a typed column. | ||
| /// If the type consistency is below this threshold, the field gets a | ||
| /// <see cref="ShredType.None"/> schema (binary-only). | ||
| /// Default is 0.8 (80%). | ||
| /// </summary> | ||
| public double MinTypeConsistency { get; set; } = 0.8; | ||
|
|
||
| /// <summary>Default options.</summary> | ||
| public static readonly ShredOptions Default = new ShredOptions(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one or more | ||
| // contributor license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright ownership. | ||
| // The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| // (the "License"); you may not use this file except in compliance with | ||
| // the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| namespace Apache.Arrow.Operations.Shredding | ||
| { | ||
| /// <summary> | ||
| /// The result of shredding a single variant value: a (value, typed_value) pair. | ||
| /// <para> | ||
| /// Follows the Parquet variant shredding spec encoding matrix: | ||
| /// <list type="bullet"> | ||
| /// <item>Both null → missing (only valid for object sub-fields)</item> | ||
| /// <item>value non-null, typed_value null → unshredded (value in binary)</item> | ||
| /// <item>value null, typed_value non-null → fully shredded into typed column</item> | ||
| /// <item>Both non-null → partially shredded object (typed_value has shredded fields, value has residual)</item> | ||
| /// </list> | ||
| /// </para> | ||
| /// </summary> | ||
| public sealed class ShredResult | ||
| { | ||
| /// <summary> | ||
| /// The residual variant value bytes. These reference the column-level metadata | ||
| /// returned by <see cref="VariantShredder.Shred(System.Collections.Generic.IEnumerable{Apache.Arrow.Variant.VariantValue}, ShredSchema)"/>; | ||
| /// they are NOT self-contained. Non-null when the value (or part of it) could | ||
| /// not be shredded into the typed column. For partially shredded objects this | ||
| /// contains only the unshredded fields. | ||
| /// </summary> | ||
| public byte[] Value { get; } | ||
|
|
||
| /// <summary> | ||
| /// The typed value extracted according to the schema. The runtime type depends | ||
| /// on the <see cref="ShredSchema.TypedValueType"/>: | ||
| /// <list type="bullet"> | ||
| /// <item>Primitives: the corresponding CLR type (bool, int, long, double, string, etc.)</item> | ||
| /// <item>Object: <see cref="ShredObjectResult"/></item> | ||
| /// <item>Array: <see cref="ShredArrayResult"/></item> | ||
| /// </list> | ||
| /// Null when the value does not match the schema type (falls back to binary). | ||
| /// </summary> | ||
| public object TypedValue { get; } | ||
|
|
||
| /// <summary> | ||
| /// True when both <see cref="Value"/> and <see cref="TypedValue"/> are null, | ||
| /// indicating the field is missing (only valid for object sub-fields). | ||
| /// </summary> | ||
| public bool IsMissing => Value == null && TypedValue == null; | ||
|
|
||
| /// <summary>Creates a shred result.</summary> | ||
| public ShredResult(byte[] value, object typedValue) | ||
| { | ||
| Value = value; | ||
| TypedValue = typedValue; | ||
| } | ||
|
|
||
| /// <summary>A missing result (both null).</summary> | ||
| public static readonly ShredResult Missing = new ShredResult(null, null); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The typed_value result for a shredded object. Contains one <see cref="ShredResult"/> | ||
| /// per field defined in the object's <see cref="ShredSchema"/>. | ||
| /// </summary> | ||
| public sealed class ShredObjectResult | ||
| { | ||
| /// <summary> | ||
| /// Shredded fields, keyed by field name matching the <see cref="ShredSchema.ObjectFields"/>. | ||
| /// Each entry is the shredded (value, typed_value) pair for that field. | ||
| /// </summary> | ||
| public IReadOnlyDictionary<string, ShredResult> Fields { get; } | ||
|
|
||
| /// <summary>Creates a shredded object result.</summary> | ||
| public ShredObjectResult(IReadOnlyDictionary<string, ShredResult> fields) | ||
| { | ||
| Fields = fields; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The typed_value result for a shredded array. Contains one <see cref="ShredResult"/> | ||
| /// per element in the source array. | ||
| /// </summary> | ||
| public sealed class ShredArrayResult | ||
| { | ||
| /// <summary> | ||
| /// Shredded elements. Each entry is the shredded (value, typed_value) pair for that element. | ||
| /// Array elements are never missing — null elements are encoded as variant null in the value column. | ||
| /// </summary> | ||
| public IReadOnlyList<ShredResult> Elements { get; } | ||
|
|
||
| /// <summary>Creates a shredded array result.</summary> | ||
| public ShredArrayResult(IReadOnlyList<ShredResult> elements) | ||
| { | ||
| Elements = elements; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ShredOptions.Defaultis a mutable static instance (the type has settable properties). Any consumer that doesShredOptions.Default.MaxDepth = ...will mutate global state for the entire process, which is easy to do accidentally and hard to debug. Consider makingDefaultreturn a new instance each time (e.g.,=> new ShredOptions()), making the options immutable (init-only), or exposing aCreateDefault()factory instead.