-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-29287: Iceberg: [V3] Variant Shredding support #6152
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| package org.apache.iceberg.mr.hive.writer; | ||
|
|
||
| import java.util.Map; | ||
| import org.apache.iceberg.FileFormat; | ||
| import org.apache.iceberg.Schema; | ||
| import org.apache.iceberg.SortOrder; | ||
|
|
@@ -31,9 +32,13 @@ | |
| import org.apache.iceberg.data.parquet.GenericParquetWriter; | ||
| import org.apache.iceberg.orc.ORC; | ||
| import org.apache.iceberg.parquet.Parquet; | ||
| import org.apache.iceberg.types.Types; | ||
|
|
||
| class HiveFileWriterFactory extends BaseFileWriterFactory<Record> { | ||
|
|
||
| private final Map<String, String> properties; | ||
| private Record sampleRecord = null; | ||
|
|
||
| HiveFileWriterFactory( | ||
| Table table, | ||
| FileFormat dataFileFormat, | ||
|
|
@@ -54,6 +59,7 @@ | |
| equalityDeleteRowSchema, | ||
| equalityDeleteSortOrder, | ||
| positionDeleteRowSchema); | ||
| properties = table.properties(); | ||
| } | ||
|
|
||
| static Builder builderFor(Table table) { | ||
|
|
@@ -78,6 +84,11 @@ | |
| @Override | ||
| protected void configureDataWrite(Parquet.DataWriteBuilder builder) { | ||
| builder.createWriterFunc(GenericParquetWriter::create); | ||
| // Configure variant shredding function if conditions are met: | ||
| if (hasVariantColumns(dataSchema()) && isVariantShreddingEnabled(properties)) { | ||
| var shreddingFunction = Parquet.constructVariantShreddingFunction(sampleRecord, dataSchema()); | ||
| builder.variantShreddingFunc(shreddingFunction); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -149,4 +160,30 @@ | |
| positionDeleteRowSchema); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Check if the schema contains any variant columns. | ||
| */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This is a Javadoc-style comment, but the content is not a Javadoc. Maybe it is better to remove one |
||
| private static boolean hasVariantColumns(Schema schema) { | ||
| return schema.columns().stream() | ||
| .anyMatch(field -> field.type() instanceof Types.VariantType); | ||
| } | ||
|
|
||
| /** | ||
| * Check if variant shredding is enabled via table properties. | ||
| */ | ||
| private static boolean isVariantShreddingEnabled(Map<String, String> properties) { | ||
| String shreddingEnabled = properties.get("variant.shredding.enabled"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be better to use constant string for property
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added constant |
||
| return "true".equalsIgnoreCase(shreddingEnabled); | ||
| } | ||
|
|
||
| /** | ||
| * Set a sample record to use for data-driven variant shredding schema generation. | ||
| * Should be called before the Parquet writer is created. | ||
| */ | ||
| public void initialize(Record record) { | ||
|
Check warning on line 184 in iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/writer/HiveFileWriterFactory.java
|
||
| if (this.sampleRecord == null) { | ||
| this.sampleRecord = record; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the use of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
| } | ||
| } | ||
| } | ||
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.
Is
nullassignment redundant?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.
it's not final, sonar doesn't report this as well