Skip to content

Conversation

@feilong-liu
Copy link
Contributor

@feilong-liu feilong-liu commented Dec 21, 2025

Description

Add function description in function metadata, and populate this field in the Json function manager

Motivation and Context

Add function description in function metadata

Impact

Add function description in function metadata

Test Plan

Simple change, existing unit tests

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== NO RELEASE NOTE ==

@feilong-liu feilong-liu requested a review from a team as a code owner December 21, 2025 23:57
@prestodb-ci prestodb-ci added the from:Meta PR from Meta label Dec 21, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 21, 2025

Reviewer's Guide

Adds an optional additionalInformation field to FunctionMetadata and wires it through constructors and equality, then populates it from SQL-invoked functions in the JSON file-based function namespace manager using the function description.

Sequence diagram for sqlInvokedFunctionToMetadata mapping additionalInformation

sequenceDiagram
    participant Manager as JsonFileBasedFunctionNamespaceManager
    participant Func as SqlInvokedFunction
    participant Sig as Signature
    participant Params as List_Parameter
    participant RC as RoutineCharacteristics
    participant Meta as FunctionMetadata

    Manager->>Func: getSignature()
    Func-->>Manager: Sig
    Manager->>Sig: getName()
    Sig-->>Manager: QualifiedObjectName
    Manager->>Sig: getArgumentTypes()
    Sig-->>Manager: List_TypeSignature
    Manager->>Func: getParameters()
    Func-->>Manager: Params
    Manager->>Params: map getName()
    Params-->>Manager: List_String_argumentNames
    Manager->>Sig: getReturnType()
    Sig-->>Manager: TypeSignature
    Manager->>Sig: getKind()
    Sig-->>Manager: FunctionKind
    Manager->>Func: getRoutineCharacteristics()
    Func-->>Manager: RC
    Manager->>RC: getLanguage()
    RC-->>Manager: Language
    Manager->>Manager: getFunctionImplementationType(function)
    Manager-->>Manager: FunctionImplementationType
    Manager->>Func: isDeterministic()
    Func-->>Manager: boolean
    Manager->>Func: isCalledOnNullInput()
    Func-->>Manager: boolean
    Manager->>Func: getVersion()
    Func-->>Manager: FunctionVersion
    Manager->>Func: getDescription()
    Func-->>Manager: String_description
    Manager->>Meta: new FunctionMetadata(name, argTypes, argNames, returnType, kind, language, implementationType, deterministic, calledOnNullInput, version, description)
    Meta-->>Manager: FunctionMetadata_with_additionalInformation
Loading

Class diagram for updated FunctionMetadata and JSON namespace mapping

classDiagram
    class FunctionMetadata {
        - QualifiedObjectName name
        - Optional~OperatorType~ operatorType
        - List~TypeSignature~ argumentTypes
        - Optional~List~ argumentNames
        - TypeSignature returnType
        - FunctionKind functionKind
        - Optional~Language~ language
        - FunctionImplementationType implementationType
        - boolean deterministic
        - boolean calledOnNullInput
        - FunctionVersion version
        - ComplexTypeFunctionDescriptor descriptor
        - Optional~String~ additionalInformation
        + FunctionMetadata(name, argumentTypes, argumentNames, returnType, functionKind, language, implementationType, deterministic, calledOnNullInput)
        + FunctionMetadata(name, argumentTypes, argumentNames, returnType, functionKind, language, implementationType, deterministic, calledOnNullInput, version)
        + FunctionMetadata(name, argumentTypes, argumentNames, returnType, functionKind, language, implementationType, deterministic, calledOnNullInput, version, additionalInformation)
        + FunctionMetadata(name, argumentTypes, argumentNames, returnType, functionKind, language, implementationType, deterministic, calledOnNullInput, version, functionDescriptor)
        + FunctionMetadata(operatorType, argumentTypes, returnType, functionKind, implementationType, deterministic, calledOnNullInput, functionDescriptor)
        + Optional~String~ getAdditionalInformation()
        + boolean equals(obj)
        + int hashCode()
    }

    class JsonFileBasedFunctionNamespaceManager {
        # Collection~SqlInvokedFunction~ fetchFunctionsDirect(name)
        # FunctionMetadata sqlInvokedFunctionToMetadata(function)
    }

    class SqlInvokedFunction {
        + Signature getSignature()
        + List~Parameter~ getParameters()
        + RoutineCharacteristics getRoutineCharacteristics()
        + boolean isDeterministic()
        + boolean isCalledOnNullInput()
        + FunctionVersion getVersion()
        + String getDescription()
    }

    class Signature {
        + QualifiedObjectName getName()
        + List~TypeSignature~ getArgumentTypes()
        + TypeSignature getReturnType()
        + FunctionKind getKind()
    }

    class Parameter {
        + String getName()
    }

    class RoutineCharacteristics {
        + Language getLanguage()
    }

    JsonFileBasedFunctionNamespaceManager ..> SqlInvokedFunction : uses
    JsonFileBasedFunctionNamespaceManager ..> FunctionMetadata : creates
    SqlInvokedFunction --> Signature : has
    SqlInvokedFunction --> Parameter : has many
    SqlInvokedFunction --> RoutineCharacteristics : has
    FunctionMetadata --> ComplexTypeFunctionDescriptor : has
    FunctionMetadata --> FunctionVersion : has
    FunctionMetadata --> Language : optional
    FunctionMetadata --> OperatorType : optional
    FunctionMetadata --> FunctionKind : has
    FunctionMetadata --> TypeSignature : uses
