Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
/*
* 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
Expand Down Expand Up @@ -230,7 +230,7 @@ public StructType(List<ThriftField> children) {
public StructType(@JsonProperty("children") List<ThriftField> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
/*
* 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
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<? extends TBase<?,?>> thriftClass) {
MessageType depRequestedSchema = getDeprecatedFilteredSchema(deprecatedFilterDesc, thriftClass);
MessageType strictRequestedSchema = getStrictFilteredSchema(strictFilterDesc, thriftClass);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
/*
* 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
Expand All @@ -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<ThriftField>(), StructOrUnionType.UNION);
Expand All @@ -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);
}
Expand Down