-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Flink: Support writing shredded variant in Flink #15596
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
base: main
Are you sure you want to change the base?
Changes from all commits
8a0be89
87433da
ccca27e
341ecea
13b0903
083f748
c7e4c67
4484b2b
cbeac58
c7d42bb
f64f2ca
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 |
|---|---|---|
|
|
@@ -262,4 +262,22 @@ public Duration tableRefreshInterval() { | |
| .flinkConfig(FlinkWriteOptions.TABLE_REFRESH_INTERVAL) | ||
| .parseOptional(); | ||
| } | ||
|
|
||
| public boolean parquetShredVariants() { | ||
| return confParser | ||
| .booleanConf() | ||
| .option(FlinkWriteOptions.SHRED_VARIANTS.key()) | ||
| .tableProperty(TableProperties.PARQUET_SHRED_VARIANTS) | ||
| .defaultValue(TableProperties.PARQUET_SHRED_VARIANTS_DEFAULT) | ||
|
Comment on lines
+270
to
+271
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. How will we handle when ORC supports shredding variants?
Contributor
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. Good catch . I rename shred-variants to parquet-shred-variants to clarify this feature is only support parquet . If orc support this, then we can add another config.
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. Let's do parquet for now since we followed that pattern for the Spark implementation. |
||
| .parse(); | ||
| } | ||
|
|
||
| public int parquetVariantInferenceBufferSize() { | ||
| return confParser | ||
| .intConf() | ||
| .option(FlinkWriteOptions.VARIANT_INFERENCE_BUFFER_SIZE.key()) | ||
| .tableProperty(TableProperties.PARQUET_VARIANT_BUFFER_SIZE) | ||
| .defaultValue(TableProperties.PARQUET_VARIANT_BUFFER_SIZE_DEFAULT) | ||
| .parse(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,4 +105,10 @@ private FlinkWriteOptions() {} | |
| // specify the uidSuffix to be used for the underlying IcebergSink | ||
| public static final ConfigOption<String> UID_SUFFIX = | ||
| ConfigOptions.key("uid-suffix").stringType().defaultValue(""); | ||
|
|
||
| public static final ConfigOption<Boolean> SHRED_VARIANTS = | ||
| ConfigOptions.key("shred-variants").booleanType().defaultValue(false); | ||
|
|
||
| public static final ConfigOption<Integer> VARIANT_INFERENCE_BUFFER_SIZE = | ||
|
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. parquet-variant-inference-buffer-size |
||
| ConfigOptions.key("variant-inference-buffer-size").intType().noDefaultValue(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package org.apache.iceberg.flink.data; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.nio.ByteOrder; | ||
| import java.util.List; | ||
| import org.apache.flink.table.data.RowData; | ||
| import org.apache.flink.table.types.logical.RowType; | ||
| import org.apache.flink.types.variant.BinaryVariant; | ||
| import org.apache.flink.types.variant.Variant; | ||
| import org.apache.iceberg.parquet.VariantShreddingAnalyzer; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
| import org.apache.iceberg.variants.VariantMetadata; | ||
| import org.apache.iceberg.variants.VariantValue; | ||
|
|
||
| /** | ||
| * Analyzes Variant fields in Flink {@link RowData} and converts Flink's binary Variant | ||
| * representation to Iceberg {@link VariantValue} instances for Variant shredding. | ||
| */ | ||
| public class FlinkVariantShreddingAnalyzer extends VariantShreddingAnalyzer<RowData, RowType> { | ||
|
Guosmilesmile marked this conversation as resolved.
|
||
|
|
||
| @Override | ||
| protected List<VariantValue> extractVariantValues( | ||
| List<RowData> bufferedRows, int variantFieldIndex) { | ||
| List<VariantValue> values = Lists.newArrayList(); | ||
|
|
||
| for (RowData row : bufferedRows) { | ||
| if (!row.isNullAt(variantFieldIndex)) { | ||
| Variant flinkVariant = row.getVariant(variantFieldIndex); | ||
| if (flinkVariant != null) { | ||
| if (flinkVariant instanceof BinaryVariant binaryVariant) { | ||
| VariantValue variantValue = | ||
| VariantValue.from( | ||
| VariantMetadata.from( | ||
| ByteBuffer.wrap(binaryVariant.getMetadata()) | ||
| .order(ByteOrder.LITTLE_ENDIAN)), | ||
| ByteBuffer.wrap(binaryVariant.getValue()).order(ByteOrder.LITTLE_ENDIAN)); | ||
|
|
||
| values.add(variantValue); | ||
| } else { | ||
| throw new UnsupportedOperationException( | ||
| "Not a supported type: " + flinkVariant.getClass()); | ||
| } | ||
| } | ||
|
Guosmilesmile marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| return values; | ||
| } | ||
|
|
||
| @Override | ||
| protected int resolveColumnIndex(RowType flinkSchema, String columnName) { | ||
| return flinkSchema.getFieldIndex(columnName); | ||
| } | ||
| } | ||
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.
parquet-variant-inference-buffer-size