mirror of https://github.com/apache/druid.git
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:
parent
26b911a384
commit
045b29fa95
|
@ -134,7 +134,9 @@ public class SqlResource
|
||||||
for (int i = 0; i < fieldList.size(); i++) {
|
for (int i = 0; i < fieldList.size(); i++) {
|
||||||
final Object value;
|
final Object value;
|
||||||
|
|
||||||
if (timeColumns[i]) {
|
if (row[i] == null) {
|
||||||
|
value = null;
|
||||||
|
} else if (timeColumns[i]) {
|
||||||
value = ISODateTimeFormat.dateTime().print(
|
value = ISODateTimeFormat.dateTime().print(
|
||||||
Calcites.calciteTimestampToJoda((long) row[i], timeZone)
|
Calcites.calciteTimestampToJoda((long) row[i], timeZone)
|
||||||
);
|
);
|
||||||
|
|
|
@ -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
|
@Test
|
||||||
public void testFieldAliasingSelect() throws Exception
|
public void testFieldAliasingSelect() throws Exception
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue