kbendick commented on a change in pull request #2062:
URL: https://github.com/apache/iceberg/pull/2062#discussion_r569859335



##########
File path: 
api/src/test/java/org/apache/iceberg/expressions/TestInclusiveManifestEvaluator.java
##########
@@ -389,6 +396,39 @@ public void testStringStartsWith() {
     Assert.assertFalse("Should skip: range doesn't match", shouldRead);
   }
 
+  @Test
+  public void testStringNotStartsWith() {
+    boolean shouldRead = 
ManifestEvaluator.forRowFilter(notStartsWith("some_nulls", "a"), SPEC, 
false).eval(FILE);
+    Assert.assertTrue("Should read: range matches", shouldRead);
+
+    shouldRead = ManifestEvaluator.forRowFilter(notStartsWith("some_nulls", 
"aa"), SPEC, false).eval(FILE);
+    Assert.assertTrue("Should read: range matches", shouldRead);
+
+    shouldRead = ManifestEvaluator.forRowFilter(notStartsWith("some_nulls", 
"dddd"), SPEC, false).eval(FILE);
+    Assert.assertTrue("Should read: range matches", shouldRead);
+
+    shouldRead = ManifestEvaluator.forRowFilter(notStartsWith("some_nulls", 
"z"), SPEC, false).eval(FILE);
+    Assert.assertTrue("Should read: range matches", shouldRead);
+
+    shouldRead = ManifestEvaluator.forRowFilter(notStartsWith("no_nulls", 
"a"), SPEC, false).eval(FILE);
+    Assert.assertTrue("Should read: range matches", shouldRead);
+
+    shouldRead = ManifestEvaluator.forRowFilter(notStartsWith("some_nulls", 
"zzzz"), SPEC, false).eval(FILE);
+    Assert.assertTrue("Should read: range matches", shouldRead);
+
+    shouldRead = ManifestEvaluator.forRowFilter(notStartsWith("some_nulls", 
"1"), SPEC, false).eval(FILE);
+    Assert.assertTrue("Should read: range matches", shouldRead);

Review comment:
       I had some concerns about my original Spark based check, so I checked 
again. I was mistaken when I initially checked to see what Spark returns, as 
Spark implements SQL 3-way boolean logic, for example:
   
   ```
   scala> val df = Seq("aa", "bb", null, "b").toDF("word")
   df: org.apache.spark.sql.DataFrame = [word: string]
   scala> df.createOrReplaceTempView("t")
   scala> df.select(not($"word".startsWith("bb"))).show
   +--------------------------+
   |(NOT startswith(word, bb))|
   +--------------------------+
   |                      true|
   |                     false|
   |                      null|
   |                      true|
   +--------------------------+
   scala> spark.sql("SELECT * FROM t WHERE word NOT LIKE 'bb%'").show
   +----+
   |word|
   +----+
   |  aa|
   |   b|
   +----+
   ```
   
   However, Iceberg does not implement 3-way boolean logic. So we need to make 
a decision on whether or not we want Iceberg to return `true` or `false` in 
this case.
   
   I discussed this offline with @rdblue and we've come up with the following 
rationale for an `all_nulls` file matching a `notStartsWith` filter:
   
   The argument in favor of returning `true` is stronger than deciding to 
return `false`, i.e. by saying that null does not start with "bb" or whatever 
the predicate's value is. The reason for this is that:
   (1) Logically, null does not start with "bb" (or any non-null value)
   (2) If we have to choose between Iceberg surfacing too many values or too 
few, we would want Iceberg to return more values and then allow the query 
engine to make the final decision on the null value. If we return too few 
values, the query engine might not return the results that it would have if the 
underlying table format were not Iceberg. However, if we return too many values 
from the predicate filters, as in this case `true` means maybe and so the query 
engine can still ensure that the result is correct (according to the query 
engines definition of correct). When `false` means definitely not, the query 
engine has no ability to catch anything.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to