RussellSpitzer commented on code in PR #14593:
URL: https://github.com/apache/iceberg/pull/14593#discussion_r2662697860
##########
api/src/test/java/org/apache/iceberg/expressions/TestInclusiveMetricsEvaluator.java:
##########
@@ -970,4 +970,172 @@ public void testNotNullInNestedStruct() {
.as("Should not read: optional_address.optional_street2 is optional")
.isFalse();
}
+
+ @Test
+ public void testNotEqWithSingleValue() {
+ DataFile rangeOfValues =
+ new TestDataFile(
+ "range_of_values.avro",
+ Row.of(),
+ 10,
+ ImmutableMap.of(3, 10L),
+ ImmutableMap.of(3, 0L),
+ ImmutableMap.of(3, 0L),
+ ImmutableMap.of(3, toByteBuffer(StringType.get(), "aaa")),
+ ImmutableMap.of(3, toByteBuffer(StringType.get(), "zzz")));
+
+ boolean shouldRead =
+ new InclusiveMetricsEvaluator(SCHEMA, notEqual("required",
"aaa")).eval(rangeOfValues);
+ assertThat(shouldRead)
+ .as("Should read: file has range of values, optimization doesn't
apply")
+ .isTrue();
+
+ DataFile singleValueFile =
+ new TestDataFile(
+ "single_value.avro",
+ Row.of(),
+ 10,
+ ImmutableMap.of(3, 10L),
+ ImmutableMap.of(3, 0L),
+ ImmutableMap.of(3, 0L),
+ ImmutableMap.of(3, toByteBuffer(StringType.get(), "abc")),
+ ImmutableMap.of(3, toByteBuffer(StringType.get(), "abc")));
+
+ shouldRead =
+ new InclusiveMetricsEvaluator(SCHEMA, notEqual("required",
"abc")).eval(singleValueFile);
+ assertThat(shouldRead)
+ .as("Should prune: file contains single value equal to literal")
+ .isFalse();
+
+ shouldRead =
+ new InclusiveMetricsEvaluator(SCHEMA, notEqual("required",
"def")).eval(singleValueFile);
+ assertThat(shouldRead)
+ .as("Should read: file contains single value not equal to literal")
+ .isTrue();
+
+ DataFile singleValueWithNulls =
+ new TestDataFile(
+ "single_value_nulls.avro",
+ Row.of(),
+ 10,
+ ImmutableMap.of(3, 10L),
+ ImmutableMap.of(3, 2L),
+ ImmutableMap.of(3, 0L),
+ ImmutableMap.of(3, toByteBuffer(StringType.get(), "abc")),
+ ImmutableMap.of(3, toByteBuffer(StringType.get(), "abc")));
+
+ shouldRead =
+ new InclusiveMetricsEvaluator(SCHEMA, notEqual("required", "abc"))
+ .eval(singleValueWithNulls);
+ assertThat(shouldRead).as("Should read: file has nulls which match !=
predicate").isTrue();
+
+ DataFile singleValueWithNaN =
+ new TestDataFile(
+ "single_value_nan.avro",
+ Row.of(),
+ 10,
+ ImmutableMap.of(9, 10L),
+ ImmutableMap.of(9, 0L),
+ ImmutableMap.of(9, 2L),
+ ImmutableMap.of(9, toByteBuffer(Types.FloatType.get(), 5.0F)),
+ ImmutableMap.of(9, toByteBuffer(Types.FloatType.get(), 5.0F)));
+
+ shouldRead =
+ new InclusiveMetricsEvaluator(SCHEMA, notEqual("no_nans",
5.0F)).eval(singleValueWithNaN);
+ assertThat(shouldRead).as("Should read: file has NaN values which match !=
predicate").isTrue();
+
+ DataFile singleValueNaNBounds =
+ new TestDataFile(
+ "single_value_nan_bounds.avro",
+ Row.of(),
+ 10,
+ ImmutableMap.of(9, 10L),
+ ImmutableMap.of(9, 0L),
+ ImmutableMap.of(9, 0L),
+ ImmutableMap.of(9, toByteBuffer(Types.FloatType.get(), Float.NaN)),
+ ImmutableMap.of(9, toByteBuffer(Types.FloatType.get(),
Float.NaN)));
+
+ shouldRead =
+ new InclusiveMetricsEvaluator(SCHEMA, notEqual("no_nans",
5.0F)).eval(singleValueNaNBounds);
+ assertThat(shouldRead).as("Should read: bounds are NaN").isTrue();
+ }
+
+ @Test
+ public void testNotInWithSingleValue() {
+ DataFile rangeOfValues =
+ new TestDataFile(
+ "range_of_values.avro",
+ Row.of(),
+ 10,
+ ImmutableMap.of(3, 10L),
+ ImmutableMap.of(3, 0L),
+ ImmutableMap.of(3, 0L),
+ ImmutableMap.of(3, toByteBuffer(StringType.get(), "aaa")),
+ ImmutableMap.of(3, toByteBuffer(StringType.get(), "zzz")));
+
+ boolean shouldRead =
+ new InclusiveMetricsEvaluator(SCHEMA, notIn("required", "aaa",
"bbb")).eval(rangeOfValues);
+ assertThat(shouldRead)
+ .as("Should read: file has range of values, optimization doesn't
apply")
+ .isTrue();
+
+ DataFile singleValueFile =
+ new TestDataFile(
+ "single_value.avro",
+ Row.of(),
+ 10,
+ ImmutableMap.of(3, 10L),
+ ImmutableMap.of(3, 0L),
+ ImmutableMap.of(3, 0L),
+ ImmutableMap.of(3, toByteBuffer(StringType.get(), "abc")),
+ ImmutableMap.of(3, toByteBuffer(StringType.get(), "abc")));
+
+ shouldRead =
+ new InclusiveMetricsEvaluator(SCHEMA, notIn("required", "abc", "def"))
+ .eval(singleValueFile);
+ assertThat(shouldRead)
+ .as("Should prune: file contains single value in exclusion list")
Review Comment:
```suggestion
.as("Should not read: file contains single value in exclusion list")
```
--
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]