rdblue commented on a change in pull request #1893:
URL: https://github.com/apache/iceberg/pull/1893#discussion_r557563674



##########
File path: 
flink/src/test/java/org/apache/iceberg/flink/TestFlinkTableSource.java
##########
@@ -90,17 +103,418 @@ public void testLimitPushDown() {
 
     Assert.assertEquals("should have 0 record", 0, sql("SELECT * FROM %s LIMIT 
0", TABLE_NAME).size());
 
-    String sqlLimitExceed = String.format("SELECT * FROM %s LIMIT 3", 
TABLE_NAME);
+    String sqlLimitExceed = String.format("SELECT * FROM %s LIMIT 4", 
TABLE_NAME);
     List<Object[]> resultExceed = sql(sqlLimitExceed);
-    Assert.assertEquals("should have 2 record", 2, resultExceed.size());
+    Assert.assertEquals("should have 3 record", 3, resultExceed.size());
     List<Object[]> expectedList = Lists.newArrayList();
     expectedList.add(new Object[] {1, "a"});
     expectedList.add(new Object[] {2, "b"});
+    expectedList.add(new Object[] {3, null});
     Assert.assertArrayEquals("Should produce the expected records", 
resultExceed.toArray(), expectedList.toArray());
 
     String sqlMixed = String.format("SELECT * FROM %s WHERE id = 1 LIMIT 2", 
TABLE_NAME);
     List<Object[]> mixedResult = sql(sqlMixed);
     Assert.assertEquals("should have 1 record", 1, mixedResult.size());
     Assert.assertArrayEquals("Should produce the expected records", 
mixedResult.get(0), new Object[] {1, "a"});
   }
+
+  @Test
+  public void testNoFilterPushDown() {
+    String sql = String.format("SELECT * FROM %s ", TABLE_NAME);
+    String explain = getTableEnv().explainSql(sql);
+    Assert.assertFalse("explain should no contains FilterPushDown", 
explain.contains(expectedFilterPushDownExplain));
+  }
+
+  @Test
+  public void testFilterPushDownEqual() {
+    String sqlLiteralRight = String.format("SELECT * FROM %s WHERE id = 1 ", 
TABLE_NAME);
+    String explain = getTableEnv().explainSql(sqlLiteralRight);
+    String expectedFilter = "ref(name=\"id\") == 1";
+    Assert.assertTrue("explain should contains the push down filter", 
explain.contains(expectedFilter));
+
+    List<Object[]> result = sql(sqlLiteralRight);
+    Assert.assertEquals("should have 1 record", 1, result.size());
+    Assert.assertArrayEquals("Should produce the expected record", 
result.get(0), new Object[] {1, "a"});
+
+    Assert.assertEquals("Should create only one scan", 1, scanEventCount);
+    Assert.assertEquals("should contains the push down filter", 
lastScanEvent.filter().toString(), expectedFilter);
+
+    // filter not push down
+    String sqlEqualNull = String.format("SELECT * FROM %s WHERE data = NULL ", 
TABLE_NAME);
+    String explainEqualNull = getTableEnv().explainSql(sqlEqualNull);
+    Assert.assertFalse("explain should not contains FilterPushDown",
+        explainEqualNull.contains(expectedFilterPushDownExplain));
+  }
+
+  @Test
+  public void testFilterPushDownEqualLiteralOnLeft() {
+    String sqlLiteralLeft = String.format("SELECT * FROM %s WHERE 1 = id ", 
TABLE_NAME);
+    String explainLeft = getTableEnv().explainSql(sqlLiteralLeft);
+    String expectedFilter = "ref(name=\"id\") == 1";
+    Assert.assertTrue("explain should contains the push down filter", 
explainLeft.contains(expectedFilter));
+
+    List<Object[]> resultLeft = sql(sqlLiteralLeft);
+    Assert.assertEquals("should have 1 record", 1, resultLeft.size());
+    Assert.assertArrayEquals("Should produce the expected record", 
resultLeft.get(0), new Object[] {1, "a"});
+
+    Assert.assertEquals("Should create only one scan", 1, scanEventCount);
+    Assert.assertEquals("should contains the push down filter", 
lastScanEvent.filter().toString(), expectedFilter);

Review comment:
       The expected value comes first so that assertion failures show the right 
labels. If this failed, the actual filter would be shown as the expected filter.




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