-
Notifications
You must be signed in to change notification settings - Fork 25.6k
SQL: Fix querying of indices without columns #74312
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
Conversation
|
Pinging @elastic/es-ql (Team:QL) |
costin
left a comment
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.
Left a comment on null vs emptyList. Small nit, the table name could be improve to no_columns, no_mapping or empty_index.
|
|
||
| // the field exists, but cannot be expanded (no sub-fields) | ||
| if (expanded.isEmpty()) { | ||
| if (expanded == 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.
why not keep the empty list vs a 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.
That's more or less what caused the bug. Previously, expansion errors resulted in an empty list but that's ambiguous if the star is expanded on an index without columns. In this case, it returns an empty list meaning "star has been expanded to no fields".
To distinguish between expansion errors and empty expansions I now had to encode the error case with a null return value.
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.
You could return singletonList(ne) instead of passing null and treat it separately.
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.
got it, makes sense 👍
| } | ||
| // qualifier resolves to a non-struct field and cannot be expanded | ||
| else if (DataTypes.isPrimitive(q.dataType())) { | ||
| return 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.
Use emptyList() instead of null - allows iteration without blowing up and it's still fast as it avoid any allocation.
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 think you could simply return singleton(q) and avoid any special/null handling.
I first used |
matriv
left a comment
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. Left a few comments though. Thx!
| @@ -0,0 +1,23 @@ | |||
| selectConstAggregationWithGroupBy | |||
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.
Why did you choose to have those in .csv-spec?
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.
they also behave differently in H2 and all return no rows. I'll add a comment to clarify this.
| DROP TABLE IF EXISTS "no_cols"; | ||
| CREATE TABLE "no_cols" (); | ||
|
|
||
| INSERT INTO "no_cols" DEFAULT VALUES; |
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.
Is this required?
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 also want to cover cases with empty documents indexed in the empty mapping index.
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.
But now we only test a table with a row with no values, but not a completely empty table?
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.
Yes that's true. Do you think it would be worth to also have an empty_empty_mapping index for covering the no rows cases? To some extent, the "no rows" cases are already covered by tests that filter out all records.
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 don't know if that's too much, @costin, what do you think?
| selectConstAggregation | ||
| SELECT MAX(1), SUM(2) FROM no_cols; | ||
|
|
||
| // fails in H2 but cannot be tested in CSV spec because datasets without columns cannot be parsed |
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.
- Just curious, why does it fail in H2?
- Maybe you can open an issue to improve testing and have a way to assert no cols in csv in the feature and link it here.
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.
H2 fails with a syntax error:
Syntax error in SQL statement "SELECT
FROM PUBLIC.""no_cols""[*]"; expected "(, USE, AS, RIGHT, LEFT, FULL, INNER, JOIN, CROSS, NATURAL, ,, SELECT"; SQL statement:
CREATE FORCE VIEW PUBLIC._0 AS
SELECT
FROM PUBLIC."no_cols" [42001-197]
Looks like it uses a view to execute the subselect and the creation fails because it selects an empty list of columns. The latest version of H2 supports the query though, so #39895 would resolve the issue as well.
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.
Thx!
.../plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainer.java
Outdated
Show resolved
Hide resolved
bpintea
left a comment
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.
Nice. Lgtm.
astefan
left a comment
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've left few comments, all related to the same issue basically.
| Request request = new Request("POST", "/" + index + "/_bulk"); | ||
| request.addParameter("refresh", "true"); | ||
| request.setJsonEntity("{\"index\":{}\n{}\n" + "{\"index\":{}\n{}\n"); | ||
| client.performRequest(request); |
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.
Why is this needed? Creating an empty index is not enough?
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 think it's helpful to also check whether the behavior is correct with documents in an index with an empty mapping. That's why I'm indexing two empty documents.
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.
Ok. Thanks.
|
|
||
| a:i | b:l | c:i | ||
| ---------------+---------------+--------------- | ||
| 1 |2 |1 |
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.
Why is this COUNT 2?
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.
It's two empty docs in the index.
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.
Sorry, missed that.
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 also initially split the request body in two lines to make it more explicit like this:
request.setJsonEntity(
"{\"index\":{}\n{}\n" +
"{\"index\":{}\n{}\n");
but spotless didn't like it and I had to squash it into one line...
| 1:i | ||
| --------------- | ||
| 1 | ||
| 1 |
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.
Second 1 - where does it come from?
astefan
left a comment
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
Fixes elastic#53001 Adds support for querying indices without columns. Previously, such queries failed. (cherry picked from commit 6f93303)
Fixes elastic#53001 Adds support for querying indices without columns. Previously, such queries failed. (cherry picked from commit 6f93303)
|
Fixes #53001
Adds support for querying indices without columns. Previously, such queries failed.