SQL: Fix BasicFormatter NPE (#37804)
This commit is contained in:
parent
7517e3a7bd
commit
163a27b93c
|
@ -36,7 +36,7 @@ public class BasicFormatter implements Writeable {
|
|||
private final Function<Object, String> apply;
|
||||
|
||||
FormatOption(Function<Object, String> apply) {
|
||||
this.apply = l -> l == null ? null : apply.apply(l);
|
||||
this.apply = apply;
|
||||
}
|
||||
|
||||
public final String apply(Object l) {
|
||||
|
|
|
@ -22,12 +22,14 @@ public class BasicFormatterTests extends ESTestCase {
|
|||
new ColumnInfo("", "foo", "string", 0),
|
||||
new ColumnInfo("", "bar", "long", 15),
|
||||
new ColumnInfo("", "15charwidename!", "double", 25),
|
||||
new ColumnInfo("", "null_field1", "integer", 0),
|
||||
new ColumnInfo("", "superduperwidename!!!", "double", 25),
|
||||
new ColumnInfo("", "baz", "keyword", 0),
|
||||
new ColumnInfo("", "date", "datetime", 24)),
|
||||
new ColumnInfo("", "date", "datetime", 24),
|
||||
new ColumnInfo("", "null_field2", "keyword", 0)),
|
||||
Arrays.asList(
|
||||
Arrays.asList("15charwidedata!", 1, 6.888, 12, "rabbit", "1953-09-02T00:00:00.000Z"),
|
||||
Arrays.asList("dog", 1.7976931348623157E308, 123124.888, 9912, "goat", "2000-03-15T21:34:37.443Z")));
|
||||
Arrays.asList("15charwidedata!", 1, 6.888, null, 12, "rabbit", "1953-09-02T00:00:00.000Z", null),
|
||||
Arrays.asList("dog", 1.7976931348623157E308, 123124.888, null, 9912, "goat", "2000-03-15T21:34:37.443Z", null)));
|
||||
private final BasicFormatter formatter = new BasicFormatter(firstResponse.columns(), firstResponse.rows(), format);
|
||||
|
||||
/**
|
||||
|
@ -40,14 +42,14 @@ public class BasicFormatterTests extends ESTestCase {
|
|||
public void testFormatWithHeader() {
|
||||
String[] result = formatter.formatWithHeader(firstResponse.columns(), firstResponse.rows()).split("\n");
|
||||
assertThat(result, arrayWithSize(4));
|
||||
assertEquals(" foo | bar |15charwidename!|superduperwidename!!!| baz |"
|
||||
+ " date ", result[0]);
|
||||
assertEquals("---------------+----------------------+---------------+---------------------+---------------+"
|
||||
+ "------------------------", result[1]);
|
||||
assertEquals("15charwidedata!|1 |6.888 |12 |rabbit |"
|
||||
+ "1953-09-02T00:00:00.000Z", result[2]);
|
||||
assertEquals("dog |1.7976931348623157E308|123124.888 |9912 |goat |"
|
||||
+ "2000-03-15T21:34:37.443Z", result[3]);
|
||||
assertEquals(" foo | bar |15charwidename!| null_field1 |superduperwidename!!!| baz |"
|
||||
+ " date | null_field2 ", result[0]);
|
||||
assertEquals("---------------+----------------------+---------------+---------------+---------------------+---------------+"
|
||||
+ "------------------------+---------------", result[1]);
|
||||
assertEquals("15charwidedata!|1 |6.888 |null |12 |rabbit |"
|
||||
+ "1953-09-02T00:00:00.000Z|null ", result[2]);
|
||||
assertEquals("dog |1.7976931348623157E308|123124.888 |null |9912 |goat |"
|
||||
+ "2000-03-15T21:34:37.443Z|null ", result[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,13 +59,13 @@ public class BasicFormatterTests extends ESTestCase {
|
|||
public void testFormatWithoutHeader() {
|
||||
String[] result = formatter.formatWithoutHeader(
|
||||
Arrays.asList(
|
||||
Arrays.asList("ohnotruncateddata", 4, 1, 77, "wombat", "1955-01-21T01:02:03.342Z"),
|
||||
Arrays.asList("dog", 2, 123124.888, 9912, "goat", "2231-12-31T23:59:59.999Z"))).split("\n");
|
||||
Arrays.asList("ohnotruncateddata", 4, 1, null, 77, "wombat", "1955-01-21T01:02:03.342Z", null),
|
||||
Arrays.asList("dog", 2, 123124.888, null, 9912, "goat", "2231-12-31T23:59:59.999Z", null))).split("\n");
|
||||
assertThat(result, arrayWithSize(2));
|
||||
assertEquals("ohnotruncatedd~|4 |1 |77 |wombat |"
|
||||
+ "1955-01-21T01:02:03.342Z", result[0]);
|
||||
assertEquals("dog |2 |123124.888 |9912 |goat |"
|
||||
+ "2231-12-31T23:59:59.999Z", result[1]);
|
||||
assertEquals("ohnotruncatedd~|4 |1 |null |77 |wombat |"
|
||||
+ "1955-01-21T01:02:03.342Z|null ", result[0]);
|
||||
assertEquals("dog |2 |123124.888 |null |9912 |goat |"
|
||||
+ "2231-12-31T23:59:59.999Z|null ", result[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue