Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.6k
[IcebergIO] Fix conversion logic for arrays of structs and maps of structs; fix output Schema resolution with column pruning#35230
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b8d79a9
fix complex types; filx filter schema logic
ahmedabu98 c6f2013
update Changes
ahmedabu98 c1b967b
add missing changes from other PRs
ahmedabu98 0aedfec
trigger ITs
ahmedabu98 49bbb2c
make separate impl for iterable
ahmedabu98 377bf50
fix
ahmedabu98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| { | ||
| "comment": "Modify this file in a trivial way to cause this test suite to run.", | ||
| "modification": 3, | ||
| "https://github.com/apache/beam/pull/35159": "moving WindowedValue and making an interface" | ||
| "modification": 5 | ||
| } |
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
51 changes: 51 additions & 0 deletions
51 sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/FilterUtils.java
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
2 changes: 1 addition & 1 deletion
2 sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/IcebergIO.java
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
70 changes: 61 additions & 9 deletions
70 sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/IcebergScanConfig.java
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
93 changes: 90 additions & 3 deletions
93 sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/IcebergUtils.java
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 |
|---|---|---|
| @@ -18,6 +18,8 @@ | ||
| package org.apache.beam.sdk.io.iceberg; | ||
| import static org.apache.beam.sdk.util.Preconditions.checkArgumentNotNull; | ||
| import static org.apache.beam.sdk.util.Preconditions.checkStateNotNull; | ||
| import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkState; | ||
| import java.nio.ByteBuffer; | ||
| import java.time.LocalDate; | ||
| @@ -30,17 +32,20 @@ | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
| import java.util.stream.Collectors; | ||
| import org.apache.beam.sdk.schemas.Schema; | ||
| import org.apache.beam.sdk.schemas.logicaltypes.SqlTypes; | ||
| import org.apache.beam.sdk.util.Preconditions; | ||
| import org.apache.beam.sdk.values.Row; | ||
| import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.annotations.VisibleForTesting; | ||
| import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableList; | ||
| import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; | ||
| import org.apache.iceberg.data.GenericRecord; | ||
| import org.apache.iceberg.data.Record; | ||
| import org.apache.iceberg.types.Type; | ||
| import org.apache.iceberg.types.Types; | ||
| import org.apache.iceberg.util.DateTimeUtil; | ||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
| import org.joda.time.DateTime; | ||
| import org.joda.time.Instant; | ||
| @@ -345,10 +350,34 @@ private static void copyFieldIntoRecord(Record rec, Types.NestedField field, Row | ||
| copyRowIntoRecord(GenericRecord.create(field.type().asStructType()), row))); | ||
| break; | ||
| case LIST: | ||
| Optional.ofNullable(value.getArray(name)).ifPresent(list -> rec.setField(name, list)); | ||
| Iterable<@NonNull ?> icebergList = value.getIterable(name); | ||
| Type collectionType = ((Types.ListType) field.type()).elementType(); | ||
| if (collectionType.isStructType() && icebergList != null) { | ||
| org.apache.iceberg.Schema innerSchema = collectionType.asStructType().asSchema(); | ||
| ImmutableList.Builder<Record> builder = ImmutableList.builder(); | ||
| for (Row v : (Iterable<Row>) icebergList) { | ||
| builder.add(beamRowToIcebergRecord(innerSchema, v)); | ||
| } | ||
| icebergList = builder.build(); | ||
| } | ||
| Optional.ofNullable(icebergList).ifPresent(list -> rec.setField(name, list)); | ||
| break; | ||
| case MAP: | ||
| Optional.ofNullable(value.getMap(name)).ifPresent(v -> rec.setField(name, v)); | ||
| Map<?, ?> icebergMap = value.getMap(name); | ||
| Type valueType = ((Types.MapType) field.type()).valueType(); | ||
| // recurse on struct types | ||
| if (valueType.isStructType() && icebergMap != null) { | ||
| org.apache.iceberg.Schema innerSchema = valueType.asStructType().asSchema(); | ||
| ImmutableMap.Builder<Object, Record> newMap = ImmutableMap.builder(); | ||
| for (Map.Entry<?, ?> entry : icebergMap.entrySet()) { | ||
| Row row = checkStateNotNull(((Row) entry.getValue())); | ||
| newMap.put(checkStateNotNull(entry.getKey()), beamRowToIcebergRecord(innerSchema, row)); | ||
| } | ||
| icebergMap = newMap.build(); | ||
| } | ||
| Optional.ofNullable(icebergMap).ifPresent(v -> rec.setField(name, v)); | ||
| break; | ||
| } | ||
| } | ||
| @@ -426,10 +455,68 @@ public static Row icebergRecordToBeamRow(Schema schema, Record record) { | ||
| case DOUBLE: // Iceberg and Beam both use double | ||
| case STRING: // Iceberg and Beam both use String | ||
| case BOOLEAN: // Iceberg and Beam both use boolean | ||
| rowBuilder.addValue(icebergValue); | ||
| break; | ||
| case ARRAY: | ||
| checkState( | ||
| icebergValue instanceof List, | ||
ahmedabu98 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| "Expected List type for field '%s' but received %s", | ||
| field.getName(), | ||
| icebergValue.getClass()); | ||
| List<@NonNull ?> beamList = (List<@NonNull ?>) icebergValue; | ||
| Schema.FieldType collectionType = | ||
| checkStateNotNull(field.getType().getCollectionElementType()); | ||
| // recurse on struct types | ||
| if (collectionType.getTypeName().isCompositeType()) { | ||
| Schema innerSchema = checkStateNotNull(collectionType.getRowSchema()); | ||
| beamList = | ||
| beamList.stream() | ||
| .map(v -> icebergRecordToBeamRow(innerSchema, (Record) v)) | ||
| .collect(Collectors.toList()); | ||
| } | ||
| rowBuilder.addValue(beamList); | ||
| break; | ||
| case ITERABLE: | ||
| checkState( | ||
| icebergValue instanceof Iterable, | ||
| "Expected Iterable type for field '%s' but received %s", | ||
| field.getName(), | ||
| icebergValue.getClass()); | ||
| Iterable<@NonNull ?> beamIterable = (Iterable<@NonNull ?>) icebergValue; | ||
| Schema.FieldType iterableCollectionType = | ||
| checkStateNotNull(field.getType().getCollectionElementType()); | ||
| // recurse on struct types | ||
| if (iterableCollectionType.getTypeName().isCompositeType()) { | ||
| Schema innerSchema = checkStateNotNull(iterableCollectionType.getRowSchema()); | ||
| ImmutableList.Builder<Row> builder = ImmutableList.builder(); | ||
| for (Record v : (Iterable<@NonNull Record>) icebergValue) { | ||
| builder.add(icebergRecordToBeamRow(innerSchema, v)); | ||
| } | ||
| beamIterable = builder.build(); | ||
| } | ||
| rowBuilder.addValue(beamIterable); | ||
| break; | ||
| case MAP: | ||
| rowBuilder.addValue(icebergValue); | ||
| checkState( | ||
| icebergValue instanceof Map, | ||
| "Expected Map type for field '%s' but received %s", | ||
| field.getName(), | ||
| icebergValue.getClass()); | ||
| Map<?, ?> beamMap = (Map<?, ?>) icebergValue; | ||
| Schema.FieldType valueType = checkStateNotNull(field.getType().getMapValueType()); | ||
| // recurse on struct types | ||
| if (valueType.getTypeName().isCompositeType()) { | ||
| Schema innerSchema = checkStateNotNull(valueType.getRowSchema()); | ||
| ImmutableMap.Builder<Object, Row> newMap = ImmutableMap.builder(); | ||
| for (Map.Entry<?, ?> entry : ((Map<?, ?>) icebergValue).entrySet()) { | ||
| Record rec = ((Record) entry.getValue()); | ||
| newMap.put( | ||
| checkStateNotNull(entry.getKey()), | ||
| icebergRecordToBeamRow(innerSchema, checkStateNotNull(rec))); | ||
| } | ||
| beamMap = newMap.build(); | ||
| } | ||
| rowBuilder.addValue(beamMap); | ||
| break; | ||
| case DATETIME: | ||
| // Iceberg uses a long for micros. | ||
5 changes: 2 additions & 3 deletions
5 sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/ReadFromTasks.java
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.