Skip to content

Commit af4576a

Browse files
committed
Update variant spec version and add test
1 parent a683f6a commit af4576a

File tree

4 files changed

+110
-4
lines changed

4 files changed

+110
-4
lines changed

parquet-column/src/test/java/org/apache/parquet/schema/TestTypeBuilders.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,76 @@ public void testVariantLogicalType() {
14351435
assertEquals(variantExpected, variantActual);
14361436
}
14371437

1438+
@Test
1439+
public void testShreddedVariantLogicalType() {
1440+
String name = "variant_field";
1441+
1442+
List<Type> eventTypeFields = new ArrayList<>();
1443+
eventTypeFields.add(new PrimitiveType(OPTIONAL, BINARY, "value"));
1444+
eventTypeFields.add(new PrimitiveType(OPTIONAL, BINARY, "typed_value", LogicalTypeAnnotation.stringType()));
1445+
1446+
List<Type> elementFields = new ArrayList<>();
1447+
elementFields.add(new PrimitiveType(OPTIONAL, BINARY, "value"));
1448+
elementFields.add(new PrimitiveType(OPTIONAL, BINARY, "typed_value", LogicalTypeAnnotation.stringType()));
1449+
1450+
new GroupType(REPEATED, "list", new GroupType(REQUIRED, "element", elementFields));
1451+
1452+
List<Type> tagsFields = new ArrayList<>();
1453+
tagsFields.add(new PrimitiveType(OPTIONAL, BINARY, "value"));
1454+
tagsFields.add(new GroupType(
1455+
OPTIONAL,
1456+
"typed_value",
1457+
LogicalTypeAnnotation.listType(),
1458+
new GroupType(REPEATED, "list", new GroupType(REQUIRED, "element", elementFields))));
1459+
1460+
List<Type> typedTypeFields = new ArrayList<>();
1461+
typedTypeFields.add(new GroupType(REQUIRED, "event_type", eventTypeFields));
1462+
typedTypeFields.add(new GroupType(REQUIRED, "tags", tagsFields));
1463+
1464+
GroupType variantExpected = new GroupType(
1465+
REQUIRED,
1466+
name,
1467+
LogicalTypeAnnotation.variantType(),
1468+
new PrimitiveType(REQUIRED, BINARY, "metadata"),
1469+
new PrimitiveType(OPTIONAL, BINARY, "value"),
1470+
new GroupType(OPTIONAL, "typed_value", typedTypeFields));
1471+
1472+
GroupType variantActual = Types.buildGroup(REQUIRED)
1473+
.addFields(
1474+
Types.required(BINARY).named("metadata"),
1475+
Types.optional(BINARY).named("value"),
1476+
Types.buildGroup(OPTIONAL)
1477+
.addFields(
1478+
Types.buildGroup(REQUIRED)
1479+
.addFields(
1480+
Types.optional(BINARY).named("value"),
1481+
Types.optional(BINARY)
1482+
.as(LogicalTypeAnnotation.stringType())
1483+
.named("typed_value"))
1484+
.named("event_type"),
1485+
Types.buildGroup(REQUIRED)
1486+
.addFields(
1487+
Types.optional(BINARY).named("value"),
1488+
Types.optionalList()
1489+
.element(Types.buildGroup(REQUIRED)
1490+
.addFields(
1491+
Types.optional(BINARY)
1492+
.named("value"),
1493+
Types.optional(BINARY)
1494+
.as(
1495+
LogicalTypeAnnotation
1496+
.stringType())
1497+
.named("typed_value"))
1498+
.named("element"))
1499+
.named("typed_value"))
1500+
.named("tags"))
1501+
.named("typed_value"))
1502+
.as(LogicalTypeAnnotation.variantType())
1503+
.named(name);
1504+
1505+
assertEquals(variantExpected, variantActual);
1506+
}
1507+
14381508
@Test(expected = IllegalArgumentException.class)
14391509
public void testDecimalLogicalTypeWithDeprecatedScaleMismatch() {
14401510
Types.required(BINARY)

parquet-format-structures/src/main/java/org/apache/parquet/format/LogicalTypes.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,10 @@ public static LogicalType DECIMAL(int scale, int precision) {
5353
public static final LogicalType JSON = LogicalType.JSON(new JsonType());
5454
public static final LogicalType BSON = LogicalType.BSON(new BsonType());
5555
public static final LogicalType FLOAT16 = LogicalType.FLOAT16(new Float16Type());
56-
public static final LogicalType VARIANT = LogicalType.VARIANT(new VariantType());
56+
57+
public static final LogicalType VARIANT() {
58+
VariantType type = new VariantType();
59+
type.setSpecification_version((byte) 1);
60+
return LogicalType.VARIANT(type);
61+
}
5762
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.parquet.format;
20+
21+
import static org.junit.Assert.assertEquals;
22+
23+
import org.junit.Test;
24+
25+
public class TestLogicalTypes {
26+
@Test
27+
public void testVariantLogicalTypeVersion() {
28+
LogicalType variant = LogicalTypes.VARIANT();
29+
assertEquals(1, (variant.getVARIANT().getSpecification_version()));
30+
}
31+
}

parquet-hadoop/src/main/java/org/apache/parquet/format/converter/ParquetMetadataConverter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import org.apache.parquet.format.KeyValue;
9090
import org.apache.parquet.format.ListType;
9191
import org.apache.parquet.format.LogicalType;
92+
import org.apache.parquet.format.LogicalTypes;
9293
import org.apache.parquet.format.MapType;
9394
import org.apache.parquet.format.MicroSeconds;
9495
import org.apache.parquet.format.MilliSeconds;
@@ -112,7 +113,6 @@
112113
import org.apache.parquet.format.TypeDefinedOrder;
113114
import org.apache.parquet.format.UUIDType;
114115
import org.apache.parquet.format.Uncompressed;
115-
import org.apache.parquet.format.VariantType;
116116
import org.apache.parquet.format.XxHash;
117117
import org.apache.parquet.hadoop.metadata.BlockMetaData;
118118
import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
@@ -517,7 +517,7 @@ public Optional<LogicalType> visit(LogicalTypeAnnotation.Float16LogicalTypeAnnot
517517
}
518518

519519
@Override
520-
public Optional<LogicalType> visit(LogicalTypeAnnotation.UnknownLogicalTypeAnnotation unknownLogicalType) {
520+
public Optional<LogicalType> visit(LogicalTypeAnnotation.UnknownLogicalTypeAnnotation intervalLogicalType) {
521521
return of(LogicalType.UNKNOWN(new NullType()));
522522
}
523523

@@ -528,7 +528,7 @@ public Optional<LogicalType> visit(LogicalTypeAnnotation.IntervalLogicalTypeAnno
528528

529529
@Override
530530
public Optional<LogicalType> visit(LogicalTypeAnnotation.VariantLogicalTypeAnnotation variantLogicalType) {
531-
return of(LogicalType.VARIANT(new VariantType()));
531+
return of(LogicalTypes.VARIANT());
532532
}
533533
}
534534

0 commit comments

Comments
 (0)