-
Notifications
You must be signed in to change notification settings - Fork 1.5k
GH-3211: Implement Variant parquet reader #3212
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
rdblue
merged 31 commits into
apache:master
from
cashmand:variant_shredding_avro_reader
May 21, 2025
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
9892a13
Create VariantSchema
cashmand ff0f110
Fixing
cashmand e9c4839
Tests pass
cashmand f740a68
Fix and update tests for byte/short/int/long
cashmand c834b7b
Cleanup
cashmand e73a0d1
Cleanup
cashmand b242081
Code review feedback
cashmand d01a912
Refactor
cashmand eef2a55
Cleanup
cashmand 19cc666
Formatting
cashmand 09a6da4
Code review feedback
cashmand 5922bee
spotless
cashmand dffa73c
Switch to rootBuilder
cashmand c67dcbe
Simple code review feedback
cashmand e6573d6
Refactor metadata.
cashmand b6ceb7d
Rename file
cashmand 240e043
Remove builder holders
cashmand b2b5d1d
Refactor object and write pos.
cashmand 710dc64
Create a BinaryConverter base class
cashmand 7c56822
Cleanup
cashmand 5ed5536
Fix
cashmand d10b34a
Switch value reader from pull to push
cashmand 955fe9a
Code review feedback
cashmand e9f74a9
Variant: Refactor readers to use a parent handler.
rdblue c32ece0
Revert "Code review feedback"
cashmand 5150b5b
Revert "Switch value reader from pull to push"
cashmand 8fbde65
Merge branch 'ryan_shredding_changes' into variant_shredding_avro_reader
cashmand ebfe322
Remove rootBuilder
cashmand cc0b38f
spotless
cashmand cebcf37
Test out of order value and metadata
cashmand f6c2eec
Fix
cashmand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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
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
96 changes: 96 additions & 0 deletions
96
parquet-avro/src/main/java/org/apache/parquet/avro/AvroVariantConverter.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 |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /* | ||
| * 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.parquet.avro; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.function.Consumer; | ||
| import org.apache.avro.Schema; | ||
| import org.apache.avro.generic.GenericData; | ||
| import org.apache.parquet.Preconditions; | ||
| import org.apache.parquet.io.api.Converter; | ||
| import org.apache.parquet.io.api.GroupConverter; | ||
| import org.apache.parquet.schema.GroupType; | ||
| import org.apache.parquet.variant.ImmutableMetadata; | ||
| import org.apache.parquet.variant.VariantBuilder; | ||
| import org.apache.parquet.variant.VariantConverters; | ||
|
|
||
| /** | ||
| * Converter for Variant values. | ||
| */ | ||
| class AvroVariantConverter extends GroupConverter implements VariantConverters.ParentConverter<VariantBuilder> { | ||
| private final ParentValueContainer parent; | ||
| private final Schema avroSchema; | ||
| private final GenericData model; | ||
| private final int metadataPos; | ||
| private final int valuePos; | ||
| private final GroupConverter wrappedConverter; | ||
|
|
||
| private VariantBuilder builder = null; | ||
| private ImmutableMetadata metadata = null; | ||
|
|
||
| AvroVariantConverter(ParentValueContainer parent, GroupType variantGroup, Schema avroSchema, GenericData model) { | ||
| this.parent = parent; | ||
| this.avroSchema = avroSchema; | ||
| this.metadataPos = avroSchema.getField("metadata").pos(); | ||
| this.valuePos = avroSchema.getField("value").pos(); | ||
| this.model = model; | ||
| this.wrappedConverter = VariantConverters.newVariantConverter(variantGroup, this::setMetadata, this); | ||
| } | ||
|
|
||
| @Override | ||
| public void build(Consumer<VariantBuilder> consumer) { | ||
| Preconditions.checkState(builder != null, "Cannot build variant: builder has not been initialized"); | ||
| consumer.accept(builder); | ||
| } | ||
|
|
||
| @Override | ||
| public Converter getConverter(int fieldIndex) { | ||
| return wrappedConverter.getConverter(fieldIndex); | ||
| } | ||
|
|
||
| @Override | ||
| public void start() { | ||
| wrappedConverter.start(); | ||
| } | ||
|
|
||
| @Override | ||
| public void end() { | ||
| wrappedConverter.end(); | ||
|
|
||
| Preconditions.checkState(metadata != null, "Cannot build variant: missing metadata"); | ||
|
|
||
| builder.appendNullIfEmpty(); | ||
|
|
||
| Object record = model.newRecord(null, avroSchema); | ||
| model.setField(record, "metadata", metadataPos, metadata.getEncodedBuffer()); | ||
| model.setField(record, "value", valuePos, builder.encodedValue()); | ||
| parent.add(record); | ||
|
|
||
| this.builder = null; | ||
| } | ||
|
|
||
| void setMetadata(ByteBuffer metadataBuffer) { | ||
| // If the metadata hasn't changed, we don't need to rebuild the map. | ||
| if (metadata == null || metadata.getEncodedBuffer() != metadataBuffer) { | ||
| this.metadata = new ImmutableMetadata(metadataBuffer); | ||
| } | ||
|
|
||
| this.builder = new VariantBuilder(metadata); | ||
| } | ||
| } |
Oops, something went wrong.
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.