-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: Add Parquet DESCRIPTOR mode for blob inline reading #18683
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
Open
rahil-c
wants to merge
2
commits into
apache:master
Choose a base branch
from
rahil-c:feat/parquet-blob-descriptor-mode
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+708
−21
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
177 changes: 177 additions & 0 deletions
177
...-spark-client/src/test/java/org/apache/hudi/io/storage/TestVectorConversionUtilsBlob.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,177 @@ | ||
| /* | ||
| * 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.hudi.io.storage; | ||
|
|
||
| import org.apache.hudi.common.schema.HoodieSchema; | ||
| import org.apache.hudi.common.schema.HoodieSchemaType; | ||
|
|
||
| import org.apache.spark.sql.catalyst.InternalRow; | ||
| import org.apache.spark.sql.catalyst.expressions.GenericInternalRow; | ||
| import org.apache.spark.sql.types.DataTypes; | ||
| import org.apache.spark.sql.types.Metadata; | ||
| import org.apache.spark.sql.types.MetadataBuilder; | ||
| import org.apache.spark.sql.types.StructField; | ||
| import org.apache.spark.sql.types.StructType; | ||
| import org.apache.spark.unsafe.types.UTF8String; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Set; | ||
| import java.util.function.Function; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| /** | ||
| * Unit tests for the blob descriptor-mode helpers in {@link VectorConversionUtils}. | ||
| */ | ||
| public class TestVectorConversionUtilsBlob { | ||
|
|
||
| private static Metadata blobMeta() { | ||
| return new MetadataBuilder() | ||
| .putString(HoodieSchema.TYPE_METADATA_FIELD, HoodieSchemaType.BLOB.name()) | ||
| .build(); | ||
| } | ||
|
|
||
| private static StructType blobStruct3Field() { | ||
| return new StructType(new StructField[] { | ||
| new StructField(HoodieSchema.Blob.TYPE, DataTypes.StringType, true, Metadata.empty()), | ||
| new StructField(HoodieSchema.Blob.INLINE_DATA_FIELD, DataTypes.BinaryType, true, Metadata.empty()), | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE, | ||
| new StructType(new StructField[] { | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE_PATH, DataTypes.StringType, true, Metadata.empty()), | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE_OFFSET, DataTypes.LongType, true, Metadata.empty()), | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE_LENGTH, DataTypes.LongType, true, Metadata.empty()), | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE_IS_MANAGED, DataTypes.BooleanType, true, Metadata.empty()) | ||
| }), true, Metadata.empty()) | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void detectBlobColumnsFromMetadataFindsMarkedFields() { | ||
| StructType schema = new StructType(new StructField[] { | ||
| new StructField("id", DataTypes.IntegerType, false, Metadata.empty()), | ||
| new StructField("payload", blobStruct3Field(), true, blobMeta()), | ||
| new StructField("name", DataTypes.StringType, true, Metadata.empty()) | ||
| }); | ||
| Set<Integer> blobs = VectorConversionUtils.detectBlobColumnsFromMetadata(schema); | ||
| assertEquals(1, blobs.size()); | ||
| assertTrue(blobs.contains(1)); | ||
| } | ||
|
|
||
| @Test | ||
| public void detectBlobColumnsFromMetadataReturnsEmptyForNonBlob() { | ||
| StructType schema = new StructType(new StructField[] { | ||
| new StructField("id", DataTypes.IntegerType, false, Metadata.empty()), | ||
| new StructField("name", DataTypes.StringType, true, Metadata.empty()) | ||
| }); | ||
| assertTrue(VectorConversionUtils.detectBlobColumnsFromMetadata(schema).isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| public void detectBlobColumnsFromMetadataNullSchema() { | ||
| assertTrue(VectorConversionUtils.detectBlobColumnsFromMetadata(null).isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| public void stripBlobDataFieldRemovesDataAndPreservesOthers() { | ||
| StructType schema = new StructType(new StructField[] { | ||
| new StructField("id", DataTypes.IntegerType, false, Metadata.empty()), | ||
| new StructField("payload", blobStruct3Field(), true, blobMeta()) | ||
| }); | ||
| Set<Integer> blobs = VectorConversionUtils.detectBlobColumnsFromMetadata(schema); | ||
|
|
||
| StructType stripped = VectorConversionUtils.stripBlobDataField(schema, blobs); | ||
|
|
||
| // Top-level fields preserved. | ||
| assertEquals(2, stripped.fields().length); | ||
| assertEquals("id", stripped.fields()[0].name()); | ||
| assertEquals("payload", stripped.fields()[1].name()); | ||
| // Top-level metadata preserved. | ||
| assertTrue(stripped.fields()[1].metadata().contains(HoodieSchema.TYPE_METADATA_FIELD)); | ||
|
|
||
| // Blob struct now has 2 fields: type, reference (no data). | ||
| StructType blob = (StructType) stripped.fields()[1].dataType(); | ||
| assertEquals(2, blob.fields().length); | ||
| assertEquals(HoodieSchema.Blob.TYPE, blob.fields()[0].name()); | ||
| assertEquals(HoodieSchema.Blob.EXTERNAL_REFERENCE, blob.fields()[1].name()); | ||
| assertFalse(blob.getFieldIndex(HoodieSchema.Blob.INLINE_DATA_FIELD).isDefined()); | ||
| } | ||
|
|
||
| @Test | ||
| public void buildBlobNullPadRowMapperReinsertsNullData() { | ||
| StructType readSchema = new StructType(new StructField[] { | ||
| new StructField("id", DataTypes.IntegerType, false, Metadata.empty()), | ||
| new StructField("payload", | ||
| new StructType(new StructField[] { | ||
| new StructField(HoodieSchema.Blob.TYPE, DataTypes.StringType, true, Metadata.empty()), | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE, | ||
| new StructType(new StructField[] { | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE_PATH, DataTypes.StringType, true, Metadata.empty()), | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE_OFFSET, DataTypes.LongType, true, Metadata.empty()), | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE_LENGTH, DataTypes.LongType, true, Metadata.empty()), | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE_IS_MANAGED, DataTypes.BooleanType, true, Metadata.empty()) | ||
| }), true, Metadata.empty()) | ||
| }), true, blobMeta()) | ||
| }); | ||
|
|
||
| GenericInternalRow blob2Field = new GenericInternalRow(2); | ||
| blob2Field.update(0, UTF8String.fromString(HoodieSchema.Blob.INLINE)); | ||
| blob2Field.setNullAt(1); // reference null | ||
| GenericInternalRow input = new GenericInternalRow(2); | ||
| input.update(0, 42); | ||
| input.update(1, blob2Field); | ||
|
|
||
| Function<InternalRow, InternalRow> mapper = | ||
| VectorConversionUtils.buildBlobNullPadRowMapper(readSchema, java.util.Collections.singleton(1), row -> row); | ||
| InternalRow out = mapper.apply(input); | ||
|
|
||
| assertEquals(42, out.getInt(0)); | ||
| InternalRow expanded = out.getStruct(1, 3); | ||
| assertEquals(HoodieSchema.Blob.INLINE, | ||
| expanded.getUTF8String(0).toString()); | ||
| assertTrue(expanded.isNullAt(1), "data should be null after pad"); | ||
| assertTrue(expanded.isNullAt(2), "reference was null in input"); | ||
| } | ||
|
|
||
| @Test | ||
| public void buildBlobNullPadRowMapperHandlesNullBlobRow() { | ||
| StructType readSchema = new StructType(new StructField[] { | ||
| new StructField("payload", | ||
| new StructType(new StructField[] { | ||
| new StructField(HoodieSchema.Blob.TYPE, DataTypes.StringType, true, Metadata.empty()), | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE, | ||
| new StructType(new StructField[] { | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE_PATH, DataTypes.StringType, true, Metadata.empty()), | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE_OFFSET, DataTypes.LongType, true, Metadata.empty()), | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE_LENGTH, DataTypes.LongType, true, Metadata.empty()), | ||
| new StructField(HoodieSchema.Blob.EXTERNAL_REFERENCE_IS_MANAGED, DataTypes.BooleanType, true, Metadata.empty()) | ||
| }), true, Metadata.empty()) | ||
| }), true, blobMeta()) | ||
| }); | ||
|
|
||
| GenericInternalRow input = new GenericInternalRow(1); | ||
| input.setNullAt(0); | ||
|
|
||
| Function<InternalRow, InternalRow> mapper = | ||
| VectorConversionUtils.buildBlobNullPadRowMapper(readSchema, java.util.Collections.singleton(0), row -> row); | ||
| InternalRow out = mapper.apply(input); | ||
| assertTrue(out.isNullAt(0), "null blob row stays null"); | ||
| } | ||
| } |
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.
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.
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.
🤖 For MOR tables with log files, the log-file branch (line 123-126) reads with the full
requiredSchema, so log records keep their populateddatafield, while base-file records under DESCRIPTOR getdata=null. After merge the user sees a mix: records updated via log have bytes, records still in base have null. Is this the intended semantics, or should DESCRIPTOR also null the data on log-file rows for consistency?- AI-generated; verify before applying. React 👍/👎 to flag quality.