JingsongLi commented on a change in pull request #17542: URL: https://github.com/apache/flink/pull/17542#discussion_r761699867
########## File path: flink-formats/flink-parquet/src/test/java/org/apache/flink/formats/parquet/row/ParquetRowDataWriterTest.java ########## @@ -158,6 +190,65 @@ private void innerTest(Configuration conf, boolean utcTimestamp) throws IOExcept Assert.assertEquals(number, cnt); } + public void complexTypeTest(Configuration conf, boolean utcTimestamp) throws Exception { + Path path = new Path(TEMPORARY_FOLDER.newFolder().getPath(), UUID.randomUUID().toString()); + int number = 1000; + List<Row> rows = new ArrayList<>(number); + Map<String, String> mapData = new HashMap<>(); + mapData.put("k1", "v1"); + mapData.put(null, "v2"); + mapData.put("k2", null); + + for (int i = 0; i < number; i++) { + Integer v = i; + rows.add(Row.of(new Integer[] {v}, mapData, Row.of(String.valueOf(v), v))); + } + + ParquetWriterFactory<RowData> factory = + ParquetRowDataBuilder.createWriterFactory(ROW_TYPE_COMPLEX, conf, utcTimestamp); + BulkWriter<RowData> writer = + factory.create(path.getFileSystem().create(path, FileSystem.WriteMode.OVERWRITE)); + for (int i = 0; i < number; i++) { + writer.addElement(CONVERTER_COMPLEX.toInternal(rows.get(i))); + } + writer.flush(); + writer.finish(); + + File file = new File(path.getPath()); + final List<Row> fileContent = readParquetFile(file); + assertEquals(rows, fileContent); + } + + private static List<Row> readParquetFile(File file) throws IOException { + InputFile inFile = + HadoopInputFile.fromPath( + new org.apache.hadoop.fs.Path(file.toURI()), new Configuration()); + + ArrayList<Row> results = new ArrayList<>(); + try (ParquetReader<GenericRecord> reader = + AvroParquetReader.<GenericRecord>builder(inFile).build()) { + GenericRecord next; + while ((next = reader.read()) != null) { + Integer c0 = (Integer) ((ArrayList<GenericData.Record>) next.get(0)).get(0).get(0); + HashMap<Utf8, Utf8> map = ((HashMap<Utf8, Utf8>) next.get(1)); + String c21 = ((GenericData.Record) next.get(2)).get(0).toString(); + Integer c22 = (Integer) ((GenericData.Record) next.get(2)).get(1); + + Map<String, String> c1 = new HashMap<>(); + for (Utf8 key : map.keySet()) { + String k = Strings.isEmpty(key) ? null : key.toString(); Review comment: I change `Strings.isEmpty(key)` to `key == null`, the tests passed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org