-
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 all 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,8 @@ | |
|
|
||
| package org.apache.iceberg.mr.hive.writer; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.function.Supplier; | ||
| import org.apache.iceberg.FileFormat; | ||
| import org.apache.iceberg.Schema; | ||
| import org.apache.iceberg.SortOrder; | ||
|
|
@@ -31,9 +33,13 @@ | |
| import org.apache.iceberg.data.parquet.GenericParquetWriter; | ||
| import org.apache.iceberg.orc.ORC; | ||
| import org.apache.iceberg.parquet.Parquet; | ||
| import org.apache.iceberg.parquet.VariantUtil; | ||
|
|
||
| class HiveFileWriterFactory extends BaseFileWriterFactory<Record> { | ||
|
|
||
| private final Map<String, String> properties; | ||
| private Supplier<Record> sampleRecord = null; | ||
|
|
||
| HiveFileWriterFactory( | ||
| Table table, | ||
| FileFormat dataFileFormat, | ||
|
|
@@ -54,6 +60,7 @@ class HiveFileWriterFactory extends BaseFileWriterFactory<Record> { | |
| equalityDeleteRowSchema, | ||
| equalityDeleteSortOrder, | ||
| positionDeleteRowSchema); | ||
| properties = table.properties(); | ||
| } | ||
|
|
||
| static Builder builderFor(Table table) { | ||
|
|
@@ -78,6 +85,9 @@ protected void configurePositionDelete(Avro.DeleteWriteBuilder builder) { | |
| @Override | ||
| protected void configureDataWrite(Parquet.DataWriteBuilder builder) { | ||
| builder.createWriterFunc(GenericParquetWriter::create); | ||
| // Configure variant shredding function if conditions are met: | ||
| VariantUtil.variantShreddingFunc(dataSchema(), sampleRecord, properties) | ||
| .ifPresent(builder::variantShreddingFunc); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -149,4 +159,14 @@ HiveFileWriterFactory build() { | |
| positionDeleteRowSchema); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * 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(Supplier<Record> record) { | ||
| if (sampleRecord == null) { | ||
| sampleRecord = record; | ||
|
Comment on lines
+168
to
+169
Member
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. thinking about this, we are taking the first record. Can it lead to but i think there wasn't a better way, maybe in some later world we allow the user itself to define the columns to be shredded
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. yes, something like this, an explicit shredded schema would be a better solution |
||
| } | ||
| } | ||
| } | ||
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 only needs to initialize when the sampleRecord is null? Wouldn't be easier just to always initialize? Maybe there is a special place for caller to handle this.
Uh oh!
There was an error while loading. Please reload this page.
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 captures the first record being written and stores it in sampleRecord. the same strategy is applied in Spark to perform variant shredding.