Skip to content

Add SQL:2023 static method invocation#29385

Queued
martint wants to merge 1 commit into
trinodb:masterfrom
martint:static-methods
Queued

Add SQL:2023 static method invocation#29385
martint wants to merge 1 commit into
trinodb:masterfrom
martint:static-methods

Conversation

@martint
Copy link
Copy Markdown
Member

@martint martint commented May 8, 2026

Description

SQL:2023 specifies <static method invocation>T::method(args) — for functions
associated with a type. Trino has no equivalent today: every function lives in a single
global namespace, so the same SQL name cannot be reused across types (e.g. a parse
function on bigint and a different parse on date).

This change introduces the syntax and a new @StaticMethod SPI annotation. Functions
tagged with @StaticMethod("<type>") are registered against a receiver type and become
callable only as T::method(args). The two namespaces are independent:

  • method(args) cannot resolve to a static method.
  • T::method(args) cannot resolve to a regular function.

Example:

@ScalarFunction("parse")
@StaticMethod(StandardTypes.BIGINT)
@SqlType(StandardTypes.BIGINT)
public static long bigintParse(@SqlType(StandardTypes.VARCHAR) Slice value) { ... }

SELECT bigint::parse('42');  -- 42

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 `@StaticMethod` annotation to register a scalar function as a static method of a
  named type, invocable via `T::method(args)`. ({issue}`29385`)

@martint
Copy link
Copy Markdown
Member Author

martint commented May 8, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request adds SQL:2023 static method call syntax to Trino, enabling expressions like bigint::parse('42'). The implementation spans grammar rules, AST parsing, semantic analysis, function resolution, and query planning. A new @StaticMethod annotation marks scalar functions as receiver-type-scoped, while FunctionMetadata gains an optional receiverType field. The parser recognizes the :: operator between a qualified type and method name with arguments. Resolution filters scalar functions by receiver type, semantic analysis validates argument types, and translation converts static calls to IR function calls. Tests verify parsing, functional evaluation, type resolution failures, and method resolution failures.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.42.1)
core/trino-parser/src/main/java/io/trino/sql/parser/AstBuilder.java
core/trino-main/src/main/java/io/trino/sql/analyzer/ExpressionAnalyzer.java
core/trino-parser/src/test/java/io/trino/sql/parser/TestSqlParser.java

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/trino-main/src/main/java/io/trino/sql/analyzer/ExpressionAnalyzer.java`:
- Around line 1462-1511: visitStaticMethodCall currently skips the
argument-count guard used for regular calls; after computing argumentTypes via
getCallArgumentTypes in visitStaticMethodCall, add the same max-arguments check
used in the regular call path (the guard that throws
semanticException(TOO_MANY_ARGUMENTS, ... ) when argumentTypes.size() exceeds
the allowed maximum) before calling functionResolver.resolveStaticMethod so
static method calls produce the same error/reporting behavior as regular
function calls.

In `@core/trino-parser/src/main/java/io/trino/sql/tree/StaticMethodCall.java`:
- Around line 60-65: The getChildren() implementation in StaticMethodCall is
including the method Identifier (method) which is metadata, not an expression;
update StaticMethodCall.getChildren() to mirror FunctionCall by returning only
the argument expression nodes (arguments) and exclude the method Identifier so
generic expression walkers traverse just expressions; locate the getChildren()
method in class StaticMethodCall and remove the .add(method) step, ensuring it
returns an ImmutableList built from arguments only.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bae76faf-6af8-446f-bb2e-fdb783fe0ab6

📥 Commits

Reviewing files that changed from the base of the PR and between c545157 and 178aafa.

📒 Files selected for processing (19)
  • core/trino-grammar/src/main/antlr4/io/trino/grammar/sql/SqlBase.g4
  • core/trino-main/src/main/java/io/trino/metadata/FunctionResolver.java
  • core/trino-main/src/main/java/io/trino/operator/scalar/ParametricScalar.java
  • core/trino-main/src/main/java/io/trino/operator/scalar/ScalarHeader.java
  • core/trino-main/src/main/java/io/trino/sql/analyzer/ExpressionAnalyzer.java
  • core/trino-main/src/main/java/io/trino/sql/planner/TranslationMap.java
  • core/trino-main/src/test/java/io/trino/operator/scalar/TestStaticMethodCall.java
  • core/trino-parser/src/main/java/io/trino/sql/ExpressionFormatter.java
  • core/trino-parser/src/main/java/io/trino/sql/parser/AstBuilder.java
  • core/trino-parser/src/main/java/io/trino/sql/tree/AstVisitor.java
  • core/trino-parser/src/main/java/io/trino/sql/tree/DefaultTraversalVisitor.java
  • core/trino-parser/src/main/java/io/trino/sql/tree/ExpressionRewriter.java
  • core/trino-parser/src/main/java/io/trino/sql/tree/ExpressionTreeRewriter.java
  • core/trino-parser/src/main/java/io/trino/sql/tree/StaticMethodCall.java
  • core/trino-parser/src/test/java/io/trino/sql/parser/TestSqlParser.java
  • core/trino-parser/src/test/java/io/trino/sql/parser/TestSqlParserErrorHandling.java
  • core/trino-spi/pom.xml
  • core/trino-spi/src/main/java/io/trino/spi/function/FunctionMetadata.java
  • core/trino-spi/src/main/java/io/trino/spi/function/StaticMethod.java

@martint martint requested a review from kasiafi May 8, 2026 17:58
@martint martint force-pushed the static-methods branch 3 times, most recently from 178aafa to 08c3d5b Compare May 9, 2026 16:28
@martint martint requested review from Praveen2112 and ebyhr May 9, 2026 21:36
@ebyhr ebyhr removed their request for review May 10, 2026 23:15
Comment thread core/trino-main/src/main/java/io/trino/operator/scalar/ScalarHeader.java Outdated
@martint martint force-pushed the static-methods branch 2 times, most recently from 65fa2ca to 8f08322 Compare May 11, 2026 17:21
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.
@martint martint added this pull request to the merge queue May 12, 2026
@martint martint removed this pull request from the merge queue due to a manual request May 12, 2026
@martint martint added this pull request to the merge queue May 12, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 12, 2026
@martint martint added this pull request to the merge queue May 12, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 12, 2026
@martint martint added this pull request to the merge queue May 12, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 12, 2026
@martint martint added this pull request to the merge queue May 12, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 12, 2026
@martint martint added this pull request to the merge queue May 12, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 12, 2026
@martint martint added this pull request to the merge queue May 12, 2026
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.

3 participants