Skip to content

Commit b6fd45e

Browse files
nandorKollargszadovszky
authored andcommitted
PARQUET-1305: Backward incompatible change introduced in 1.8 (#483)
1 parent 1e0760a commit b6fd45e

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

parquet-thrift/src/main/java/org/apache/parquet/thrift/struct/ThriftType.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
/*
1+
/*
22
* Licensed to the Apache Software Foundation (ASF) under one
33
* or more contributor license agreements. See the NOTICE file
44
* distributed with this work for additional information
55
* regarding copyright ownership. The ASF licenses this file
66
* to you under the Apache License, Version 2.0 (the
77
* "License"); you may not use this file except in compliance
88
* with the License. You may obtain a copy of the License at
9-
*
9+
*
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
*
1212
* Unless required by applicable law or agreed to in writing,
1313
* software distributed under the License is distributed on an
1414
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -230,7 +230,7 @@ public StructType(List<ThriftField> children) {
230230
public StructType(@JsonProperty("children") List<ThriftField> children,
231231
@JsonProperty("structOrUnionType") StructOrUnionType structOrUnionType) {
232232
super(STRUCT);
233-
this.structOrUnionType = structOrUnionType == null ? StructOrUnionType.UNKNOWN : structOrUnionType;
233+
this.structOrUnionType = structOrUnionType == null ? StructOrUnionType.STRUCT : structOrUnionType;
234234
this.children = children;
235235
int maxId = 0;
236236
if (children != null) {

parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftSchemaConverter.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
/*
1+
/*
22
* Licensed to the Apache Software Foundation (ASF) under one
33
* or more contributor license agreements. See the NOTICE file
44
* distributed with this work for additional information
55
* regarding copyright ownership. The ASF licenses this file
66
* to you under the Apache License, Version 2.0 (the
77
* "License"); you may not use this file except in compliance
88
* with the License. You may obtain a copy of the License at
9-
*
9+
*
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
*
1212
* Unless required by applicable law or agreed to in writing,
1313
* software distributed under the License is distributed on an
1414
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -23,6 +23,7 @@
2323
import org.apache.parquet.thrift.projection.StrictFieldProjectionFilter;
2424
import org.apache.parquet.thrift.projection.ThriftProjectionException;
2525
import org.apache.parquet.thrift.projection.deprecated.DeprecatedFieldProjectionFilter;
26+
import org.apache.parquet.thrift.struct.ThriftField;
2627
import org.apache.parquet.thrift.struct.ThriftType;
2728
import org.apache.parquet.thrift.struct.ThriftType.StructType;
2829
import org.apache.parquet.thrift.test.compat.MapStructV2;
@@ -34,7 +35,10 @@
3435
import com.twitter.data.proto.tutorial.thrift.Person;
3536
import com.twitter.elephantbird.thrift.test.TestStructInMap;
3637

38+
import java.util.Arrays;
39+
3740
import static org.apache.parquet.schema.MessageTypeParser.parseMessageType;
41+
import static org.apache.parquet.thrift.struct.ThriftField.Requirement.REQUIRED;
3842
import static org.junit.Assert.assertEquals;
3943
import static org.junit.Assert.fail;
4044

@@ -288,6 +292,26 @@ public void testSetPartialProjection() {
288292
}
289293
}
290294

295+
@Test
296+
public void testConvertStructCreatedViaDeprecatedConstructor() {
297+
String expected = "message ParquetSchema {\n" +
298+
" required binary a (UTF8) = 1;\n" +
299+
" required binary b (UTF8) = 2;\n" +
300+
"}\n";
301+
302+
ThriftSchemaConverter converter = new ThriftSchemaConverter();
303+
304+
StructType structType = new StructType(
305+
Arrays.asList(
306+
new ThriftField("a", (short) 1, REQUIRED, new ThriftType.StringType()),
307+
new ThriftField("b", (short) 2, REQUIRED, new ThriftType.StringType())
308+
)
309+
);
310+
311+
final MessageType converted = converter.convert(structType);
312+
assertEquals(MessageTypeParser.parseMessageType(expected), converted);
313+
}
314+
291315
public static void shouldGetProjectedSchema(String deprecatedFilterDesc, String strictFilterDesc, String expectedSchemaStr, Class<? extends TBase<?,?>> thriftClass) {
292316
MessageType depRequestedSchema = getDeprecatedFilteredSchema(deprecatedFilterDesc, thriftClass);
293317
MessageType strictRequestedSchema = getStrictFilteredSchema(strictFilterDesc, thriftClass);

parquet-thrift/src/test/java/org/apache/parquet/thrift/struct/TestThriftType.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
/*
1+
/*
22
* Licensed to the Apache Software Foundation (ASF) under one
33
* or more contributor license agreements. See the NOTICE file
44
* distributed with this work for additional information
55
* regarding copyright ownership. The ASF licenses this file
66
* to you under the Apache License, Version 2.0 (the
77
* "License"); you may not use this file except in compliance
88
* with the License. You may obtain a copy of the License at
9-
*
9+
*
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
*
1212
* Unless required by applicable law or agreed to in writing,
1313
* software distributed under the License is distributed on an
1414
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -35,7 +35,7 @@ public void testWriteUnionInfo() throws Exception {
3535
assertEquals("{\n"
3636
+" \"id\" : \"STRUCT\",\n"
3737
+" \"children\" : [ ],\n"
38-
+" \"structOrUnionType\" : \"UNKNOWN\"\n"
38+
+" \"structOrUnionType\" : \"STRUCT\"\n"
3939
+"}", st.toJSON());
4040

4141
st = new StructType(new LinkedList<ThriftField>(), StructOrUnionType.UNION);
@@ -60,7 +60,7 @@ public void testParseUnionInfo() throws Exception {
6060
st = (StructType) StructType.fromJSON("{\"id\": \"STRUCT\", \"children\":[], \"structOrUnionType\": \"STRUCT\"}");
6161
assertEquals(st.getStructOrUnionType(), StructOrUnionType.STRUCT);
6262
st = (StructType) StructType.fromJSON("{\"id\": \"STRUCT\", \"children\":[]}");
63-
assertEquals(st.getStructOrUnionType(), StructOrUnionType.UNKNOWN);
63+
assertEquals(st.getStructOrUnionType(), StructOrUnionType.STRUCT);
6464
st = (StructType) StructType.fromJSON("{\"id\": \"STRUCT\", \"children\":[], \"structOrUnionType\": \"UNKNOWN\"}");
6565
assertEquals(st.getStructOrUnionType(), StructOrUnionType.UNKNOWN);
6666
}

0 commit comments

Comments
 (0)