-
Notifications
You must be signed in to change notification settings - Fork 25.4k
ESQL: Drop null columns in text formats #117643
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
ESQL: Drop null columns in text formats #117643
Conversation
Pinging @elastic/es-analytical-engine (Team:Analytics) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat! I left a small thing but I think it's great!
@bpintea, you wrote the text formatter stuff, would you like to review this one too?
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/formatter/TextFormat.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, left some small remarks.
@@ -60,17 +60,23 @@ public TextFormatter(EsqlQueryResponse response) { | |||
/** | |||
* Format the provided {@linkplain EsqlQueryResponse} optionally including the header lines. | |||
*/ | |||
public Iterator<CheckedConsumer<Writer, IOException>> format(boolean includeHeader) { | |||
public Iterator<CheckedConsumer<Writer, IOException>> format(boolean includeHeader, boolean dropNullColumns) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that includeHeader
was passed here as param, but this object is only created once per response. Maybe it's worth configuring it right from the start by passing these options in the c'tor and building there the [] dropColumns
, rather than passing this array down the method chain.
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/formatter/TextFormat.java
Outdated
Show resolved
Hide resolved
Thank you @bpintea . I have modified the code based on your comments. Please review it when you have time. If there are any other changes needed, please let me know. I am happy to make them. |
@elasticsearchmachine test this please |
hasHeader(request) && esqlResponse.columns().isEmpty() == false | ||
hasHeader(request) && esqlResponse.columns() != null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe columns will never be null. However, changing the check to see if they are empty might cause some test cases to fail. Perhaps it should be updated to handle empty values and adjust the affected test cases accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't try it out, but it looks to me like it should produce the same result. But yes, seems like esqlResponse.columns()
will currently never be null
.
case "csv" -> { | ||
assertEquals(initialValue, "\r\n"); | ||
assertEquals("\r\n", initialValue); | ||
initialValue = ""; | ||
} | ||
case "tsv" -> { | ||
assertEquals(initialValue, "\n"); | ||
assertEquals("\n", initialValue); | ||
initialValue = ""; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the test case I mentioned earlier that caused an error. When I first encountered this error, the expected and actual values were reversed, which confused me at first. Therefore, I think it would be better to flip them.
@bpintea, I have modified the code to resolve the test failure. However, I can only see this one failure because my IDEA crashes every time when running checks (Maybe I should update my equipment😂). It might be more convenient for external contributors if the elasticsearch-pull-request pipeline were open to the public, similar to the logstash-pull-request-pipeline. |
buildkite test this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @kanoshiou!
This PR resolves the issue where, despite setting `drop_null_columns=true`, columns that are entirely null are still returned when using `format=txt`, `format=csv`, or `format=tsv`. Closes elastic#116848
💚 Backport successful
|
This PR resolves the issue where, despite setting `drop_null_columns=true`, columns that are entirely null are still returned when using `format=txt`, `format=csv`, or `format=tsv`. Closes #116848 Co-authored-by: kanoshiou <[email protected]>
A bit late for this PR, but it is from now on. |
Thank you very much @bpintea ! |
This PR resolves the issue where, despite setting
drop_null_columns=true
, columns that are entirely null are still returned when usingformat=txt
,format=csv
, orformat=tsv
.Closes #116848