Loading

File-Level Changes

Change Details Files
Extend FunctionMetadata to carry optional additional information about a function and ensure it participates in construction and equality.
  • Add Optional additionalInformation field to FunctionMetadata and initialize it in the primary constructor
  • Introduce an overload of the public FunctionMetadata constructor that accepts an additionalInformation string and passes it to the primary constructor
  • Update existing constructors and factory-style overloads to pass Optional.empty() for additionalInformation when not provided
  • Include additionalInformation in equals and hashCode computations
  • Expose additionalInformation via a new getAdditionalInformation() accessor
presto-spi/src/main/java/com/facebook/presto/spi/function/FunctionMetadata.java
Populate FunctionMetadata.additionalInformation for SQL-invoked functions managed by the JSON file-based namespace manager.
  • Override sqlInvokedFunctionToMetadata to construct FunctionMetadata using the new constructor that takes additionalInformation
  • Map SqlInvokedFunction properties (name, argument types/names, return type, kind, language, implementation type, determinism, null-input behavior, version, description) into the FunctionMetadata instance
presto-function-namespace-managers/src/main/java/com/facebook/presto/functionNamespace/json/JsonFileBasedFunctionNamespaceManager.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

feilong-liu added a commit to feilong-liu/presto that referenced this pull request Dec 22, 2025
Summary: Pull Request resolved: prestodb#26843

Differential Revision: D89610313
@feilong-liu feilong-liu changed the title decouple ai function registration misc: Add function description in function metadata Dec 22, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In the new FunctionMetadata constructor that accepts a String additionalInformation, you wrap it with Optional.of(additionalInformation); if function.getDescription() can be null (as is common for descriptions), this will NPE, so either enforce non-null at the caller or switch to accepting Optional<String> and using Optional.ofNullable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the new `FunctionMetadata` constructor that accepts a `String additionalInformation`, you wrap it with `Optional.of(additionalInformation)`; if `function.getDescription()` can be null (as is common for descriptions), this will NPE, so either enforce non-null at the caller or switch to accepting `Optional<String>` and using `Optional.ofNullable`.

## Individual Comments

### Comment 1
<location> `presto-function-namespace-managers/src/main/java/com/facebook/presto/functionNamespace/json/JsonFileBasedFunctionNamespaceManager.java:188` </location>
<code_context>
+                function.isDeterministic(),
+                function.isCalledOnNullInput(),
+                function.getVersion(),
+                function.getDescription());
+    }
+
</code_context>

<issue_to_address>
**question (bug_risk):** Clarify/ensure non-nullability of `function.getDescription()` when passing to the new `FunctionMetadata` constructor

Because the new `FunctionMetadata` overload wraps this in `Optional.of(...)`, any null from `SqlInvokedFunction.getDescription()` will cause an NPE. If `description` can be null/omitted, normalize it here (e.g., convert null to `Optional.empty()`) or change the constructor to accept an `Optional<String>` to match the internal representation.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Summary: Pull Request resolved: prestodb#26843

Differential Revision: D89610313
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants