Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: Fix BasicFormatter NPE #37804

Merged
merged 4 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public enum FormatOption {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand All @@ -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]);
}

/**
Expand All @@ -57,13 +59,13 @@ public void testFormatWithHeader() {
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]);
}

/**
Expand Down