Skip to content
Open
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
Expand Up @@ -154,8 +154,10 @@ public WriteContext init(ParquetConfiguration configuration) {
this.configuration = configuration;
if (this.protocolFactory == null) {
try {
this.protocolFactory = getTProtocolFactoryClass(configuration).newInstance();
} catch (InstantiationException | IllegalAccessException e) {
this.protocolFactory = getTProtocolFactoryClass(configuration)
.getDeclaredConstructor()
.newInstance();
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ public TBaseRecordConverter(
@Override
public T readOneRecord(TProtocol protocol) throws TException {
try {
T thriftObject = thriftClass.newInstance();
T thriftObject =
thriftClass.getDeclaredConstructor().newInstance();
thriftObject.read(protocol);
return thriftObject;
} catch (InstantiationException e) {
} catch (ReflectiveOperationException e) {
throw new ParquetDecodingException("Could not instantiate Thrift " + thriftClass, e);
} catch (IllegalAccessException e) {
throw new ParquetDecodingException(
"Thrift class or constructor not public " + thriftClass, e);
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void readStructEnd() throws TException {}
@Override
public void readFieldEnd() throws TException {}
};
List createdEvents = new ArrayList<TProtocol>();
List<TProtocol> createdEvents = new ArrayList<>();

public List<TProtocol> createProtocolEventsForField(ThriftField missingField) {
TProtocol fieldBegin = new ReadFieldBeginProtocol(missingField);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public DeprecatedFieldProjectionFilter(String filterDescStr) {

filterPatterns = new LinkedList<PathGlobPatternStatus>();

if (filterDescStr == null || filterDescStr.isEmpty()) return;
if (filterDescStr.isEmpty()) return;

String[] rawPatterns = filterDescStr.split(PATTERN_SEPARATOR);
for (String rawPattern : rawPatterns) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;
import org.apache.parquet.thrift.ThriftSchemaConverter;
import org.apache.thrift.TBase;

Expand All @@ -38,7 +39,7 @@
*/
public class CompatibilityRunner {
public static void main(String[] args) throws Exception {
LinkedList<String> arguments = new LinkedList<String>(Arrays.asList(args));
Deque<String> arguments = new ArrayDeque<>(List.of(args));
String operator = arguments.pollFirst();
if (operator.equals("generate-json")) {
// java CompatibilityRunner generate-json tfe_request com.twitter.logs.TfeRequestLog old_json/
Expand All @@ -50,7 +51,7 @@ public static void main(String[] args) throws Exception {
}
}

private static void compareJson(LinkedList<String> arguments) throws IOException {
private static void compareJson(Deque<String> arguments) throws IOException {
String oldJsonPath = arguments.pollFirst();
String newJsonPath = arguments.pollFirst();

Expand Down Expand Up @@ -83,7 +84,7 @@ private static void checkExist(File f) {
if (!f.exists()) throw new RuntimeException("can not find file " + f);
}

private static void generateJson(LinkedList<String> arguments) throws ClassNotFoundException, IOException {
private static void generateJson(Deque<String> arguments) throws ClassNotFoundException, IOException {
String catName = arguments.pollFirst();
String className = arguments.pollFirst();
String storedPath = arguments.pollFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.parquet.schema.LogicalTypeAnnotation;

/**
Expand Down Expand Up @@ -249,7 +249,7 @@ public StructType(
@JsonProperty("children") List<ThriftField> children,
@JsonProperty("structOrUnionType") StructOrUnionType structOrUnionType) {
super(STRUCT);
this.structOrUnionType = structOrUnionType == null ? StructOrUnionType.STRUCT : structOrUnionType;
this.structOrUnionType = Objects.requireNonNullElse(structOrUnionType, StructOrUnionType.STRUCT);
this.children = children;
int maxId = 0;
if (children != null) {
Expand Down Expand Up @@ -502,12 +502,7 @@ public EnumType(@JsonProperty("values") List<EnumValue> values) {
}

public Iterable<EnumValue> getValues() {
return new Iterable<EnumValue>() {
@Override
public Iterator<EnumValue> iterator() {
return values.iterator();
}
};
return List.copyOf(values);
}

public EnumValue getEnumValueById(int id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import com.google.common.collect.Lists;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
Expand Down Expand Up @@ -520,9 +519,9 @@ public void write(RecordConsumer rc) {
});

ListOfLists expected = new ListOfLists();
expected.addToListOfLists(Arrays.asList(34, 35, 36));
expected.addToListOfLists(Arrays.<Integer>asList());
expected.addToListOfLists(Arrays.asList(32, 33, 34));
expected.addToListOfLists(List.of(34, 35, 36));
expected.addToListOfLists(List.of());
expected.addToListOfLists(List.of(32, 33, 34));

// should detect the "array" name
assertReaderContains(reader(test, ListOfLists.class), expected);
Expand Down Expand Up @@ -581,9 +580,9 @@ public void write(RecordConsumer rc) {
});

ListOfLists expected = new ListOfLists();
expected.addToListOfLists(Arrays.asList(34, 35, 36));
expected.addToListOfLists(Arrays.<Integer>asList());
expected.addToListOfLists(Arrays.asList(32, 33, 34));
expected.addToListOfLists(List.of(34, 35, 36));
expected.addToListOfLists(List.of());
expected.addToListOfLists(List.of(32, 33, 34));

// should detect the "_tuple" names
assertReaderContains(reader(test, ListOfLists.class), expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.twitter.data.proto.tutorial.thrift.PhoneNumber;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -82,29 +81,23 @@ public void testThriftOptionalFieldsWithReadProjectionUsingParquetSchema() throw
+ " }\n"
+ "}";
conf.set(ReadSupport.PARQUET_READ_SCHEMA, readProjectionSchema);
TBase toWrite = new AddressBook(Arrays.asList(new Person(
new Name("Bob", "Roberts"),
0,
"[email protected]",
Arrays.asList(new PhoneNumber("1234567890")))));
TBase toWrite = new AddressBook(List.of(new Person(
new Name("Bob", "Roberts"), 0, "[email protected]", List.of(new PhoneNumber("1234567890")))));

TBase toRead = new AddressBook(Arrays.asList(new Person(new Name("Bob", "Roberts"), 0, null, null)));
TBase toRead = new AddressBook(List.of(new Person(new Name("Bob", "Roberts"), 0, null, null)));
shouldDoProjection(conf, toWrite, toRead, AddressBook.class);
}

@Test
public void testPullingInRequiredStructWithFilter() throws Exception {
final String projectionFilterDesc = "persons/{id};persons/email";
TBase toWrite = new AddressBook(Arrays.asList(new Person(
new Name("Bob", "Roberts"),
0,
"[email protected]",
Arrays.asList(new PhoneNumber("1234567890")))));
TBase toWrite = new AddressBook(List.of(new Person(
new Name("Bob", "Roberts"), 0, "[email protected]", List.of(new PhoneNumber("1234567890")))));

// Name is a required field, but is projected out. To make the thrift record pass validation, the name field is
// filled
// with empty string
TBase toRead = new AddressBook(Arrays.asList(new Person(new Name("", ""), 0, "[email protected]", null)));
TBase toRead = new AddressBook(List.of(new Person(new Name("", ""), 0, "[email protected]", null)));
shouldDoProjectionWithThriftColumnFilter(projectionFilterDesc, toWrite, toRead, AddressBook.class);
}

Expand All @@ -124,14 +117,11 @@ public void testProjectOutOptionalFields() throws Exception {

final String projectionFilterDesc = "persons/name/*";

TBase toWrite = new AddressBook(Arrays.asList(new Person(
new Name("Bob", "Roberts"),
0,
"[email protected]",
Arrays.asList(new PhoneNumber("1234567890")))));
TBase toWrite = new AddressBook(List.of(new Person(
new Name("Bob", "Roberts"), 0, "[email protected]", List.of(new PhoneNumber("1234567890")))));

// emails and phones are optional fields that do not match the projection filter
TBase toRead = new AddressBook(Arrays.asList(new Person(new Name("Bob", "Roberts"), 0, null, null)));
TBase toRead = new AddressBook(List.of(new Person(new Name("Bob", "Roberts"), 0, null, null)));

shouldDoProjectionWithThriftColumnFilter(projectionFilterDesc, toWrite, toRead, AddressBook.class);
}
Expand Down Expand Up @@ -292,7 +282,7 @@ public void testPullInRequiredLists() throws Exception {
String filter = "info";

RequiredListFixture toWrite =
new RequiredListFixture(Arrays.asList(new org.apache.parquet.thrift.test.Name("first_name")));
new RequiredListFixture(List.of(new org.apache.parquet.thrift.test.Name("first_name")));
toWrite.setInfo("test_info");

RequiredListFixture toRead = new RequiredListFixture(new ArrayList<org.apache.parquet.thrift.test.Name>());
Expand All @@ -306,7 +296,7 @@ public void testPullInRequiredSets() throws Exception {
String filter = "info";

RequiredSetFixture toWrite = new RequiredSetFixture(new HashSet<org.apache.parquet.thrift.test.Name>(
Arrays.asList(new org.apache.parquet.thrift.test.Name("first_name"))));
List.of(new org.apache.parquet.thrift.test.Name("first_name"))));
toWrite.setInfo("test_info");

RequiredSetFixture toRead = new RequiredSetFixture(new HashSet<org.apache.parquet.thrift.test.Name>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.twitter.elephantbird.thrift.test.TestMapInList;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -72,11 +71,8 @@ public class TestThriftToParquetFileWriter {

@Test
public void testWriteFile() throws IOException, InterruptedException, TException {
final AddressBook a = new AddressBook(Arrays.asList(new Person(
new Name("Bob", "Roberts"),
0,
"[email protected]",
Arrays.asList(new PhoneNumber("1234567890")))));
final AddressBook a = new AddressBook(List.of(new Person(
new Name("Bob", "Roberts"), 0, "[email protected]", List.of(new PhoneNumber("1234567890")))));

final Path fileToCreate = createFile(new Configuration(), a);

Expand Down Expand Up @@ -215,7 +211,7 @@ public void testWriteFileListOfMap() throws IOException, InterruptedException, T
map1.put("key12", "value12");
Map<String, String> map2 = new HashMap<String, String>();
map2.put("key21", "value21");
final TestMapInList listMap = new TestMapInList("listmap", Arrays.asList(map1, map2));
final TestMapInList listMap = new TestMapInList("listmap", List.of(map1, map2));

final Path fileToCreate = createFile(new Configuration(), listMap);

Expand All @@ -236,7 +232,7 @@ public void testWriteFileListOfMap() throws IOException, InterruptedException, T
@Test
public void testWriteFileMapOfList() throws IOException, InterruptedException, TException {
Map<String, List<String>> map = new HashMap<String, List<String>>();
map.put("key", Arrays.asList("val1", "val2"));
map.put("key", List.of("val1", "val2"));
final TestListInMap mapList = new TestListInMap("maplist", map);
final Path fileToCreate = createFile(new Configuration(), mapList);

Expand All @@ -262,7 +258,7 @@ public void testWriteFileMapOfList() throws IOException, InterruptedException, T
@Test
public void testWriteFileMapOfLists() throws IOException, InterruptedException, TException {
Map<List<String>, List<String>> map = new HashMap<List<String>, List<String>>();
map.put(Arrays.asList("key1", "key2"), Arrays.asList("val1", "val2"));
map.put(List.of("key1", "key2"), List.of("val1", "val2"));
final TestListsInMap mapList = new TestListsInMap("maplists", map);
final Path fileToCreate = createFile(new Configuration(), mapList);

Expand Down Expand Up @@ -303,11 +299,8 @@ public void testWriteFileMapOfLists() throws IOException, InterruptedException,

@Test
public void testWriteFileWithThreeLevelsList() throws IOException, InterruptedException, TException {
final AddressBook a = new AddressBook(Arrays.asList(new Person(
new Name("Bob", "Roberts"),
0,
"[email protected]",
Arrays.asList(new PhoneNumber("1234567890")))));
final AddressBook a = new AddressBook(List.of(new Person(
new Name("Bob", "Roberts"), 0, "[email protected]", List.of(new PhoneNumber("1234567890")))));

Configuration conf = new Configuration();
conf.set(ParquetWriteProtocol.WRITE_THREE_LEVEL_LISTS, "true");
Expand Down Expand Up @@ -336,7 +329,7 @@ public void testWriteFileListOfMapWithThreeLevelLists() throws IOException, Inte
map1.put("key12", "value12");
Map<String, String> map2 = new HashMap<String, String>();
map2.put("key21", "value21");
final TestMapInList listMap = new TestMapInList("listmap", Arrays.asList(map1, map2));
final TestMapInList listMap = new TestMapInList("listmap", List.of(map1, map2));

Configuration conf = new Configuration();
conf.set(ParquetWriteProtocol.WRITE_THREE_LEVEL_LISTS, "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.twitter.elephantbird.thrift.test.TestStructInMap;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -114,13 +113,9 @@ public void testOneOfEach() throws TException {
public void testRead() throws Exception {
final PhoneNumber phoneNumber = new PhoneNumber("5555555555");
phoneNumber.type = MOBILE;
List<Person> persons = Arrays.asList(
new Person(new Name("john", "johson"), 1, "[email protected]", Arrays.asList(phoneNumber)),
new Person(
new Name("jack", "jackson"),
2,
"[email protected]",
Arrays.asList(new PhoneNumber("5555555556"))));
List<Person> persons = List.of(
new Person(new Name("john", "johson"), 1, "[email protected]", List.of(phoneNumber)),
new Person(new Name("jack", "jackson"), 2, "[email protected]", List.of(new PhoneNumber("5555555556"))));
AddressBook expected = new AddressBook(persons);
validate(expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,12 @@ public void testProtocolAddressBook() throws Exception {
new Name("Bob", "Roberts"),
1,
"[email protected]",
Arrays.asList(new PhoneNumber("555 999 9999"), phoneNumber)));
List.of(new PhoneNumber("555 999 9999"), phoneNumber)));
persons.add(new Person(
new Name("Dick", "Richardson"),
2,
"[email protected]",
Arrays.asList(new PhoneNumber("555 999 9997"), new PhoneNumber("555 999 9996"))));
List.of(new PhoneNumber("555 999 9997"), new PhoneNumber("555 999 9996"))));
AddressBook a = new AddressBook(persons);
validatePig(expectations, a);
// naming conventions are slightly different for the bag inner tuple. The reader should ignore this.
Expand Down Expand Up @@ -632,7 +632,7 @@ public void testListOfMapThreeLevelList() throws TException {
map1.put("key12", "value12");
Map<String, String> map2 = new HashMap<String, String>();
map2.put("key21", "value21");
final TestMapInList listMap = new TestMapInList("listmap", Arrays.asList(map1, map2));
final TestMapInList listMap = new TestMapInList("listmap", List.of(map1, map2));

String[] expectations = {
"startMessage()",
Expand Down Expand Up @@ -703,7 +703,7 @@ private void validateThrift(Configuration configuration, String[] expectations,
LOG.info("{}", schema);
final StructType structType = thriftSchemaConverter.toStructType(class1);
ExpectationValidatingRecordConsumer recordConsumer =
new ExpectationValidatingRecordConsumer(new ArrayDeque<String>(Arrays.asList(expectations)));
new ExpectationValidatingRecordConsumer(new ArrayDeque<String>(List.of(expectations)));
final MessageColumnIO columnIO = new ColumnIOFactory().getColumnIO(schema);
ParquetWriteProtocol p = new ParquetWriteProtocol(
configuration, new RecordConsumerLoggingWrapper(recordConsumer), columnIO, structType);
Expand Down
Loading