Skip to content

Commit

Permalink
[CALCITE-1188] NullPointerException when EXTRACT is applied to NULL d…
Browse files Browse the repository at this point in the history
…ate field (Alessandro Solimando)

This commit is just a test case, and it passes; the bug was apparently fixed a while ago.

Fix a compilation error caused by upgrade to Java 8.

Close apache#607
Close apache#608

Change-Id: I5afd0f0609353666fe6236883357beb77cd10c92
  • Loading branch information
asolimando authored and julianhyde committed Jan 18, 2018
1 parent 0ecbdab commit 8de5d8d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions core/src/test/java/org/apache/calcite/test/JdbcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,30 @@ public Void apply(ResultSet a0) {
.returns("C=3\n");
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1188">[CALCITE-1188]
* NullPointerException when EXTRACT is applied to NULL date field</a>.
* The problem occurs when EXTRACT appears in both SELECT and WHERE ... IN
* clauses, the latter with at least two values. */
@Test public void testExtractOnNullDateField() {
final String sql = "select\n"
+ " extract(year from \"end_date\"), \"hire_date\", \"birth_date\"\n"
+ "from \"foodmart\".\"employee\"\n"
+ "where extract(year from \"end_date\") in (1994, 1995, 1996)\n"
+ "group by\n"
+ " extract(year from \"end_date\"), \"hire_date\", \"birth_date\"\n";
final String sql2 = sql + "\n"
+ "limit 10000";
final String sql3 = "select *\n"
+ "from \"foodmart\".\"employee\"\n"
+ "where extract(year from \"end_date\") in (1994, 1995, 1996)";
final CalciteAssert.AssertThat with = CalciteAssert.that()
.with(CalciteAssert.Config.FOODMART_CLONE);
with.query(sql).returns("");
with.query(sql2).returns("");
with.query(sql3).returns("");
}

@Test public void testFloorDate() {
CalciteAssert.that()
.with(CalciteAssert.Config.JDBC_FOODMART)
Expand Down
2 changes: 1 addition & 1 deletion piglet/src/main/java/org/apache/calcite/piglet/Ast.java
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ public UnParser append(Node n) {

public UnParser appendList(List<? extends Node> list) {
append("[").in();
for (Ord<Node> n : Ord.zip(list)) {
for (Ord<Node> n : Ord.<Node>zip(list)) {
newline().append(n.e);
if (n.i < list.size() - 1) {
append(",");
Expand Down

0 comments on commit 8de5d8d

Please sign in to comment.