-
Notifications
You must be signed in to change notification settings - Fork 1.6k
GH-3710: Tolerate unrecognized logical/physical type combinations when reading #3711
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
divjotarora
wants to merge
2
commits into
apache:master
Choose a base branch
from
divjotarora:log-phys-type-combo
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.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,12 +106,16 @@ | |
| import org.apache.parquet.format.GeospatialStatistics; | ||
| import org.apache.parquet.format.LogicalType; | ||
| import org.apache.parquet.format.MapType; | ||
| import org.apache.parquet.format.MilliSeconds; | ||
| import org.apache.parquet.format.PageHeader; | ||
| import org.apache.parquet.format.PageType; | ||
| import org.apache.parquet.format.RowGroup; | ||
| import org.apache.parquet.format.SchemaElement; | ||
| import org.apache.parquet.format.StringType; | ||
| import org.apache.parquet.format.TimeUnit; | ||
| import org.apache.parquet.format.TimestampType; | ||
| import org.apache.parquet.format.Type; | ||
| import org.apache.parquet.format.TypeDefinedOrder; | ||
| import org.apache.parquet.format.Util; | ||
| import org.apache.parquet.hadoop.ParquetReader; | ||
| import org.apache.parquet.hadoop.ParquetWriter; | ||
|
|
@@ -2279,4 +2283,62 @@ public void testColumnIndexNanCountsRoundTrip() { | |
| assertThat(roundTrip).isNotNull(); | ||
| assertThat(roundTrip.getNanCounts()).containsExactly(1L, 0L, 0L); | ||
| } | ||
|
|
||
| @Test | ||
|
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. not sure where the right file for it is but it would be good to have a more end-to-end test.
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. Added a new |
||
| public void testUnsupportedTypeCombinationDropsAnnotationAndStats() { | ||
| ParquetMetadataConverter converter = new ParquetMetadataConverter(); | ||
| TimeUnit unit = new TimeUnit(); | ||
| unit.setMILLIS(new MilliSeconds()); | ||
| SchemaElement leaf = new SchemaElement("bool_ts") | ||
| .setRepetition_type(FieldRepetitionType.OPTIONAL) | ||
| .setType(Type.BOOLEAN) | ||
| .setLogicalType(LogicalType.TIMESTAMP(new TimestampType(true, unit))); | ||
| List<SchemaElement> parquetSchema = Lists.newArrayList(new SchemaElement("Message").setNum_children(1), leaf); | ||
| List<org.apache.parquet.format.ColumnOrder> columnOrders = | ||
| Lists.newArrayList(new org.apache.parquet.format.ColumnOrder()); | ||
| columnOrders.get(0).setTYPE_ORDER(new TypeDefinedOrder()); | ||
|
|
||
| MessageType schema = converter.fromParquetSchema(parquetSchema, columnOrders); | ||
|
|
||
| PrimitiveType result = schema.getType("bool_ts").asPrimitiveType(); | ||
| assertThat(result.getPrimitiveTypeName()).isEqualTo(PrimitiveTypeName.BOOLEAN); | ||
| assertThat(result.getLogicalTypeAnnotation()).isNull(); | ||
| assertThat(result.columnOrder().getColumnOrderName()).isEqualTo(ColumnOrder.ColumnOrderName.UNDEFINED); | ||
| } | ||
|
|
||
| private static PrimitiveType droppedAnnotationInt32() { | ||
| return Types.optional(PrimitiveTypeName.INT32) | ||
| .columnOrder(ColumnOrder.undefined()) | ||
| .named("ts_int32"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDroppedAnnotationIgnoresStats() { | ||
| ParquetMetadataConverter converter = new ParquetMetadataConverter(); | ||
| org.apache.parquet.format.Statistics stats = new org.apache.parquet.format.Statistics(); | ||
| stats.setMin_value(new byte[] {1, 2, 3, 4}); | ||
| stats.setMax_value(new byte[] {0, 1, 2, 3}); | ||
| stats.setNull_count(3L); | ||
|
|
||
| Statistics<?> result = converter.fromParquetStatistics(Version.FULL_VERSION, stats, droppedAnnotationInt32()); | ||
|
|
||
| assertThat(result.hasNonNullValue()).isFalse(); | ||
| assertThat(result.isNumNullsSet()).isTrue(); | ||
| assertThat(result.getNumNulls()).isEqualTo(3L); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDroppedAnnotationColumnIndexIsNull() { | ||
| PrimitiveType int32Type = Types.required(PrimitiveTypeName.INT32).named("i32"); | ||
| ColumnIndexBuilder cb = ColumnIndexBuilder.getBuilder(int32Type, Integer.MAX_VALUE); | ||
| Statistics<?> stats = Statistics.createStats(int32Type); | ||
| stats.updateStats(-100); | ||
| stats.updateStats(100); | ||
| cb.add(stats, null); | ||
| org.apache.parquet.format.ColumnIndex parquetColumnIndex = | ||
| ParquetMetadataConverter.toParquetColumnIndex(int32Type, cb.build()); | ||
|
|
||
| assertThat(ParquetMetadataConverter.fromParquetColumnIndex(droppedAnnotationInt32(), parquetColumnIndex)) | ||
| .isNull(); | ||
| } | ||
| } | ||
77 changes: 77 additions & 0 deletions
77
parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestReadInvalidTypeCombination.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,77 @@ | ||
| /* | ||
| * 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.hadoop; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.net.URISyntaxException; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.parquet.example.data.Group; | ||
| import org.apache.parquet.hadoop.example.GroupReadSupport; | ||
| import org.apache.parquet.hadoop.metadata.ParquetMetadata; | ||
| import org.apache.parquet.hadoop.util.HadoopInputFile; | ||
| import org.apache.parquet.schema.ColumnOrder.ColumnOrderName; | ||
| import org.apache.parquet.schema.PrimitiveType; | ||
| import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class TestReadInvalidTypeCombination { | ||
|
|
||
| // Path to a Parquet file that contains an invalid logical/physical type combination. | ||
| private static final String FILE_PATH = "/invalid_type_combination.parquet"; | ||
|
|
||
| private static Path getFilePath() { | ||
| try { | ||
| return new Path(TestReadInvalidTypeCombination.class.getResource(FILE_PATH).toURI()); | ||
| } catch (URISyntaxException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testReadInvalidTypeCombinationSucceeds() throws Exception { | ||
| Configuration conf = new Configuration(); | ||
| Path file = getFilePath(); | ||
|
|
||
| // The footer parse should succeed and drop the annotation and stats for the column. | ||
| try (ParquetFileReader reader = ParquetFileReader.open(HadoopInputFile.fromPath(file, conf))) { | ||
| ParquetMetadata footer = reader.getFooter(); | ||
| PrimitiveType column = | ||
| footer.getFileMetaData().getSchema().getType("int32_uuid").asPrimitiveType(); | ||
|
|
||
| assertThat(column.getPrimitiveTypeName()).isEqualTo(PrimitiveTypeName.INT32); | ||
| assertThat(column.getLogicalTypeAnnotation()).isNull(); | ||
| assertThat(column.columnOrder().getColumnOrderName()).isEqualTo(ColumnOrderName.UNDEFINED); | ||
| } | ||
|
|
||
| // The physical values are still fully readable. | ||
| int rows = 0; | ||
| try (ParquetReader<Group> reader = ParquetReader.builder(new GroupReadSupport(), file) | ||
| .withConf(conf) | ||
| .build()) { | ||
| Group g; | ||
| while ((g = reader.read()) != null) { | ||
| assertThat(g.getInteger("int32_uuid", 0)).isEqualTo(rows); | ||
| rows++; | ||
| } | ||
| } | ||
| assertThat(rows).isEqualTo(10); | ||
| } | ||
| } |
Binary file not shown.
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.
how is this method expected to be called in practice?
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 is called directly in
ParquetMetadataConverter.javahere