-
Notifications
You must be signed in to change notification settings - Fork 123
Fix parsing failure on WITH clauses #531
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
Fix parsing failure on WITH clauses #531
Conversation
mosabua
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.
The changes look ok but overall I think we are doing the wrong thing here .. we really should not try to parse the query since we are missing the full context .. only the coordinator really has that. I think in the long run we have to go down the route of farming this work out to a coordinator .. otherwise we end up pulling everything in and duplicating it so we kinda end up with the whole parsing code again.
ebyhr
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.
Please add a test.
gateway-ha/src/main/java/io/trino/gateway/ha/router/TrinoQueryProperties.java
Outdated
Show resolved
Hide resolved
I agree, even if it is quite helpful information. We should talk more on this next time. |
3e1cbb3 to
05d0600
Compare
05d0600 to
cfca1ed
Compare
gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingGroupSelector.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingGroupSelector.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingGroupSelector.java
Outdated
Show resolved
Hide resolved
cfca1ed to
f35c48c
Compare
gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingGroupSelector.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingGroupSelector.java
Outdated
Show resolved
Hide resolved
f35c48c to
998379d
Compare
willmostly
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.
it looks like we are preserving with clause names in the tables list - I think we should exclude them. Lets discuss if needed
gateway-ha/src/main/java/io/trino/gateway/ha/router/TrinoQueryProperties.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingGroupSelector.java
Outdated
Show resolved
Hide resolved
2802539 to
32ddf59
Compare
gateway-ha/src/main/java/io/trino/gateway/ha/router/TrinoQueryProperties.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingGroupSelector.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingGroupSelector.java
Outdated
Show resolved
Hide resolved
32ddf59 to
40593ae
Compare
gateway-ha/src/main/java/io/trino/gateway/ha/router/TrinoQueryProperties.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/main/java/io/trino/gateway/ha/router/TrinoQueryProperties.java
Outdated
Show resolved
Hide resolved
| case Table s -> { | ||
| // ignore temporary tables as they can have various table parts | ||
| if (!temporaryTables.contains(s.getName())) { | ||
| tableBuilder.add(qualifyName(s.getName())); | ||
| } | ||
| } | ||
| case TableFunctionInvocation s -> tableBuilder.add(qualifyName(s.getName())); | ||
| case WithQuery withQuery -> temporaryTables.add(QualifiedName.of(withQuery.getName().getValue())); |
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.
If you revert this to handle Query nodes, then we can bypass my concern about encountering a Table with a WithQuery name before it is added to temporaryTables. The concern is basically that node.getChildren() could return a list with the QueryBody before the With. If we explicitly process any With, then we can ensure that the names are collected before they are referenced. Something like
case Query query -> query.getWith().ifPresent(
with -> temporaryTables.addAll(with.getQueries().stream().map(WithQuery::getName).map(Identifier::getValue).map(QualifiedName::of).toList()));
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.
bypass my concern about encountering a Table with a WithQuery name before it is added to temporaryTables
I don't think we should worry too much about this as they say that WITH clause must always come before select in various docs.
- The WITH clause must always come at the beginning of the SQL statement, before any table is referenced in the main query. This placement allows the database engine to process the CTEs before executing the main query, ensuring that the defined temporary result sets are available for use throughout the rest of the statement
Oracle mysql docs also say that WITH clause must be placed at the beginning of the query or immediately preceding the SELECT statement in various contexts too.

But nonetheless it simplfies code so i changed it 👍
9f55135 to
0033d36
Compare
0033d36 to
5861e19
Compare
|
As discussed in the sync I think we should try to get this in asap and then cut 12 - I hope you can collab on that @willmostly @ebyhr and @Chaho12 |
willmostly
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!
|
Merging for release 12 - further fixups can be done as a follow up |
Description
Fix parsing failure on WITH clauses.
Additional context and related issues
Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text: