Add SQL:2023 non-static method invocation#29399
Open
martint wants to merge 2 commits into
Open
Conversation
764bd2f to
7b3cfec
Compare
SQL:2023 specifies <static method invocation>, T::method(args), for functions associated with a type. Trino has no equivalent today: every function lives in the global namespace, so the same SQL name cannot be reused across types. Functions tagged with the new @staticmethod SPI annotation are registered with a receiver type and become callable only as T::method(args). Plain method(args) calls cannot resolve to a static method, and T::method(args) cannot resolve to a regular function — the two namespaces are independent.
SQL:2023 specifies <method invocation>, expr.method(args), as a sibling of <static method invocation>. Where T::method(args) namespaces a function under a type, expr.method(args) dispatches on the runtime type of the receiver and passes it as the implicit self argument. Functions tagged with the new @instancemethod SPI annotation register with a receiver type taken from their first @SqlType parameter and become callable only as expr.method(args). A plain method(args) call cannot resolve to an instance method, mirroring the static-method namespace separation. The receiver expression form (expr).method(args) parses unambiguously as a method call. The bare A.B(args) form (where A is in scope as a column) keeps parsing as a routine invocation but, per SQL:2023 6.3 Syntax Rule 2, the analyzer treats it as a method invocation when one applies and only falls back to function resolution otherwise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #29385.
Description
SQL:2023 specifies
<method invocation>—expr.method(args)— as a sibling of<static method invocation>. WhereT::method(args)namespaces a function under atype,
expr.method(args)dispatches on the receiver's type and passes it as theimplicit self argument.
This change introduces the syntax and a new
@InstanceMethodSPI annotation.Functions tagged with
@InstanceMethodregister with a receiver type taken fromtheir first
@SqlTypeparameter and become callable only asexpr.method(args).A plain
method(args)call cannot resolve to an instance method, mirroring thestatic-method namespace separation introduced in #29385.
The receiver expression form
(expr).method(args)parses unambiguously as a methodcall. The bare
A.B(args)form (whereAis in scope as a column) keeps parsingas a routine invocation, but per SQL:2023 6.3 Syntax Rule 2 the analyzer treats it
as a method invocation when one applies, falling back to function resolution
otherwise.
Example:
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: