From d083d51293ff21c90f4d1400aabb7418063aa70a Mon Sep 17 00:00:00 2001 From: Chunwei Lei Date: Fri, 26 Apr 2019 19:41:23 +0800 Subject: [PATCH] [CALCITE-2292] Query result is wrong when table is implemented with FilterableTable and the sql has multiple where conditions --- .../adapter/enumerable/RexImpTable.java | 4 ++++ .../java/org/apache/calcite/test/CsvTest.java | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java index 87afe4b5ab0e..73fee327ea33 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java @@ -727,6 +727,10 @@ private NullAs negate(NullAs nullAs) { return NullAs.TRUE; case TRUE: return NullAs.FALSE; + case IS_NULL: + return NullAs.IS_NOT_NULL; + case IS_NOT_NULL: + return NullAs.IS_NULL; default: return nullAs; } 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 dd43474fa6ee..d073d2f5c96c 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,29 @@ private static StringBuilder escapeString(StringBuilder buf, String s) { .returns("EMPNO=130; GENDER=F; NAME=Alice").ok(); } + /** Test case for + * [CALCITE-2272] + * Incorrect result for {@code name like '%E%' and city not like '%W%'}. + */ + @Test public void testFilterableWhereWithNot1() throws SQLException { + sql("filterable-model", + "select name, empno from EMPS " + + "where name like '%E%' and city not like '%W%' ") + .returns("NAME=Eric; EMPNO=110") + .ok(); + } + + /** Similar to {@link #testFilterableWhereWithNot1()}; + * But use the same column. */ + @Test public void testFilterableWhereWithNot2() throws SQLException { + sql("filterable-model", + "select name, empno from EMPS " + + "where name like '%i%' and name not like '%W%' ") + .returns("NAME=Eric; EMPNO=110", + "NAME=Alice; EMPNO=130") + .ok(); + } + @Test public void testJson() throws SQLException { final String sql = "select _MAP['id'] as id,\n" + " _MAP['title'] as title,\n"