Skip to content

misc: Add method comments and update docs for distributed procedures#26890

Merged
hantangwangd merged 1 commit intoprestodb:masterfrom
hantangwangd:fix_comment_and_docs_for_procedures
Jan 10, 2026
Merged

misc: Add method comments and update docs for distributed procedures#26890
hantangwangd merged 1 commit intoprestodb:masterfrom
hantangwangd:fix_comment_and_docs_for_procedures

Conversation

@hantangwangd
Copy link
Member

Description

This PR updates the procedure development documentation to align with the interface and implementation logic adjustments in the distributed procedure code, and adds comments to some abstract methods in class DistributedProcedure.

Motivation and Context

Ensures the procedure development documentation more accurate.

Impact

N/A

Test Plan

N/A

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

== NO RELEASE NOTE ==

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 2, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates distributed procedure documentation to match the current interface and adds clarifying JavaDoc for key lifecycle methods in DistributedProcedure, including context creation and execution phases.

Sequence diagram for distributed procedure execution lifecycle

sequenceDiagram
    actor Client
    participant PrestoCoordinator
    participant ConnectorMetadata
    participant DistributedProcedure
    participant WorkerTasks

    Client->>PrestoCoordinator: invoke distributed procedure
    PrestoCoordinator->>ConnectorMetadata: get DistributedProcedure
    ConnectorMetadata-->>PrestoCoordinator: DistributedProcedure instance

    PrestoCoordinator->>DistributedProcedure: createContext(arguments)
    DistributedProcedure-->>PrestoCoordinator: ConnectorProcedureContext
    PrestoCoordinator->>ConnectorMetadata: bind ConnectorProcedureContext

    PrestoCoordinator->>DistributedProcedure: begin(session, procedureContext, tableLayoutHandle, arguments)
    DistributedProcedure-->>PrestoCoordinator: ConnectorDistributedProcedureHandle

    PrestoCoordinator->>WorkerTasks: execute distributed work using procedureHandle
    WorkerTasks-->>PrestoCoordinator: Collection<Slice> fragments

    PrestoCoordinator->>DistributedProcedure: finish(session, procedureContext, procedureHandle, fragments)
    DistributedProcedure-->>PrestoCoordinator: commit complete

    PrestoCoordinator-->>Client: procedure completed
Loading

Class diagram for DistributedProcedure lifecycle methods

classDiagram
    class DistributedProcedure {
        <<abstract>>
        -DistributedProcedureType type
        +DistributedProcedureType getType()
        +ConnectorDistributedProcedureHandle begin(ConnectorSession session, ConnectorProcedureContext procedureContext, ConnectorTableLayoutHandle tableLayoutHandle, Object[] arguments)
        +void finish(ConnectorSession session, ConnectorProcedureContext procedureContext, ConnectorDistributedProcedureHandle procedureHandle, Collection~Slice~ fragments)
        +ConnectorProcedureContext createContext(Object[] arguments)
    }
Loading

File-Level Changes

Change Details Files
Add lifecycle and context-creation JavaDoc to DistributedProcedure to clarify how distributed procedures are executed and how context is managed.
  • Document the responsibilities of begin() as preparatory work for starting distributed procedure execution.
  • Document the responsibilities of finish() as the centralized final commit after distributed execution completes.
  • Document createContext() as the hook for creating connector- or subtype-specific procedure context, its invocation timing, binding to ConnectorMetadata, and its use in begin() and finish().
presto-spi/src/main/java/com/facebook/presto/spi/procedure/DistributedProcedure.java
Align procedure development documentation with the current distributed procedure interface and lifecycle semantics.
  • Update developer docs for procedures to describe the distributed procedure lifecycle consistent with the begin/finish/createContext semantics.
  • Clarify how distributed procedure context is created, bound, and used during execution in the documentation.
presto-docs/src/main/sphinx/develop/procedures.rst

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

