Skip to content

Commit

Permalink
fix ordering with a scalar on a column containing NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
msbt committed Mar 10, 2015
1 parent 1dcb4cc commit 5280263
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changes for Crate
Unreleased
==========

- Fix: Sorting on a scalar with a column containing NULL values as
argument no longer throws an NPE

- Fix: group by on clustered by column on a partitioned table now produces
correct results for groups spanning different partitions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public int compareBottom(int doc) throws IOException {
LuceneCollectorExpression collectorExpression = collectorExpressions.get(i);
collectorExpression.setNextDocId(doc);
}
return valueType.compareValueTo(bottom, input.value());
return valueType.compareValueTo(bottom, MoreObjects.firstNonNull(input.value(), missingValue));
}

@SuppressWarnings("unchecked")
Expand All @@ -509,7 +509,7 @@ public int compareTop(int doc) throws IOException {
LuceneCollectorExpression collectorExpression = collectorExpressions.get(i);
collectorExpression.setNextDocId(doc);
}
return valueType.compareValueTo(top, input.value());
return valueType.compareValueTo(top, MoreObjects.firstNonNull(input.value(), missingValue));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,20 @@ public void testArithmeticScalarFunctionsOnAllTypes() throws Exception {
execute(String.format(Locale.ENGLISH, "select %s, d from t where %s < 2", doubleCall, doubleCall));
}
}

@Test
public void testSelectOrderByScalarOnNullValue() throws Exception {
execute("create table t (d long, name string) clustered into 1 shards with (number_of_replicas=0)");
ensureGreen();
execute("insert into t (d, name) values (?, ?)", new Object[][] {
new Object[] {-7L, "Marvin" },
new Object[] {null, "Arthur" },
new Object[] {5L, "Trillian" },
new Object[] {null, "Trillian" }

} );
execute("refresh table t");
execute("select (d - 10) from t order by (d - 10) nulls first limit 2");
assertThat(response.rows()[0][0], is(nullValue()));
}
}

0 comments on commit 5280263

Please sign in to comment.