yangshangqing95 commented on code in PR #17750:
URL: https://github.com/apache/iceberg/pull/17750#discussion_r3846094985
##########
orc/src/test/java/org/apache/iceberg/orc/TestOrcDataReader.java:
##########
@@ -167,4 +176,65 @@ public void testRowReaderWithFilterWithSelected() throws
IOException {
assertThat(readRecords.get(0).get(1)).isEqualTo("c");
assertThat(readRecords.get(0).get(3)).isEqualTo(Arrays.asList(3, 4, 5));
}
+
+ @ParameterizedTest
+ @MethodSource("timestampNanoCases")
+ void filtersTimestampNanosWithoutLosingPrecision(
+ Types.TimestampNanoType timestampType,
+ Object boundary,
+ Object matchingValue,
+ long boundaryNanos)
+ throws IOException {
+ Schema schema =
+ new Schema(
+ Types.NestedField.required(1, "id", Types.LongType.get()),
+ Types.NestedField.optional(2, "ts", timestampType));
+
+ GenericRecord recordTemplate = GenericRecord.create(schema);
+ OutputFile timestampFile = Files.localOutput(new File(temp, timestampType
+ ".orc"));
+
+ try (FileAppender<Record> writer =
+ ORC.write(timestampFile)
+ .schema(schema)
+ .createWriterFunc(GenericOrcWriter::buildWriter)
+ .build()) {
+ writer.add(recordTemplate.copy("id", 1L, "ts", boundary));
+ writer.add(recordTemplate.copy("id", 2L, "ts", matchingValue));
+ writer.add(recordTemplate.copy("id", 3L));
+ }
+
+ Expression filter =
+ Expressions.predicate(Expression.Operation.GT, "ts",
Expressions.nanos(boundaryNanos));
+
+ List<Record> rows;
+ try (CloseableIterable<Record> reader =
+ ORC.read(timestampFile.toInputFile())
+ .project(schema)
+ .createReaderFunc(fileSchema ->
GenericOrcReader.buildReader(schema, fileSchema))
+ .filter(filter)
+ .config(OrcConf.ALLOW_SARG_TO_FILTER.getAttribute(),
String.valueOf(true))
+ .config(OrcConf.READER_USE_SELECTED.getAttribute(),
String.valueOf(true))
+ .build()) {
+ rows = Lists.newArrayList(reader);
+ }
+
+ assertThat(rows).extracting(row -> row.getField("id")).containsExactly(2L);
+ }
+
+ private static Stream<Arguments> timestampNanoCases() {
Review Comment:
Thanks for the reviewing, done
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]