From b6e70fb4fb55784f61a07bfc6d7a1ce33ff9019b Mon Sep 17 00:00:00 2001 From: Aaron Niskode-Dossett Date: Mon, 29 Dec 2025 09:23:07 -0600 Subject: [PATCH 1/2] [parquet-thrift] move up from java 8 --- .../thrift/ThriftBytesWriteSupport.java | 4 ++-- .../parquet/thrift/TBaseRecordConverter.java | 7 ++---- .../amend/DefaultProtocolEventsGenerator.java | 2 +- .../DeprecatedFieldProjectionFilter.java | 2 +- .../thrift/struct/CompatibilityRunner.java | 11 +++++---- .../parquet/thrift/struct/ThriftType.java | 10 +++----- .../hadoop/thrift/TestArrayCompatibility.java | 13 +++++------ ...ParquetToThriftReadWriteAndProjection.java | 23 +++++++++---------- .../thrift/TestThriftToParquetFileWriter.java | 17 +++++++------- .../thrift/TestParquetReadProtocol.java | 7 +++--- .../thrift/TestParquetWriteProtocol.java | 8 +++---- .../thrift/TestProtocolReadToWrite.java | 12 +++++----- .../thrift/TestThriftParquetReaderWriter.java | 6 ++--- .../thrift/TestThriftRecordConverter.java | 4 ++-- .../thrift/TestThriftSchemaConverter.java | 4 ++-- .../thrift/projection/TestFieldsPath.java | 15 ++++-------- .../TestStrictFieldProjectionFilter.java | 6 ++--- .../parquet/thrift/struct/TestThriftType.java | 8 +++---- 18 files changed, 72 insertions(+), 87 deletions(-) diff --git a/parquet-thrift/src/main/java/org/apache/parquet/hadoop/thrift/ThriftBytesWriteSupport.java b/parquet-thrift/src/main/java/org/apache/parquet/hadoop/thrift/ThriftBytesWriteSupport.java index 0ed3f0edf6..36028f4037 100644 --- a/parquet-thrift/src/main/java/org/apache/parquet/hadoop/thrift/ThriftBytesWriteSupport.java +++ b/parquet-thrift/src/main/java/org/apache/parquet/hadoop/thrift/ThriftBytesWriteSupport.java @@ -154,8 +154,8 @@ 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); } } diff --git a/parquet-thrift/src/main/java/org/apache/parquet/thrift/TBaseRecordConverter.java b/parquet-thrift/src/main/java/org/apache/parquet/thrift/TBaseRecordConverter.java index 22c928137f..a4c3f1bf3a 100644 --- a/parquet-thrift/src/main/java/org/apache/parquet/thrift/TBaseRecordConverter.java +++ b/parquet-thrift/src/main/java/org/apache/parquet/thrift/TBaseRecordConverter.java @@ -59,14 +59,11 @@ 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); } } }, diff --git a/parquet-thrift/src/main/java/org/apache/parquet/thrift/projection/amend/DefaultProtocolEventsGenerator.java b/parquet-thrift/src/main/java/org/apache/parquet/thrift/projection/amend/DefaultProtocolEventsGenerator.java index d4db92f27f..07ccf0ab83 100644 --- a/parquet-thrift/src/main/java/org/apache/parquet/thrift/projection/amend/DefaultProtocolEventsGenerator.java +++ b/parquet-thrift/src/main/java/org/apache/parquet/thrift/projection/amend/DefaultProtocolEventsGenerator.java @@ -49,7 +49,7 @@ public void readStructEnd() throws TException {} @Override public void readFieldEnd() throws TException {} }; - List createdEvents = new ArrayList(); + List createdEvents = new ArrayList<>(); public List createProtocolEventsForField(ThriftField missingField) { TProtocol fieldBegin = new ReadFieldBeginProtocol(missingField); diff --git a/parquet-thrift/src/main/java/org/apache/parquet/thrift/projection/deprecated/DeprecatedFieldProjectionFilter.java b/parquet-thrift/src/main/java/org/apache/parquet/thrift/projection/deprecated/DeprecatedFieldProjectionFilter.java index c2c31cd120..2fdf3e7631 100644 --- a/parquet-thrift/src/main/java/org/apache/parquet/thrift/projection/deprecated/DeprecatedFieldProjectionFilter.java +++ b/parquet-thrift/src/main/java/org/apache/parquet/thrift/projection/deprecated/DeprecatedFieldProjectionFilter.java @@ -62,7 +62,7 @@ public DeprecatedFieldProjectionFilter(String filterDescStr) { filterPatterns = new LinkedList(); - if (filterDescStr == null || filterDescStr.isEmpty()) return; + if (filterDescStr.isEmpty()) return; String[] rawPatterns = filterDescStr.split(PATTERN_SEPARATOR); for (String rawPattern : rawPatterns) { diff --git a/parquet-thrift/src/main/java/org/apache/parquet/thrift/struct/CompatibilityRunner.java b/parquet-thrift/src/main/java/org/apache/parquet/thrift/struct/CompatibilityRunner.java index 73d12297b9..344d20a0e1 100644 --- a/parquet-thrift/src/main/java/org/apache/parquet/thrift/struct/CompatibilityRunner.java +++ b/parquet-thrift/src/main/java/org/apache/parquet/thrift/struct/CompatibilityRunner.java @@ -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; @@ -38,7 +39,7 @@ */ public class CompatibilityRunner { public static void main(String[] args) throws Exception { - LinkedList arguments = new LinkedList(Arrays.asList(args)); + Deque 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/ @@ -50,7 +51,7 @@ public static void main(String[] args) throws Exception { } } - private static void compareJson(LinkedList arguments) throws IOException { + private static void compareJson(Deque arguments) throws IOException { String oldJsonPath = arguments.pollFirst(); String newJsonPath = arguments.pollFirst(); @@ -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 arguments) throws ClassNotFoundException, IOException { + private static void generateJson(Deque arguments) throws ClassNotFoundException, IOException { String catName = arguments.pollFirst(); String className = arguments.pollFirst(); String storedPath = arguments.pollFirst(); 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 264790333a..d4db789c23 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 @@ -42,6 +42,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import org.apache.parquet.schema.LogicalTypeAnnotation; /** @@ -249,7 +250,7 @@ public StructType( @JsonProperty("children") List 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) { @@ -502,12 +503,7 @@ public EnumType(@JsonProperty("values") List values) { } public Iterable getValues() { - return new Iterable() { - @Override - public Iterator iterator() { - return values.iterator(); - } - }; + return List.copyOf(values); } public EnumValue getEnumValueById(int id) { diff --git a/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestArrayCompatibility.java b/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestArrayCompatibility.java index 9d14b45ed6..a4e3fb1318 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestArrayCompatibility.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestArrayCompatibility.java @@ -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; @@ -520,9 +519,9 @@ public void write(RecordConsumer rc) { }); ListOfLists expected = new ListOfLists(); - expected.addToListOfLists(Arrays.asList(34, 35, 36)); - expected.addToListOfLists(Arrays.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); @@ -581,9 +580,9 @@ public void write(RecordConsumer rc) { }); ListOfLists expected = new ListOfLists(); - expected.addToListOfLists(Arrays.asList(34, 35, 36)); - expected.addToListOfLists(Arrays.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); diff --git a/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestParquetToThriftReadWriteAndProjection.java b/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestParquetToThriftReadWriteAndProjection.java index 015f685ff9..b38d2965bb 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestParquetToThriftReadWriteAndProjection.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestParquetToThriftReadWriteAndProjection.java @@ -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; @@ -82,29 +81,29 @@ public void testThriftOptionalFieldsWithReadProjectionUsingParquetSchema() throw + " }\n" + "}"; conf.set(ReadSupport.PARQUET_READ_SCHEMA, readProjectionSchema); - TBase toWrite = new AddressBook(Arrays.asList(new Person( + TBase toWrite = new AddressBook(List.of(new Person( new Name("Bob", "Roberts"), 0, "bob.roberts@example.com", - Arrays.asList(new PhoneNumber("1234567890"))))); + 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( + TBase toWrite = new AddressBook(List.of(new Person( new Name("Bob", "Roberts"), 0, "bob.roberts@example.com", - Arrays.asList(new PhoneNumber("1234567890"))))); + 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, "bob.roberts@example.com", null))); + TBase toRead = new AddressBook(List.of(new Person(new Name("", ""), 0, "bob.roberts@example.com", null))); shouldDoProjectionWithThriftColumnFilter(projectionFilterDesc, toWrite, toRead, AddressBook.class); } @@ -124,14 +123,14 @@ public void testProjectOutOptionalFields() throws Exception { final String projectionFilterDesc = "persons/name/*"; - TBase toWrite = new AddressBook(Arrays.asList(new Person( + TBase toWrite = new AddressBook(List.of(new Person( new Name("Bob", "Roberts"), 0, "bob.roberts@example.com", - Arrays.asList(new PhoneNumber("1234567890"))))); + 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); } @@ -292,7 +291,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()); @@ -306,7 +305,7 @@ public void testPullInRequiredSets() throws Exception { String filter = "info"; RequiredSetFixture toWrite = new RequiredSetFixture(new HashSet( - 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()); diff --git a/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestThriftToParquetFileWriter.java b/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestThriftToParquetFileWriter.java index 487e9fa611..ca38f10b11 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestThriftToParquetFileWriter.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestThriftToParquetFileWriter.java @@ -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; @@ -72,11 +71,11 @@ public class TestThriftToParquetFileWriter { @Test public void testWriteFile() throws IOException, InterruptedException, TException { - final AddressBook a = new AddressBook(Arrays.asList(new Person( + final AddressBook a = new AddressBook(List.of(new Person( new Name("Bob", "Roberts"), 0, "bob.roberts@example.com", - Arrays.asList(new PhoneNumber("1234567890"))))); + List.of(new PhoneNumber("1234567890"))))); final Path fileToCreate = createFile(new Configuration(), a); @@ -215,7 +214,7 @@ public void testWriteFileListOfMap() throws IOException, InterruptedException, T map1.put("key12", "value12"); Map map2 = new HashMap(); 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); @@ -236,7 +235,7 @@ public void testWriteFileListOfMap() throws IOException, InterruptedException, T @Test public void testWriteFileMapOfList() throws IOException, InterruptedException, TException { Map> map = new HashMap>(); - 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); @@ -262,7 +261,7 @@ public void testWriteFileMapOfList() throws IOException, InterruptedException, T @Test public void testWriteFileMapOfLists() throws IOException, InterruptedException, TException { Map, List> map = new HashMap, List>(); - 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); @@ -303,11 +302,11 @@ public void testWriteFileMapOfLists() throws IOException, InterruptedException, @Test public void testWriteFileWithThreeLevelsList() throws IOException, InterruptedException, TException { - final AddressBook a = new AddressBook(Arrays.asList(new Person( + final AddressBook a = new AddressBook(List.of(new Person( new Name("Bob", "Roberts"), 0, "bob.roberts@example.com", - Arrays.asList(new PhoneNumber("1234567890"))))); + List.of(new PhoneNumber("1234567890"))))); Configuration conf = new Configuration(); conf.set(ParquetWriteProtocol.WRITE_THREE_LEVEL_LISTS, "true"); @@ -336,7 +335,7 @@ public void testWriteFileListOfMapWithThreeLevelLists() throws IOException, Inte map1.put("key12", "value12"); Map map2 = new HashMap(); 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"); diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestParquetReadProtocol.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestParquetReadProtocol.java index 100c7e996b..9c6b885275 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestParquetReadProtocol.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestParquetReadProtocol.java @@ -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; @@ -114,13 +113,13 @@ public void testOneOfEach() throws TException { public void testRead() throws Exception { final PhoneNumber phoneNumber = new PhoneNumber("5555555555"); phoneNumber.type = MOBILE; - List persons = Arrays.asList( - new Person(new Name("john", "johson"), 1, "john@johnson.org", Arrays.asList(phoneNumber)), + List persons = List.of( + new Person(new Name("john", "johson"), 1, "john@johnson.org", List.of(phoneNumber)), new Person( new Name("jack", "jackson"), 2, "jack@jackson.org", - Arrays.asList(new PhoneNumber("5555555556")))); + List.of(new PhoneNumber("5555555556")))); AddressBook expected = new AddressBook(persons); validate(expected); } diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestParquetWriteProtocol.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestParquetWriteProtocol.java index 9e562bf734..7bfe69126f 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestParquetWriteProtocol.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestParquetWriteProtocol.java @@ -435,12 +435,12 @@ public void testProtocolAddressBook() throws Exception { new Name("Bob", "Roberts"), 1, "bob@roberts.com", - 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, "dick@richardson.com", - 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. @@ -632,7 +632,7 @@ public void testListOfMapThreeLevelList() throws TException { map1.put("key12", "value12"); Map map2 = new HashMap(); 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()", @@ -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(Arrays.asList(expectations))); + new ExpectationValidatingRecordConsumer(new ArrayDeque(List.of(expectations))); final MessageColumnIO columnIO = new ColumnIOFactory().getColumnIO(schema); ParquetWriteProtocol p = new ParquetWriteProtocol( configuration, new RecordConsumerLoggingWrapper(recordConsumer), columnIO, structType); diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestProtocolReadToWrite.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestProtocolReadToWrite.java index 15059e1f1c..3e45261681 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestProtocolReadToWrite.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestProtocolReadToWrite.java @@ -34,9 +34,9 @@ import java.io.OutputStream; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import org.apache.parquet.thrift.test.Phone; @@ -99,12 +99,12 @@ public void testWriteRead() throws Exception { new Name("Bob", "Roberts"), 1, "bob@roberts.com", - 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, "dick@richardson.com", - 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); writeReadCompare(a); } @@ -125,7 +125,7 @@ public void testMapSet() throws Exception { writeReadCompare(a); } - private void writeReadCompare(TBase a) throws TException, InstantiationException, IllegalAccessException { + private void writeReadCompare(TBase a) throws TException, ReflectiveOperationException { ProtocolPipe[] pipes = { new ProtocolReadToWrite(), new BufferedProtocolReadToWrite(ThriftSchemaConverter.toStructType((Class>) a.getClass())) @@ -135,7 +135,7 @@ private void writeReadCompare(TBase a) throws TException, InstantiationExc final ByteArrayOutputStream out = new ByteArrayOutputStream(); a.write(protocol(in)); p.readOne(protocol(new ByteArrayInputStream(in.toByteArray())), protocol(out)); - TBase b = a.getClass().newInstance(); + TBase b = a.getClass().getDeclaredConstructor().newInstance(); b.read(protocol(new ByteArrayInputStream(out.toByteArray()))); assertEquals(p.getClass().getSimpleName(), a, b); @@ -381,7 +381,7 @@ public void handleFieldIgnored(TField field) { assertEquals(1, countingHandler.recordCountOfMissingFields); assertEquals(1, countingHandler.fieldIgnoredCount); - StructV4WithExtracStructField b = StructV4WithExtracStructField.class.newInstance(); + StructV4WithExtracStructField b = StructV4WithExtracStructField.class.getDeclaredConstructor().newInstance(); b.read(protocol(new ByteArrayInputStream(out.toByteArray()))); assertEquals(dataWithNewSchema.getName(), b.getName()); assertEquals(dataWithNewSchema.getAge(), b.getAge()); diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftParquetReaderWriter.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftParquetReaderWriter.java index 57eb26dd8b..5ec5037200 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftParquetReaderWriter.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftParquetReaderWriter.java @@ -23,7 +23,7 @@ import com.twitter.data.proto.tutorial.thrift.Person; import com.twitter.data.proto.tutorial.thrift.PhoneNumber; import java.io.IOException; -import java.util.Arrays; +import java.util.List; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; @@ -52,8 +52,8 @@ private void readWriteTest(Boolean useThreeLevelLists) throws IOException { fs.delete(f, true); } - AddressBook original = new AddressBook(Arrays.asList(new Person( - new Name("Bob", "Roberts"), 1, "bob@roberts.com", Arrays.asList(new PhoneNumber("5555555555"))))); + AddressBook original = new AddressBook(List.of(new Person( + new Name("Bob", "Roberts"), 1, "bob@roberts.com", List.of(new PhoneNumber("5555555555"))))); { // write ThriftParquetWriter thriftParquetWriter = diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftRecordConverter.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftRecordConverter.java index 46c2acd847..6b555b5f45 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftRecordConverter.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftRecordConverter.java @@ -25,7 +25,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; -import java.util.Arrays; +import java.util.List; import org.apache.parquet.io.ParquetDecodingException; import org.apache.parquet.io.api.Binary; import org.apache.parquet.thrift.ThriftRecordConverter.FieldEnumConverter; @@ -43,7 +43,7 @@ public class TestThriftRecordConverter { @Test public void testUnknownEnumThrowsGoodException() throws Exception { - EnumType et = new EnumType(Arrays.asList(new EnumValue(77, "hello"))); + EnumType et = new EnumType(List.of(new EnumValue(77, "hello"))); ThriftField field = new ThriftField("name", (short) 1, Requirement.REQUIRED, et); ArrayList events = new ArrayList(); 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 8f9faf160f..9f64878005 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 @@ -26,7 +26,7 @@ import com.twitter.data.proto.tutorial.thrift.AddressBook; import com.twitter.data.proto.tutorial.thrift.Person; import com.twitter.elephantbird.thrift.test.TestStructInMap; -import java.util.Arrays; +import java.util.List; import org.apache.parquet.schema.MessageType; import org.apache.parquet.schema.MessageTypeParser; import org.apache.parquet.thrift.projection.StrictFieldProjectionFilter; @@ -333,7 +333,7 @@ public void testConvertStructCreatedViaDeprecatedConstructor() { ThriftSchemaConverter converter = new ThriftSchemaConverter(); - StructType structType = new StructType(Arrays.asList( + StructType structType = new StructType(List.of( new ThriftField("a", (short) 1, REQUIRED, new ThriftType.StringType()), new ThriftField("b", (short) 2, REQUIRED, new ThriftType.StringType()))); diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestFieldsPath.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestFieldsPath.java index 2ea614b75b..f9dbbdb198 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestFieldsPath.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestFieldsPath.java @@ -23,7 +23,6 @@ import com.twitter.data.proto.tutorial.thrift.Person; import com.twitter.elephantbird.thrift.test.TestStructInMap; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.apache.parquet.thrift.ThriftSchemaConverter; import org.apache.parquet.thrift.struct.ThriftField; @@ -48,20 +47,16 @@ public void testFieldsPath() { StructType person = ThriftSchemaConverter.toStructType(Person.class); List paths = PrimitivePathVisitor.visit(person, "."); - assertEquals( - Arrays.asList("name.first_name", "name.last_name", "id", "email", "phones.number", "phones.type"), - paths); + assertEquals(List.of("name.first_name", "name.last_name", "id", "email", "phones.number", "phones.type"), paths); paths = PrimitivePathVisitor.visit(person, "/"); - assertEquals( - Arrays.asList("name/first_name", "name/last_name", "id", "email", "phones/number", "phones/type"), - paths); + assertEquals(List.of("name/first_name", "name/last_name", "id", "email", "phones/number", "phones/type"), paths); StructType structInMap = ThriftSchemaConverter.toStructType(TestStructInMap.class); paths = PrimitivePathVisitor.visit(structInMap, "."); assertEquals( - Arrays.asList( + List.of( "name", "names.key", "names.value.name.first_name", @@ -74,7 +69,7 @@ public void testFieldsPath() { paths = PrimitivePathVisitor.visit(structInMap, "/"); assertEquals( - Arrays.asList( + List.of( "name", "names/key", "names/value/name/first_name", @@ -133,7 +128,7 @@ public List visit(StructType structType, FieldsPath path) { } private List visitPrimitive(FieldsPath path) { - return Arrays.asList(path.toDelimitedString(delim)); + return List.of(path.toDelimitedString(delim)); } @Override diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestStrictFieldProjectionFilter.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestStrictFieldProjectionFilter.java index cee9e9bbd7..2175cf0dca 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestStrictFieldProjectionFilter.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestStrictFieldProjectionFilter.java @@ -24,7 +24,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import java.util.Arrays; +import java.util.List; import java.util.List; import org.junit.Test; @@ -33,7 +33,7 @@ public class TestStrictFieldProjectionFilter { @Test public void testFromSemicolonDelimitedString() { List globs = StrictFieldProjectionFilter.parseSemicolonDelimitedString(";x.y.z;*.a.b.c*;;foo;;;;bar;"); - assertEquals(Arrays.asList("x.y.z", "*.a.b.c*", "foo", "bar"), globs); + assertEquals(List.of("x.y.z", "*.a.b.c*", "foo", "bar"), globs); try { StrictFieldProjectionFilter.parseSemicolonDelimitedString(";;"); @@ -113,7 +113,7 @@ public void testIsStrict() { @Test public void testWarnWhenMultiplePatternsMatch() { StrictFieldProjectionFilter filter = createMockBuilder(StrictFieldProjectionFilter.class) - .withConstructor(Arrays.asList("a.b.c.{x_average,z_average}", "a.*_average")) + .withConstructor(List.of("a.b.c.{x_average,z_average}", "a.*_average")) .addMockedMethod("warn") .createMock(); 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 0c13ce03d6..88c99db2e6 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 @@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals; -import java.util.LinkedList; +import java.util.List; import org.apache.parquet.thrift.struct.ThriftType.StructType; import org.apache.parquet.thrift.struct.ThriftType.StructType.StructOrUnionType; import org.junit.Test; @@ -29,7 +29,7 @@ public class TestThriftType { @Test public void testWriteUnionInfo() throws Exception { - StructType st = new StructType(new LinkedList(), null); + StructType st = new StructType(List.of(), null); assertEquals( ("{\n" + " \"id\" : \"STRUCT\",\n" @@ -40,7 +40,7 @@ public void testWriteUnionInfo() throws Exception { .replace("\n", System.lineSeparator()), st.toJSON()); - st = new StructType(new LinkedList(), StructOrUnionType.UNION); + st = new StructType(List.of(), StructOrUnionType.UNION); assertEquals( ("{\n" + " \"id\" : \"STRUCT\",\n" @@ -51,7 +51,7 @@ public void testWriteUnionInfo() throws Exception { .replace("\n", System.lineSeparator()), st.toJSON()); - st = new StructType(new LinkedList(), StructOrUnionType.STRUCT); + st = new StructType(List.of(), StructOrUnionType.STRUCT); assertEquals( ("{\n" + " \"id\" : \"STRUCT\",\n" From 779d327efc55493adf2969753e176271437cd8d0 Mon Sep 17 00:00:00 2001 From: Aaron Niskode-Dossett Date: Mon, 29 Dec 2025 10:17:49 -0600 Subject: [PATCH 2/2] make spotless --- .../hadoop/thrift/ThriftBytesWriteSupport.java | 4 +++- .../parquet/thrift/TBaseRecordConverter.java | 3 ++- .../apache/parquet/thrift/struct/ThriftType.java | 1 - ...TestParquetToThriftReadWriteAndProjection.java | 15 +++------------ .../thrift/TestThriftToParquetFileWriter.java | 10 ++-------- .../parquet/thrift/TestParquetReadProtocol.java | 6 +----- .../parquet/thrift/TestProtocolReadToWrite.java | 3 ++- .../thrift/TestThriftParquetReaderWriter.java | 4 ++-- .../parquet/thrift/projection/TestFieldsPath.java | 6 ++++-- .../TestStrictFieldProjectionFilter.java | 1 - 10 files changed, 19 insertions(+), 34 deletions(-) diff --git a/parquet-thrift/src/main/java/org/apache/parquet/hadoop/thrift/ThriftBytesWriteSupport.java b/parquet-thrift/src/main/java/org/apache/parquet/hadoop/thrift/ThriftBytesWriteSupport.java index 36028f4037..790e65de5b 100644 --- a/parquet-thrift/src/main/java/org/apache/parquet/hadoop/thrift/ThriftBytesWriteSupport.java +++ b/parquet-thrift/src/main/java/org/apache/parquet/hadoop/thrift/ThriftBytesWriteSupport.java @@ -154,7 +154,9 @@ public WriteContext init(ParquetConfiguration configuration) { this.configuration = configuration; if (this.protocolFactory == null) { try { - this.protocolFactory = getTProtocolFactoryClass(configuration).getDeclaredConstructor().newInstance(); + this.protocolFactory = getTProtocolFactoryClass(configuration) + .getDeclaredConstructor() + .newInstance(); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } diff --git a/parquet-thrift/src/main/java/org/apache/parquet/thrift/TBaseRecordConverter.java b/parquet-thrift/src/main/java/org/apache/parquet/thrift/TBaseRecordConverter.java index a4c3f1bf3a..d1fb536b49 100644 --- a/parquet-thrift/src/main/java/org/apache/parquet/thrift/TBaseRecordConverter.java +++ b/parquet-thrift/src/main/java/org/apache/parquet/thrift/TBaseRecordConverter.java @@ -59,7 +59,8 @@ public TBaseRecordConverter( @Override public T readOneRecord(TProtocol protocol) throws TException { try { - T thriftObject = thriftClass.getDeclaredConstructor().newInstance(); + T thriftObject = + thriftClass.getDeclaredConstructor().newInstance(); thriftObject.read(protocol); return thriftObject; } catch (ReflectiveOperationException e) { 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 d4db789c23..6c01edb7ed 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 @@ -39,7 +39,6 @@ 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; diff --git a/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestParquetToThriftReadWriteAndProjection.java b/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestParquetToThriftReadWriteAndProjection.java index b38d2965bb..d80e7dbf1b 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestParquetToThriftReadWriteAndProjection.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestParquetToThriftReadWriteAndProjection.java @@ -82,10 +82,7 @@ public void testThriftOptionalFieldsWithReadProjectionUsingParquetSchema() throw + "}"; conf.set(ReadSupport.PARQUET_READ_SCHEMA, readProjectionSchema); TBase toWrite = new AddressBook(List.of(new Person( - new Name("Bob", "Roberts"), - 0, - "bob.roberts@example.com", - List.of(new PhoneNumber("1234567890"))))); + new Name("Bob", "Roberts"), 0, "bob.roberts@example.com", List.of(new PhoneNumber("1234567890"))))); TBase toRead = new AddressBook(List.of(new Person(new Name("Bob", "Roberts"), 0, null, null))); shouldDoProjection(conf, toWrite, toRead, AddressBook.class); @@ -95,10 +92,7 @@ public void testThriftOptionalFieldsWithReadProjectionUsingParquetSchema() throw public void testPullingInRequiredStructWithFilter() throws Exception { final String projectionFilterDesc = "persons/{id};persons/email"; TBase toWrite = new AddressBook(List.of(new Person( - new Name("Bob", "Roberts"), - 0, - "bob.roberts@example.com", - List.of(new PhoneNumber("1234567890"))))); + new Name("Bob", "Roberts"), 0, "bob.roberts@example.com", 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 @@ -124,10 +118,7 @@ public void testProjectOutOptionalFields() throws Exception { final String projectionFilterDesc = "persons/name/*"; TBase toWrite = new AddressBook(List.of(new Person( - new Name("Bob", "Roberts"), - 0, - "bob.roberts@example.com", - List.of(new PhoneNumber("1234567890"))))); + new Name("Bob", "Roberts"), 0, "bob.roberts@example.com", List.of(new PhoneNumber("1234567890"))))); // emails and phones are optional fields that do not match the projection filter TBase toRead = new AddressBook(List.of(new Person(new Name("Bob", "Roberts"), 0, null, null))); diff --git a/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestThriftToParquetFileWriter.java b/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestThriftToParquetFileWriter.java index ca38f10b11..82b41f1b69 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestThriftToParquetFileWriter.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestThriftToParquetFileWriter.java @@ -72,10 +72,7 @@ public class TestThriftToParquetFileWriter { @Test public void testWriteFile() throws IOException, InterruptedException, TException { final AddressBook a = new AddressBook(List.of(new Person( - new Name("Bob", "Roberts"), - 0, - "bob.roberts@example.com", - List.of(new PhoneNumber("1234567890"))))); + new Name("Bob", "Roberts"), 0, "bob.roberts@example.com", List.of(new PhoneNumber("1234567890"))))); final Path fileToCreate = createFile(new Configuration(), a); @@ -303,10 +300,7 @@ public void testWriteFileMapOfLists() throws IOException, InterruptedException, @Test public void testWriteFileWithThreeLevelsList() throws IOException, InterruptedException, TException { final AddressBook a = new AddressBook(List.of(new Person( - new Name("Bob", "Roberts"), - 0, - "bob.roberts@example.com", - List.of(new PhoneNumber("1234567890"))))); + new Name("Bob", "Roberts"), 0, "bob.roberts@example.com", List.of(new PhoneNumber("1234567890"))))); Configuration conf = new Configuration(); conf.set(ParquetWriteProtocol.WRITE_THREE_LEVEL_LISTS, "true"); diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestParquetReadProtocol.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestParquetReadProtocol.java index 9c6b885275..f9c84da062 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestParquetReadProtocol.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestParquetReadProtocol.java @@ -115,11 +115,7 @@ public void testRead() throws Exception { phoneNumber.type = MOBILE; List persons = List.of( new Person(new Name("john", "johson"), 1, "john@johnson.org", List.of(phoneNumber)), - new Person( - new Name("jack", "jackson"), - 2, - "jack@jackson.org", - List.of(new PhoneNumber("5555555556")))); + new Person(new Name("jack", "jackson"), 2, "jack@jackson.org", List.of(new PhoneNumber("5555555556")))); AddressBook expected = new AddressBook(persons); validate(expected); } diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestProtocolReadToWrite.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestProtocolReadToWrite.java index 3e45261681..b683142c64 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestProtocolReadToWrite.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestProtocolReadToWrite.java @@ -381,7 +381,8 @@ public void handleFieldIgnored(TField field) { assertEquals(1, countingHandler.recordCountOfMissingFields); assertEquals(1, countingHandler.fieldIgnoredCount); - StructV4WithExtracStructField b = StructV4WithExtracStructField.class.getDeclaredConstructor().newInstance(); + StructV4WithExtracStructField b = + StructV4WithExtracStructField.class.getDeclaredConstructor().newInstance(); b.read(protocol(new ByteArrayInputStream(out.toByteArray()))); assertEquals(dataWithNewSchema.getName(), b.getName()); assertEquals(dataWithNewSchema.getAge(), b.getAge()); diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftParquetReaderWriter.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftParquetReaderWriter.java index 5ec5037200..68fcbad40e 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftParquetReaderWriter.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/TestThriftParquetReaderWriter.java @@ -52,8 +52,8 @@ private void readWriteTest(Boolean useThreeLevelLists) throws IOException { fs.delete(f, true); } - AddressBook original = new AddressBook(List.of(new Person( - new Name("Bob", "Roberts"), 1, "bob@roberts.com", List.of(new PhoneNumber("5555555555"))))); + AddressBook original = new AddressBook(List.of( + new Person(new Name("Bob", "Roberts"), 1, "bob@roberts.com", List.of(new PhoneNumber("5555555555"))))); { // write ThriftParquetWriter thriftParquetWriter = diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestFieldsPath.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestFieldsPath.java index f9dbbdb198..eedd1e2941 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestFieldsPath.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestFieldsPath.java @@ -47,10 +47,12 @@ public void testFieldsPath() { StructType person = ThriftSchemaConverter.toStructType(Person.class); List paths = PrimitivePathVisitor.visit(person, "."); - assertEquals(List.of("name.first_name", "name.last_name", "id", "email", "phones.number", "phones.type"), paths); + assertEquals( + List.of("name.first_name", "name.last_name", "id", "email", "phones.number", "phones.type"), paths); paths = PrimitivePathVisitor.visit(person, "/"); - assertEquals(List.of("name/first_name", "name/last_name", "id", "email", "phones/number", "phones/type"), paths); + assertEquals( + List.of("name/first_name", "name/last_name", "id", "email", "phones/number", "phones/type"), paths); StructType structInMap = ThriftSchemaConverter.toStructType(TestStructInMap.class); diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestStrictFieldProjectionFilter.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestStrictFieldProjectionFilter.java index 2175cf0dca..cb4ecc9ff2 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestStrictFieldProjectionFilter.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestStrictFieldProjectionFilter.java @@ -24,7 +24,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import java.util.List; import java.util.List; import org.junit.Test;