-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add support for WITH SESSION
clause
#23474
base: master
Are you sure you want to change the base?
Conversation
308303f
to
b9402ef
Compare
core/trino-grammar/src/main/antlr4/io/trino/grammar/sql/SqlBase.g4
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/SessionSpecificationEvaluator.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/SessionSpecificationEvaluator.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/SessionSpecificationEvaluator.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/SessionSpecificationEvaluator.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/SessionSpecificationEvaluator.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/SessionSpecificationEvaluator.java
Outdated
Show resolved
Hide resolved
validateSystemProperties(session, resolvedSessionSpecifications.systemProperties()); | ||
|
||
// Catalog session properties were already evaluated so we need to evaluate overrides | ||
if (session.getTransactionId().isPresent()) { |
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.
did you consider moving validation logic to Session
class where it already is? You can put it in Session.withProperties
maybe?
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 requires some changes for injecting AccessControl
to Session
. Added a TODO comment.
Object objectValue; | ||
|
||
try { | ||
objectValue = evaluatePropertyValue(specification.getValue(), type, session, plannerContext, accessControl, parameters); |
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.
Consider extracting common code from here and SetSessionTask
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 logic is a little different from SetSessionTask
. Added a TODO 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.
Looks nice. Some comments
b9402ef
to
644c66b
Compare
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 syntax generally looks good, but there's a point we should discuss.
When inline functions are present, the full query will look like this:
WITH
FUNCTION x(a BIGINT) RETURNS BIGINT RETURN 1
SESSION a = 1
SELECT * FROM t
The session properties are supposed to apply to everything, including function definitions. It would be clearer and less surprising to users if it were structured like this, instead:
WITH
SESSION a = 1
FUNCTION x(a BIGINT) RETURNS BIGINT RETURN 1
SELECT * FROM t
docs/src/main/sphinx/sql/select.md
Outdated
@@ -4,6 +4,7 @@ | |||
|
|||
```text | |||
[ WITH FUNCTION sql_routines ] | |||
[ WITH SESSION name = expression [, ...] ] |
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 incorrect per the proposed grammar. The combined form when inline functions are present would be:
WITH
FUNCTION x(a BIGINT) RETURNS BIGINT RETURN 1
SESSION a = 1
SELECT * FROM t
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.
Changed to [ WITH [ SESSION name = expression [, ...] ] [ FUNCTION sql_routines ] ]
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.
Did you forget to push a change? I don't see it reflected in the docs above.
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.
No, it was updated in a fixup commit. Let me squash commits.
644c66b
to
f8efa89
Compare
How do WITH SESSION, WITH FUNCTION, and WITH cte look like together? |
We can repeat WITH
SESSION time_zone_id = 'Europe/Warsaw'
FUNCTION foo() RETURNS varchar RETURN current_timezone()
WITH RECURSIVE t(n, x) AS (
VALUES (1, foo())
UNION ALL
SELECT n + 1, foo() FROM t WHERE n < 4
)
SELECT * FROM t; |
f8efa89
to
ff964ea
Compare
Addressed comments. |
core/trino-grammar/src/main/antlr4/io/trino/grammar/sql/SqlBase.g4
Outdated
Show resolved
Hide resolved
@@ -650,6 +656,15 @@ protected Void visitQuery(Query node, Integer indent) | |||
} | |||
builder.append('\n'); | |||
} | |||
|
|||
Iterator<SessionSpecification> sessionProperties = node.getSessionProperties().iterator(); |
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 should go above functions. Are we missing some tests? Otherwise, this should fail.
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 was moved in a fixup commit. Squashed commits.
core/trino-grammar/src/main/antlr4/io/trino/grammar/sql/SqlBase.g4
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/tree/SessionSpecification.java
Outdated
Show resolved
Hide resolved
docs/src/main/sphinx/sql/select.md
Outdated
@@ -4,6 +4,7 @@ | |||
|
|||
```text | |||
[ WITH FUNCTION sql_routines ] | |||
[ WITH SESSION name = expression [, ...] ] |
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.
Did you forget to push a change? I don't see it reflected in the docs above.
Co-Authored-By: Mateusz "Serafin" Gajewski <[email protected]>
Co-Authored-By: Mateusz "Serafin" Gajewski <[email protected]>
ff964ea
to
64df594
Compare
64df594
to
bf3228e
Compare
bf3228e
to
f4195ad
Compare
Description
Add support for
WITH SESSION
clause:The syntax with both sessions and SQL functions:
WITH SESSION
with DML is unsupported in this PR.Supersedes #21303
Release notes