This is an automated email from the ASF dual-hosted git repository.

danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/master by this push:
     new b039a36  [CALCITE-3034] CSV test case description does not match it's 
code logic (FaxianZhao)
b039a36 is described below

commit b039a36a3d683f0948531b16a9d97ee50615a5eb
Author: zhaofaxian <[email protected]>
AuthorDate: Mon Apr 29 14:06:40 2019 +0800

    [CALCITE-3034] CSV test case description does not match it's code logic 
(FaxianZhao)
    
    The o.a.c.a.c.CsvFilterableTable will ignore the whole filter condition
    with AND as SqlKind before this patch.
    
    Close apache/calcite#3034
---
 .../java/org/apache/calcite/adapter/csv/CsvFilterableTable.java  | 6 +++++-
 example/csv/src/test/java/org/apache/calcite/test/CsvTest.java   | 9 +++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git 
a/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvFilterableTable.java
 
b/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvFilterableTable.java
index 46555f0..baf960b 100644
--- 
a/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvFilterableTable.java
+++ 
b/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvFilterableTable.java
@@ -63,7 +63,11 @@ public class CsvFilterableTable extends CsvTable
   }
 
   private boolean addFilter(RexNode filter, Object[] filterValues) {
-    if (filter.isA(SqlKind.EQUALS)) {
+    if (filter.isA(SqlKind.AND)) {
+        // We cannot refine(remove) the operands of AND,
+        // it will cause o.a.c.i.TableScanNode.createFilterable filters check 
failed.
+      ((RexCall) filter).getOperands().forEach(subFilter -> 
addFilter(subFilter, filterValues));
+    } else if (filter.isA(SqlKind.EQUALS)) {
       final RexCall call = (RexCall) filter;
       RexNode left = call.getOperands().get(0);
       if (left.isA(SqlKind.CAST)) {
diff --git a/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java 
b/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
index d073d2f..eee4804 100644
--- a/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
+++ b/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
@@ -297,6 +297,15 @@ public class CsvTest {
         .returns("EMPNO=130; GENDER=F; NAME=Alice").ok();
   }
 
+  /** Filter that can be slightly handled by CsvFilterableTable. */
+  @Test public void testFilterableWhere3() throws SQLException {
+    final String sql = "select empno, gender, name from EMPS\n"
+            + " where gender <> 'M' and empno > 125";
+    sql("filterable-model", sql)
+        .returns("EMPNO=130; GENDER=F; NAME=Alice")
+        .ok();
+  }
+
   /** Test case for
    * <a 
href="https://issues.apache.org/jira/browse/CALCITE-2272";>[CALCITE-2272]
    * Incorrect result for {@code name like '%E%' and city not like '%W%'}</a>.

Reply via email to