pvary commented on code in PR #8808: URL: https://github.com/apache/iceberg/pull/8808#discussion_r1361742942
########## flink/v1.15/flink/src/test/java/org/apache/iceberg/flink/data/TestFlinkParquetReader.java: ########## @@ -81,26 +75,87 @@ public void testTwoLevelList() throws IOException { recordBuilder.set("topbytes", expectedBinary); GenericData.Record expectedRecord = recordBuilder.build(); - writer.write(expectedRecord); - writer.close(); + try (ParquetWriter<GenericRecord> writer = + AvroParquetWriter.<GenericRecord>builder(new Path(testFile.toURI())) + .withDataModel(GenericData.get()) + .withSchema(avroSchema) + .config("parquet.avro.add-list-element-records", "true") + .config("parquet.avro.write-old-list-structure", "true") + .build()) { + writer.write(expectedRecord); + } try (CloseableIterable<RowData> reader = Parquet.read(Files.localInput(testFile)) .project(schema) .createReaderFunc(type -> FlinkParquetReaders.buildReader(schema, type)) .build()) { Iterator<RowData> rows = reader.iterator(); - Assert.assertTrue("Should have at least one row", rows.hasNext()); + assertThat(rows).as("Should have at least one row").hasNext(); + RowData rowData = rows.next(); + assertThat(expectedByte).isEqualTo(rowData.getArray(0).getBinary(0)); + assertThat(expectedByte).isEqualTo(rowData.getBinary(1)); + assertThat(rows).as("Should not have more than one row").isExhausted(); + } + } + + @Test + public void testReadBinaryFieldAsString() throws IOException { + Schema schemaForWriteBinary = new Schema(optional(1, "strbytes", Types.BinaryType.get())); + org.apache.avro.Schema avroSchema = AvroSchemaUtil.convert(schemaForWriteBinary.asStruct()); + + File testFile = temp.newFile(); + assertThat(testFile.delete()).isTrue(); + + String expectedString = "hello"; + + GenericRecordBuilder recordBuilder = new GenericRecordBuilder(avroSchema); + ByteBuffer expectedBinary = ByteBuffer.wrap(expectedString.getBytes(StandardCharsets.UTF_8)); + recordBuilder.set("strbytes", expectedBinary); + GenericData.Record expectedRecord = recordBuilder.build(); + + try (ParquetWriter<GenericRecord> writer = + AvroParquetWriter.<GenericRecord>builder(new Path(testFile.toURI())) + .withDataModel(GenericData.get()) + .withSchema(avroSchema) + .build()) { + writer.write(expectedRecord); + } + + // read as string + Schema schemaForReadBinaryAsString = + new Schema(optional(1, "strbytes", Types.StringType.get())); + try (CloseableIterable<RowData> reader = + Parquet.read(Files.localInput(testFile)) + .project(schemaForReadBinaryAsString) + .createReaderFunc( + type -> FlinkParquetReaders.buildReader(schemaForReadBinaryAsString, type)) + .build()) { + Iterator<RowData> rows = reader.iterator(); + assertThat(rows).as("Should have at least one row").hasNext(); + RowData rowData = rows.next(); + assertThat(rowData.getString(0)).isInstanceOf(BinaryStringData.class); + assertThat(rowData.getString(0).toString()).isEqualTo(expectedString); + assertThat(rows).as("Should not have more than one row").isExhausted(); + } + + // read as byte[] Review Comment: Should this be a separate test case? -- 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...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org