bodduv commented on code in PR #14500:
URL: https://github.com/apache/iceberg/pull/14500#discussion_r2816421717
##########
api/src/test/java/org/apache/iceberg/expressions/TestInclusiveManifestEvaluator.java:
##########
@@ -853,4 +869,335 @@ public void testNotInWithSingleValue() {
.as("Should not read: manifest contains single float value with no
NaNs")
.isFalse();
}
+
+ @Test
+ public void testUuidEq() {
+ UUID belowMin = UUID.fromString("00000000-0000-0000-0000-000000000000");
+ boolean shouldRead =
+ ManifestEvaluator.forRowFilter(equal("uuid", belowMin), SPEC,
true).eval(FILE);
+ assertThat(shouldRead).as("Should not read: uuid below lower
bound").isFalse();
+
+ shouldRead =
+ ManifestEvaluator.forRowFilter(equal("uuid", UUID_MIN_VALUE), SPEC,
true).eval(FILE);
+ assertThat(shouldRead).as("Should read: uuid equal to lower
bound").isTrue();
+
+ UUID between = UUID.fromString("7fffffff-ffff-ffff-7fff-ffffffffffff");
+ shouldRead = ManifestEvaluator.forRowFilter(equal("uuid", between), SPEC,
true).eval(FILE);
+ assertThat(shouldRead).as("Should read: uuid between lower and upper
bounds").isTrue();
+
+ shouldRead =
+ ManifestEvaluator.forRowFilter(equal("uuid", UUID_MAX_VALUE), SPEC,
true).eval(FILE);
+ assertThat(shouldRead).as("Should read: uuid equal to upper
bound").isTrue();
+
+ UUID aboveMax = UUID.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff");
+ shouldRead = ManifestEvaluator.forRowFilter(equal("uuid", aboveMax), SPEC,
true).eval(FILE);
+ assertThat(shouldRead).as("Should not read: uuid above upper
bound").isFalse();
+ }
+
+ @Test
+ public void testUuidLt() {
+ // With RFC comparison, belowMin is below the lower bound so no rows can
be < belowMin.
+ // With signed comparison, UUID_MIN_VALUE.compareTo(belowMin) = -1 (lower
< lit),
+ // so rows might match. We try both comparators and return true if either
matches.
+ UUID belowMin = UUID.fromString("00000000-0000-0000-0000-000000000000");
+ boolean shouldRead =
+ ManifestEvaluator.forRowFilter(lessThan("uuid", belowMin), SPEC,
true).eval(FILE);
+ assertThat(shouldRead)
+ .as("Should read: signed UUID fallback finds matches with inverted
bounds")
+ .isTrue();
+
+ // UUID_MIN_VALUE is the lower bound, so no rows can be < UUID_MIN_VALUE.
+ // Both RFC and signed comparators agree on this since we're comparing the
value to itself.
+ shouldRead =
+ ManifestEvaluator.forRowFilter(lessThan("uuid", UUID_MIN_VALUE), SPEC,
true).eval(FILE);
+ assertThat(shouldRead)
+ .as("Should not read: uuid range below lower bound (UUID_MIN is not <
UUID_MIN)")
+ .isFalse();
+
+ UUID justAboveMin =
UUID.fromString("00000000-0000-0001-0000-000000000000");
+ shouldRead =
+ ManifestEvaluator.forRowFilter(lessThan("uuid", justAboveMin), SPEC,
true).eval(FILE);
+ assertThat(shouldRead).as("Should read: one possible uuid").isTrue();
+
+ shouldRead =
+ ManifestEvaluator.forRowFilter(lessThan("uuid", UUID_MAX_VALUE), SPEC,
true).eval(FILE);
+ assertThat(shouldRead).as("Should read: uuid between lower and upper
bounds").isTrue();
+
+ UUID aboveMax = UUID.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff");
+ shouldRead = ManifestEvaluator.forRowFilter(lessThan("uuid", aboveMax),
SPEC, true).eval(FILE);
+ assertThat(shouldRead).as("Should read: all uuids in range").isTrue();
+ }
+
+ @Test
+ public void testUuidLtEq() {
+ // With RFC comparison, belowMin is below the lower bound so no rows can
be <= belowMin.
+ // With signed comparison, the bounds are inverted, so rows might match.
+ UUID belowMin = UUID.fromString("00000000-0000-0000-0000-000000000000");
+ boolean shouldRead =
+ ManifestEvaluator.forRowFilter(lessThanOrEqual("uuid", belowMin),
SPEC, true).eval(FILE);
+ assertThat(shouldRead)
+ .as("Should read: signed UUID fallback finds matches with inverted
bounds")
+ .isTrue();
+
+ shouldRead =
+ ManifestEvaluator.forRowFilter(lessThanOrEqual("uuid",
UUID_MIN_VALUE), SPEC, true)
+ .eval(FILE);
+ assertThat(shouldRead).as("Should read: one possible uuid").isTrue();
+
+ shouldRead =
+ ManifestEvaluator.forRowFilter(lessThanOrEqual("uuid",
UUID_MAX_VALUE), SPEC, true)
+ .eval(FILE);
+ assertThat(shouldRead).as("Should read: all uuids in range").isTrue();
+
+ UUID aboveMax = UUID.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff");
+ shouldRead =
+ ManifestEvaluator.forRowFilter(lessThanOrEqual("uuid", aboveMax),
SPEC, true).eval(FILE);
+ assertThat(shouldRead).as("Should read: all uuids in range").isTrue();
+ }
+
+ @Test
+ public void testUuidGt() {
+ UUID belowMin = UUID.fromString("00000000-0000-0000-0000-000000000000");
+ boolean shouldRead =
+ ManifestEvaluator.forRowFilter(greaterThan("uuid", belowMin), SPEC,
true).eval(FILE);
+ assertThat(shouldRead).as("Should read: all uuids in range").isTrue();
+
+ shouldRead =
+ ManifestEvaluator.forRowFilter(greaterThan("uuid", UUID_MIN_VALUE),
SPEC, true).eval(FILE);
+ assertThat(shouldRead).as("Should read: uuid between lower and upper
bounds").isTrue();
+
+ UUID justBelowMax =
UUID.fromString("ffffffff-ffff-fffe-ffff-ffffffffffff");
+ shouldRead =
+ ManifestEvaluator.forRowFilter(greaterThan("uuid", justBelowMax),
SPEC, true).eval(FILE);
+ assertThat(shouldRead).as("Should read: one possible uuid").isTrue();
Review Comment:
Changed it to: `Should read: uuid between justBelowMax and the upper bound`.
--
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]