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



##########
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);
+  }
+
+  @Test
+  public void testFilterPushDownNoEqual() {
+    String sqlNE = String.format("SELECT * FROM %s WHERE id <> 1 ", 
TABLE_NAME);
+    String explainNE = getTableEnv().explainSql(sqlNE);
+    String expectedFilter = "ref(name=\"id\") != 1";
+    Assert.assertTrue("explain should contains the push down filter", 
explainNE.contains(expectedFilter));
+
+    List<Object[]> resultNE = sql(sqlNE);
+    Assert.assertEquals("should have 2 record", 2, resultNE.size());
+
+    List<Object[]> expectedNE = Lists.newArrayList();
+    expectedNE.add(new Object[] {2, "b"});
+    expectedNE.add(new Object[] {3, null});
+    Assert.assertArrayEquals("Should produce the expected record", 
resultNE.toArray(), expectedNE.toArray());
+    Assert.assertEquals("Should create only one scan", 1, scanEventCount);
+    Assert.assertEquals("should contains the push down filter", 
lastScanEvent.filter().toString(), expectedFilter);
+
+    String sqlNotEqualNull = String.format("SELECT * FROM %s WHERE data <> 
NULL ", TABLE_NAME);
+    String explainNotEqualNull = getTableEnv().explainSql(sqlNotEqualNull);
+    Assert.assertFalse("explain should not contains FilterPushDown", 
explainNotEqualNull.contains(
+        expectedFilterPushDownExplain));
+  }
+
+  @Test
+  public void testFilterPushDownAnd() {
+    String sqlAnd = String.format("SELECT * FROM %s WHERE id = 1 AND data = 
'a' ", TABLE_NAME);
+    String explainAnd = getTableEnv().explainSql(sqlAnd);
+    String expectedFilter = "ref(name=\"id\") == 1,ref(name=\"data\") == 
\"a\"";
+    Assert.assertTrue("explain should contains the push down filter", 
explainAnd.contains(expectedFilter));
+
+    List<Object[]> resultAnd = sql(sqlAnd);
+    Assert.assertEquals("should have 1 record", 1, resultAnd.size());
+    Assert.assertArrayEquals("Should produce the expected record", 
resultAnd.get(0), new Object[] {1, "a"});
+
+    Assert.assertEquals("Should create only one scan", 1, scanEventCount);
+    Assert
+        .assertEquals("should contains the push down filter", 
"(ref(name=\"id\") == 1 and ref(name=\"data\") == \"a\")",

Review comment:
       If we put it in one line, it will exceed the max limit of checkstyle, I 
extract the expected filter to a single string.




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