-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Data: Enable Parquet variant shredding for Record writes #16370
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
67bfc1a
ce90bc0
03ff0d2
788a74c
ef24bfa
4f6cd1f
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 |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * 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.data; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.iceberg.Schema; | ||
| import org.apache.iceberg.parquet.VariantShreddingAnalyzer; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Maps; | ||
| import org.apache.iceberg.types.Types.NestedField; | ||
| import org.apache.iceberg.variants.Variant; | ||
| import org.apache.iceberg.variants.VariantValue; | ||
|
|
||
| /** | ||
| * Generic {@link Record} implementation that extracts variant values from {@link Record#get(int)} | ||
| * using positional indices aligned with {@link Schema#columns()}. | ||
| * | ||
| * <p>Buffered rows must be laid out against the same {@link Schema} passed as {@code engineSchema}; | ||
| * otherwise {@link Record#get(int)} positions will not match the resolved column indices. | ||
| */ | ||
| class RecordVariantShreddingAnalyzer extends VariantShreddingAnalyzer<Record, Schema> { | ||
|
|
||
| private final Map<Schema, Map<String, Integer>> columnIndicesBySchema = Maps.newHashMap(); | ||
|
|
||
| RecordVariantShreddingAnalyzer() {} | ||
|
|
||
| @Override | ||
|
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. This override duplicates the loop from |
||
| protected int resolveColumnIndex(Schema engineSchema, String columnName) { | ||
| Preconditions.checkNotNull(engineSchema, "Invalid engine schema: null"); | ||
|
|
||
| Map<String, Integer> indices = | ||
| columnIndicesBySchema.computeIfAbsent( | ||
| engineSchema, RecordVariantShreddingAnalyzer::indexByName); | ||
| Integer index = indices.get(columnName); | ||
| return index != null ? index : -1; | ||
| } | ||
|
|
||
| private static Map<String, Integer> indexByName(Schema schema) { | ||
| List<NestedField> cols = schema.columns(); | ||
| Map<String, Integer> indices = Maps.newHashMapWithExpectedSize(cols.size()); | ||
| for (int i = 0; i < cols.size(); i++) { | ||
|
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. Non-blocker, but worth thinking about: this is O(n) per variant column, so O(n·k) for wide schemas (CDC tables with 200+ columns are not uncommon). Spark uses Also, while we're here — the class Javadoc says "positional indices aligned with |
||
| indices.put(cols.get(i).name(), i); | ||
| } | ||
| return indices; | ||
| } | ||
|
|
||
| @Override | ||
| protected List<VariantValue> extractVariantValues( | ||
|
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.
|
||
| List<Record> bufferedRows, int variantFieldIndex) { | ||
| List<VariantValue> values = Lists.newArrayList(); | ||
| for (Record record : bufferedRows) { | ||
| Object fieldValue = record.get(variantFieldIndex); | ||
| if (fieldValue == null) { | ||
| continue; | ||
| } | ||
|
|
||
| Preconditions.checkArgument( | ||
| fieldValue instanceof Variant, | ||
| "Expected Variant at index %s but was: %s", | ||
| variantFieldIndex, | ||
| fieldValue.getClass().getName()); | ||
| values.add(((Variant) fieldValue).value()); | ||
| } | ||
| return values; | ||
| } | ||
| } | ||
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.
This javadoc describes pre-fix state ("is unused", "always produced -1", "never activated") rather than what the method
does. Suggest dropping it -
{@inheritDoc}is the default for overrides and the override's behavior needs to be explained instead