Skip to content

Add SQL:2023 non-static method invocation#29399

Open
martint wants to merge 2 commits into
trinodb:masterfrom
martint:method-call
Open

Add SQL:2023 non-static method invocation#29399
martint wants to merge 2 commits into
trinodb:masterfrom
martint:method-call

Conversation

@martint
Copy link
Copy Markdown
Member

@martint martint commented May 9, 2026

Depends on #29385.

Description

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 receiver's type and passes it as the
implicit self argument.

This change introduces the syntax and a new @InstanceMethod SPI annotation.
Functions tagged with @InstanceMethod 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 introduced in #29385.

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, falling back to function resolution
otherwise.

Example:

@ScalarFunction("char_length")
@InstanceMethod
@SqlType(StandardTypes.BIGINT)
public static long varcharCharLength(@SqlType(StandardTypes.VARCHAR) Slice self) { ... }

SELECT ('hello').char_length();                            -- 5
SELECT s.char_length() FROM (VALUES VARCHAR 'hi') t(s);    -- 2

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:

# SPI
* Add `@InstanceMethod` annotation to register a scalar function as a non-static
  method of its receiver type, invocable via `expr.method(args)`.

@martint martint requested review from ebyhr and kasiafi May 9, 2026 16:36
@martint martint requested a review from Praveen2112 May 9, 2026 21:35
@ebyhr ebyhr removed their request for review May 10, 2026 23:15
@martint martint force-pushed the method-call branch 2 times, most recently from 764bd2f to 7b3cfec Compare May 11, 2026 17:21
martint added 2 commits May 12, 2026 08:42
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant