-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support backwards compatible reads for unnanotated repeated primitive
fields in Parquet Per the Parquet Spec `A repeated field that is neither contained by a LIST- or MAP-annotated group nor annotated by LIST or MAP should be interpreted as a required list of required elements where the element type is the type of the field`, however Trino currently throws an error: `class org.apache.parquet.io.PrimitiveColumnIO cannot be cast to class org.apache.parquet.io.GroupColumnIO (org.apache.parquet.io.PrimitiveColumnIO and org.apache.parquet.io.GroupColumnIO`. This commit adds support for these backwards compatible reads.
- Loading branch information
1 parent
dc73c85
commit 8ac025f
Showing
6 changed files
with
175 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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
58 changes: 58 additions & 0 deletions
58
lib/trino-parquet/src/test/java/io/trino/parquet/reader/TestColumnReaderFactory.java
This file contains 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,58 @@ | ||
/* | ||
* Licensed 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 io.trino.parquet.reader; | ||
|
||
import io.trino.parquet.PrimitiveField; | ||
import io.trino.parquet.reader.flat.FlatColumnReader; | ||
import org.apache.parquet.column.ColumnDescriptor; | ||
import org.apache.parquet.schema.PrimitiveType; | ||
import org.testng.annotations.Test; | ||
|
||
import static io.trino.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext; | ||
import static io.trino.spi.type.IntegerType.INTEGER; | ||
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT32; | ||
import static org.apache.parquet.schema.Type.Repetition.OPTIONAL; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.joda.time.DateTimeZone.UTC; | ||
|
||
public class TestColumnReaderFactory | ||
{ | ||
@Test | ||
public void testTopLevelPrimitiveFields() | ||
{ | ||
ColumnReaderFactory columnReaderFactory = new ColumnReaderFactory(UTC); | ||
PrimitiveType primitiveType = new PrimitiveType(OPTIONAL, INT32, "test"); | ||
|
||
PrimitiveField topLevelRepeatedPrimitiveField = new PrimitiveField( | ||
INTEGER, | ||
true, | ||
new ColumnDescriptor(new String[] {"topLevelRepeatedPrimitiveField test"}, primitiveType, 1, 1), | ||
0); | ||
assertThat(columnReaderFactory.create(topLevelRepeatedPrimitiveField, newSimpleAggregatedMemoryContext())).isInstanceOf(NestedColumnReader.class); | ||
|
||
PrimitiveField topLevelOptionalPrimitiveField = new PrimitiveField( | ||
INTEGER, | ||
false, | ||
new ColumnDescriptor(new String[] {"topLevelRequiredPrimitiveField test"}, primitiveType, 0, 1), | ||
0); | ||
assertThat(columnReaderFactory.create(topLevelOptionalPrimitiveField, newSimpleAggregatedMemoryContext())).isInstanceOf(FlatColumnReader.class); | ||
|
||
PrimitiveField topLevelRequiredPrimitiveField = new PrimitiveField( | ||
INTEGER, | ||
true, | ||
new ColumnDescriptor(new String[] {"topLevelRequiredPrimitiveField test"}, primitiveType, 0, 0), | ||
0); | ||
assertThat(columnReaderFactory.create(topLevelRequiredPrimitiveField, newSimpleAggregatedMemoryContext())).isInstanceOf(FlatColumnReader.class); | ||
} | ||
} |
This file contains 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
Binary file added
BIN
+389 Bytes
...in/trino-hive/src/test/resources/parquet_repeated_primitives/int/old-repeated-int.parquet
Binary file not shown.
Binary file added
BIN
+411 Bytes
...no-hive/src/test/resources/parquet_repeated_primitives/string/old-repeated-string.parquet
Binary file not shown.