-
Notifications
You must be signed in to change notification settings - Fork 25.8k
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
Changes from 3 commits
f78559b
0e85eae
1928df4
86c43c9
868edd7
46f77b9
19c54f5
4d1f92c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| selectConstAggregationWithGroupBy | ||
| SELECT 1 a, COUNT(*) b, MAX(1) c FROM no_cols GROUP BY a; | ||
|
|
||
| a:i | b:l | c:i | ||
| ---------------+---------------+--------------- | ||
| 1 |1 |1 | ||
| ; | ||
|
|
||
| subselectWithConst | ||
| SELECT 1, * FROM (SELECT * FROM no_cols) s; | ||
|
|
||
| 1:i | ||
| --------------- | ||
| 1 | ||
| ; | ||
|
|
||
| subselectWithInnerConst | ||
| SELECT * FROM (SELECT 1, * FROM no_cols) s; | ||
|
|
||
| 1:i | ||
| --------------- | ||
| 1 | ||
| ; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| selectStar | ||
| SELECT * FROM no_cols; | ||
| selectStarWithFilter | ||
| SELECT * FROM no_cols WHERE 2 > 1; | ||
| selectStarWithFilterAndLimit | ||
| SELECT * FROM no_cols WHERE 1 > 2 LIMIT 10; | ||
|
|
||
| selectCount | ||
| SELECT COUNT(*) FROM no_cols; | ||
| // awaits fix: https://github.com/elastic/elasticsearch/issues/74311 | ||
| // selectCountWithWhere | ||
| // SELECT COUNT(*) FROM no_cols WHERE 1 + 1 = 3; | ||
|
|
||
| selectConst | ||
| SELECT 1, 2, 3 FROM no_cols; | ||
| 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 | ||
|
||
| // subselect | ||
| // SELECT * FROM (SELECT * FROM no_cols) s; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| DROP TABLE IF EXISTS "no_cols"; | ||
| CREATE TABLE "no_cols" (); | ||
|
|
||
| INSERT INTO "no_cols" DEFAULT VALUES; | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -417,8 +417,9 @@ private List<NamedExpression> expandProjections(List<? extends NamedExpression> | |
| for (NamedExpression ne : projections) { | ||
| if (ne instanceof UnresolvedStar) { | ||
| List<NamedExpression> expanded = expandStar((UnresolvedStar) ne, output); | ||
|
|
||
| // the field exists, but cannot be expanded (no sub-fields) | ||
| if (expanded.isEmpty()) { | ||
| if (expanded == null) { | ||
|
||
| result.add(ne); | ||
| } else { | ||
| result.addAll(expanded); | ||
|
|
@@ -442,7 +443,7 @@ private List<NamedExpression> expandStar(UnresolvedStar us, List<Attribute> outp | |
| // a qualifier is specified - since this is a star, it should be a CompoundDataType | ||
| if (us.qualifier() != null) { | ||
| // resolve the so-called qualifier first | ||
| // since this is an unresolved start we don't know whether it's a path or an actual qualifier | ||
| // since this is an unresolved star we don't know whether it's a path or an actual qualifier | ||
| Attribute q = resolveAgainstList(us.qualifier(), output, true); | ||
|
|
||
| // the wildcard couldn't be expanded because the field doesn't exist at all | ||
|
|
@@ -455,6 +456,10 @@ private List<NamedExpression> expandStar(UnresolvedStar us, List<Attribute> outp | |
| else if (q.resolved() == false) { | ||
| return singletonList(q); | ||
| } | ||
| // qualifier resolves to a non-struct field and cannot be expanded | ||
| else if (DataTypes.isPrimitive(q.dataType())) { | ||
| return null; | ||
|
||
| } | ||
|
|
||
| // now use the resolved 'qualifier' to match | ||
| for (Attribute attr : output) { | ||
|
|
||
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.