Correctly handle null values in time column results (#10642)

* handle null case

* test this case

* test sql resource

* fix style
This commit is contained in:
Franklyn Dsouza 2021-01-05 01:22:46 -05:00 committed by GitHub
parent 26b911a384
commit 045b29fa95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -134,7 +134,9 @@ public class SqlResource
for (int i = 0; i < fieldList.size(); i++) {
final Object value;
if (timeColumns[i]) {
if (row[i] == null) {
value = null;
} else if (timeColumns[i]) {
value = ISODateTimeFormat.dateTime().print(
Calcites.calciteTimestampToJoda((long) row[i], timeZone)
);

View File

@ -325,6 +325,31 @@ public class SqlResourceTest extends CalciteTestBase
);
}
@Test
public void testTimestampsInResponseWithNulls() throws Exception
{
final List<Map<String, Object>> rows = doPost(
new SqlQuery(
"SELECT MAX(__time) as t1, MAX(__time) FILTER(WHERE dim1 = 'non_existing') as t2 FROM druid.foo",
ResultFormat.OBJECT,
false,
null,
null
)
).rhs;
Assert.assertEquals(
NullHandling.replaceWithDefault() ?
ImmutableList.of(
ImmutableMap.of("t1", "2001-01-03T00:00:00.000Z", "t2", "-292275055-05-16T16:47:04.192Z") // t2 represents Long.MIN converted to a timestamp
) :
ImmutableList.of(
Maps.transformValues(ImmutableMap.of("t1", "2001-01-03T00:00:00.000Z", "t2", ""), (val) -> "".equals(val) ? null : val)
),
rows
);
}
@Test
public void testFieldAliasingSelect() throws Exception
{