nastra commented on code in PR #8808: URL: https://github.com/apache/iceberg/pull/8808#discussion_r1358326874
########## flink/v1.15/flink/src/test/java/org/apache/iceberg/flink/data/TestFlinkParquetReader.java: ########## @@ -90,17 +92,72 @@ public void testTwoLevelList() throws IOException { .createReaderFunc(type -> FlinkParquetReaders.buildReader(schema, type)) .build()) { Iterator<RowData> rows = reader.iterator(); - Assert.assertTrue("Should have at least one row", rows.hasNext()); + assertThat(rows.hasNext()).as("Should have at least one row").isTrue(); RowData rowData = rows.next(); - Assert.assertArrayEquals(rowData.getArray(0).getBinary(0), expectedByte); - Assert.assertArrayEquals(rowData.getBinary(1), expectedByte); - Assert.assertFalse("Should not have more than one row", rows.hasNext()); + assertThat(expectedByte).isEqualTo(rowData.getArray(0).getBinary(0)); + assertThat(expectedByte).isEqualTo(rowData.getBinary(1)); + assertThat(rows.hasNext()).as("Should not have more than one row").isFalse(); + } + } + + @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(); + + ParquetWriter<GenericRecord> writer = + AvroParquetWriter.<GenericRecord>builder(new Path(testFile.toURI())) + .withDataModel(GenericData.get()) + .withSchema(avroSchema) + .build(); + + 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(); + + writer.write(expectedRecord); + writer.close(); + + // 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.hasNext()).as("Should have at least one row").isTrue(); Review Comment: this should typically be `assertThat(rows).as("...").hasNext()`. The reason for that is that AssertJ provides additional context when an assertion fails and such fluent-style checks are usually preferred over the `.isTrue()`/`.isFalse()` checks -- 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