Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor Author

@chunweilei chunweilei Apr 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change, the generated code for conditions like name like 'ss' and name not like 'xx' is
inp1_ == null || inp1_ != null ? (Boolean) null : Boolean.TRUE)
which is wrong because it always return null.
After this change it becomes
inp1_ == null ? (Boolean) null : Boolean.TRUE.

}
Expand Down
23 changes: 23 additions & 0 deletions example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,29 @@ private static StringBuilder escapeString(StringBuilder buf, String s) {
.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>.
*/
@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"
Expand Down