@hantangwangd hantangwangd marked this pull request as ready for review January 2, 2026 17:38
@hantangwangd hantangwangd requested review from a team, elharo and steveburnett as code owners January 2, 2026 17:38
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 2 issues, and left some high level feedback:

  • The new Javadoc comments for begin and finish should be updated to end with periods and use consistent verb tense/style (e.g., "Performs preparatory work..." vs "Perform the preparatory work...") to match the rest of the codebase’s Javadoc conventions.
  • Consider referencing the method names in comments with {@code begin()}/{@code finish()} (or {@link #begin(...)}/{@link #finish(...)}) in the createContext Javadoc so that tooling can correctly link them and the text is clearer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new Javadoc comments for `begin` and `finish` should be updated to end with periods and use consistent verb tense/style (e.g., "Performs preparatory work..." vs "Perform the preparatory work...") to match the rest of the codebase’s Javadoc conventions.
- Consider referencing the method names in comments with `{@code begin()}`/`{@code finish()}` (or `{@link #begin(...)}`/`{@link #finish(...)}`) in the `createContext` Javadoc so that tooling can correctly link them and the text is clearer.

## Individual Comments

### Comment 1
<location> `presto-spi/src/main/java/com/facebook/presto/spi/procedure/DistributedProcedure.java:47-55` </location>
<code_context>
-   public ConnectorProcedureContext createContext()
+   public ConnectorProcedureContext createContext(Object... arguments);

    /**
     * Performs the preparatory work required when starting the execution of this distributed procedure
</code_context>

<issue_to_address>
**suggestion:** Clarify what the returned handle from `begin` represents and its lifecycle.

The Javadoc for `begin` describes the preparatory work but not what the returned `ConnectorDistributedProcedureHandle` is contractually supposed to represent or how it should be used (e.g., whether it must be passed unchanged to `finish`, whether it needs to be stable/serializable). Please add a brief note on its semantics and lifecycle to make the API contract clearer for connector authors.

```suggestion
    /**
     * Performs the preparatory work required when starting the execution of this distributed procedure.
     * <p>
     * The returned {@link ConnectorDistributedProcedureHandle} represents the logical execution of a single
     * invocation of this distributed procedure. It:
     * <ul>
     *     <li>MUST be passed, unchanged, to {@link #finish(ConnectorSession, ConnectorProcedureContext, ConnectorDistributedProcedureHandle, Collection)}.</li>
     *     <li>MUST be stable for the lifetime of that invocation (i.e., identifies one specific run of the procedure).</li>
     *     <li>SHOULD be serializable and safe to use across tasks or nodes if the implementation needs to reference it in distributed execution.</li>
     * </ul>
     * Implementations may encode connector-specific state in the handle, but must treat it as an opaque token
     * from the perspective of callers.
     */
    public abstract ConnectorDistributedProcedureHandle begin(ConnectorSession session, ConnectorProcedureContext procedureContext, ConnectorTableLayoutHandle tableLayoutHandle, Object[] arguments);

    /**
     * Performs the work required for the final centralized commit, after all distributed execution tasks have
     * completed for a single invocation of this distributed procedure.
     * <p>
     * The {@code procedureHandle} passed here is the same handle returned from {@link #begin(ConnectorSession,
     * ConnectorProcedureContext, ConnectorTableLayoutHandle, Object[])} and identifies the procedure invocation
     * whose fragments are being finalized.
     */
    public abstract void finish(ConnectorSession session, ConnectorProcedureContext procedureContext, ConnectorDistributedProcedureHandle procedureHandle, Collection<Slice> fragments);
```
</issue_to_address>

### Comment 2
<location> `presto-docs/src/main/sphinx/develop/procedures.rst:428` </location>
<code_context>
-                   IcebergProcedureContext::new);
+                   ((session, procedureContext, tableHandle, fragments) -> finishCallDistributedProcedure(session, (IcebergProcedureContext) procedureContext, tableHandle, fragments)),
+                   arguments -> {
+                       checkArgument(arguments.length == 2, "invalid arguments count: " + arguments.length);
+                       checkArgument(arguments[0] instanceof Table && arguments[1] instanceof Transaction, "Invalid arguments, required: [Table, Transaction]");
+                       return new IcebergProcedureContext((Table) arguments[0], (Transaction) arguments[1]);
</code_context>

<issue_to_address>
**suggestion (typo):** Consider correcting the error message to use "argument count" instead of "arguments count".

"invalid arguments count" is ungrammatical. Please change it to "invalid argument count" or "invalid number of arguments" for clearer messaging.

```suggestion
                       checkArgument(arguments.length == 2, "invalid argument count: " + arguments.length);
```
</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.

@hantangwangd hantangwangd force-pushed the fix_comment_and_docs_for_procedures branch from 12bf780 to 09b4967 Compare January 3, 2026 09:07
Copy link
Contributor

@PingLiuPing PingLiuPing left a comment

Choose a reason for hiding this comment

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

Thank you.

@hantangwangd hantangwangd requested a review from tdcmeehan January 8, 2026 09:26
Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

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

LGTM! (docs)

Pull branch, local doc build, looks great. Thank you!

@hantangwangd hantangwangd merged commit 20f5ca5 into prestodb:master Jan 10, 2026
139 of 145 checks passed
@hantangwangd hantangwangd deleted the fix_comment_and_docs_for_procedures branch January 10, 2026 16:39
tdcmeehan pushed a commit to rdtr/presto that referenced this pull request Jan 14, 2026
…restodb#26890)

## Description

This PR updates the procedure development documentation to align with
the interface and implementation logic adjustments in the distributed
procedure code, and adds comments to some abstract methods in class
`DistributedProcedure`.

## Motivation and Context

Ensures the procedure development documentation more accurate.

## Impact

N/A

## Test Plan

N/A

## Contributor checklist

- [ ] Please make sure your submission complies with our [contributing
guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md),
in particular [code
style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style)
and [commit
standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#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](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines).
- [ ] Adequate tests were added if applicable.
- [ ] CI passed.
- [ ] If adding new dependencies, verified they have an [OpenSSF
Scorecard](https://securityscorecards.dev/#the-checks) score of 5.0 or
higher (or obtained explicit TSC approval for lower scores).

## Release Notes

```
== NO RELEASE NOTE ==
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants