diff --git a/parquet-thrift/src/main/java/org/apache/parquet/thrift/struct/ThriftType.java b/parquet-thrift/src/main/java/org/apache/parquet/thrift/struct/ThriftType.java index 3d64e8dcf9..5f8afe6d0d 100644 --- a/parquet-thrift/src/main/java/org/apache/parquet/thrift/struct/ThriftType.java +++ b/parquet-thrift/src/main/java/org/apache/parquet/thrift/struct/ThriftType.java @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -6,9 +6,9 @@ * 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 @@ -230,7 +230,7 @@ public StructType(List children) { public StructType(@JsonProperty("children") List children, @JsonProperty("structOrUnionType") StructOrUnionType structOrUnionType) { super(STRUCT); - this.structOrUnionType = structOrUnionType == null ? StructOrUnionType.UNKNOWN : structOrUnionType; + this.structOrUnionType = structOrUnionType == null ? StructOrUnionType.STRUCT : structOrUnionType; this.children = children; int maxId = 0; if (children != null) { diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftSchemaConverter.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftSchemaConverter.java index cd5fc47eb4..2cde15bb1e 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftSchemaConverter.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftSchemaConverter.java @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -6,9 +6,9 @@ * 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 @@ -23,6 +23,7 @@ import org.apache.parquet.thrift.projection.StrictFieldProjectionFilter; import org.apache.parquet.thrift.projection.ThriftProjectionException; import org.apache.parquet.thrift.projection.deprecated.DeprecatedFieldProjectionFilter; +import org.apache.parquet.thrift.struct.ThriftField; import org.apache.parquet.thrift.struct.ThriftType; import org.apache.parquet.thrift.struct.ThriftType.StructType; import org.apache.parquet.thrift.test.compat.MapStructV2; @@ -34,7 +35,10 @@ import com.twitter.data.proto.tutorial.thrift.Person; import com.twitter.elephantbird.thrift.test.TestStructInMap; +import java.util.Arrays; + import static org.apache.parquet.schema.MessageTypeParser.parseMessageType; +import static org.apache.parquet.thrift.struct.ThriftField.Requirement.REQUIRED; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -288,6 +292,26 @@ public void testSetPartialProjection() { } } + @Test + public void testConvertStructCreatedViaDeprecatedConstructor() { + String expected = "message ParquetSchema {\n" + + " required binary a (UTF8) = 1;\n" + + " required binary b (UTF8) = 2;\n" + + "}\n"; + + ThriftSchemaConverter converter = new ThriftSchemaConverter(); + + StructType structType = new StructType( + Arrays.asList( + new ThriftField("a", (short) 1, REQUIRED, new ThriftType.StringType()), + new ThriftField("b", (short) 2, REQUIRED, new ThriftType.StringType()) + ) + ); + + final MessageType converted = converter.convert(structType); + assertEquals(MessageTypeParser.parseMessageType(expected), converted); + } + public static void shouldGetProjectedSchema(String deprecatedFilterDesc, String strictFilterDesc, String expectedSchemaStr, Class> thriftClass) { MessageType depRequestedSchema = getDeprecatedFilteredSchema(deprecatedFilterDesc, thriftClass); MessageType strictRequestedSchema = getStrictFilteredSchema(strictFilterDesc, thriftClass); diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/struct/TestThriftType.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/struct/TestThriftType.java index e700042904..88e8bf1f12 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/struct/TestThriftType.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/struct/TestThriftType.java @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -6,9 +6,9 @@ * 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 @@ -35,7 +35,7 @@ public void testWriteUnionInfo() throws Exception { assertEquals("{\n" +" \"id\" : \"STRUCT\",\n" +" \"children\" : [ ],\n" - +" \"structOrUnionType\" : \"UNKNOWN\"\n" + +" \"structOrUnionType\" : \"STRUCT\"\n" +"}", st.toJSON()); st = new StructType(new LinkedList(), StructOrUnionType.UNION); @@ -60,7 +60,7 @@ public void testParseUnionInfo() throws Exception { st = (StructType) StructType.fromJSON("{\"id\": \"STRUCT\", \"children\":[], \"structOrUnionType\": \"STRUCT\"}"); assertEquals(st.getStructOrUnionType(), StructOrUnionType.STRUCT); st = (StructType) StructType.fromJSON("{\"id\": \"STRUCT\", \"children\":[]}"); - assertEquals(st.getStructOrUnionType(), StructOrUnionType.UNKNOWN); + assertEquals(st.getStructOrUnionType(), StructOrUnionType.STRUCT); st = (StructType) StructType.fromJSON("{\"id\": \"STRUCT\", \"children\":[], \"structOrUnionType\": \"UNKNOWN\"}"); assertEquals(st.getStructOrUnionType(), StructOrUnionType.UNKNOWN); }