Skip to content

fix(optimizer): Fix bug in partitioning utils#27179

Open
feilong-liu wants to merge 1 commit intoprestodb:masterfrom
feilong-liu:fix_remote_func
Open

fix(optimizer): Fix bug in partitioning utils#27179
feilong-liu wants to merge 1 commit intoprestodb:masterfrom
feilong-liu:fix_remote_func

Conversation

@feilong-liu
Copy link
Contributor

@feilong-liu feilong-liu commented Feb 19, 2026

Description

Current isPartitionedOn function will return true when partition columns is empty, it's under the assumption that empty partition columns means no partitioning hence all data in one single node. However this is not the case for arbitrary distribution, where partition columns is empty but data is not in one single node. In this PR, I explicitly check that the partition is single node when partition columns is empty.

Motivation and Context

Bug fix

Impact

Fix a correctness bug

Test Plan

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 ==

Summary by Sourcery

Fix partitioning utility behavior for empty partitioning arguments and strengthen test coverage for partitioning semantics.

Bug Fixes:

  • Correct isPartitionedOn to only treat empty partitioning arguments as partitioned when using single-node or coordinator-only distributions.

Tests:

  • Add unit tests covering isPartitionedOn behavior across different distribution types, empty arguments, known constants, and matching/non-matching columns.

@feilong-liu feilong-liu requested review from a team and jaystarshot as code owners February 19, 2026 21:55
@prestodb-ci prestodb-ci added the from:Meta PR from Meta label Feb 19, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 19, 2026

Reviewer's Guide

Adjusts PartitioningUtils.isPartitionedOn semantics for empty partitioning arguments to distinguish truly single-node/coordinator-only distributions from multi-node distributions, and adds unit tests to cover the new behavior and existing partitioning scenarios.

Class diagram for updated partitioning types and isPartitionedOn

classDiagram
    class PartitioningUtils {
        +boolean isPartitionedOn(Partitioning partitioning, Collection columns, Set knownConstants)
    }

    class Partitioning {
        +List arguments
        +PartitioningHandle handle
        +List getArguments()
        +PartitioningHandle getHandle()
    }

    class PartitioningHandle {
        +boolean isSingleNode()
        +boolean isCoordinatorOnly()
    }

    class VariableReferenceExpression {
    }

    class RowExpression {
    }

    class Collection_VariableReferenceExpression {
    }

    class Set_VariableReferenceExpression {
    }

    PartitioningUtils --> Partitioning : uses
    PartitioningUtils --> VariableReferenceExpression : uses
    PartitioningUtils --> RowExpression : uses
    Partitioning --> PartitioningHandle : has
    Partitioning --> RowExpression : has arguments
    PartitioningUtils --> PartitioningHandle : checks distribution
    PartitioningUtils --> Collection_VariableReferenceExpression : columns (Collection<VariableReferenceExpression>)
    PartitioningUtils --> Set_VariableReferenceExpression : knownConstants (Set<VariableReferenceExpression>)
Loading

Flow diagram for updated isPartitionedOn partitioning logic

flowchart TD
    A[Start isPartitionedOn] --> B[Read partitioning.arguments]
    B --> C{arguments is empty?}
    C -- Yes --> D[Check partitioning.handle.isSingleNode]
    D --> E[Check partitioning.handle.isCoordinatorOnly]
    E --> F{isSingleNode or isCoordinatorOnly?}
    F -- Yes --> G[Return true]
    F -- No --> H[Return false]
    C -- No --> I[Iterate each RowExpression argument]
    I --> J[Ignore arguments that are constants using knownConstants]
    J --> K[Compare remaining arguments to columns]
    K --> L{All required columns covered by arguments?}
    L -- Yes --> G
    L -- No --> H
Loading

File-Level Changes

Change Details Files
Refine isPartitionedOn behavior when partitioning arguments are empty to depend on the partitioning handle rather than assuming single-node semantics.
  • Add an early return in isPartitionedOn that checks partitioning handles with no arguments and returns true only for single-node or coordinator-only distributions
  • Preserve existing per-argument partitioning checks for cases where partitioning arguments are present
presto-main-base/src/main/java/com/facebook/presto/sql/planner/optimizations/PartitioningUtils.java
Introduce unit test coverage for isPartitionedOn across different distribution handles, argument configurations, and known-constant columns.
  • Add TestPartitioningUtils class exercising empty-argument behavior for SINGLE, COORDINATOR, HASH, BROADCAST, ARBITRARY, and SOURCE distributions
  • Add tests for matching and non-matching partition columns and for columns treated as known constants
  • Add tests validating that single-node and coordinator distributions report partitioned-on for any requested columns even when partitioning arguments are empty
presto-main-base/src/test/java/com/facebook/presto/sql/planner/optimizations/TestPartitioningUtils.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 feilong-liu changed the title fix: Fix bug in partitioning utils fix(Optimizer): Fix bug in partitioning utils Feb 19, 2026
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 left some high level feedback:

  • Consider adding a short comment in isPartitionedOn above the early return for empty arguments to document why only single-node and coordinator-only partitioning are treated as partitioned in that case, since this is subtle and changes previous behavior.
  • The tests in TestPartitioningUtils repeatedly construct VariableReferenceExpression instances in the same way; you could extract a small helper method (e.g., variable(String name)) to reduce duplication and improve readability.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding a short comment in `isPartitionedOn` above the early return for empty arguments to document why only single-node and coordinator-only partitioning are treated as partitioned in that case, since this is subtle and changes previous behavior.
- The tests in `TestPartitioningUtils` repeatedly construct `VariableReferenceExpression` instances in the same way; you could extract a small helper method (e.g., `variable(String name)`) to reduce duplication and improve readability.

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.

@feilong-liu feilong-liu requested a review from kaikalur February 19, 2026 22:00
@feilong-liu feilong-liu changed the title fix(Optimizer): Fix bug in partitioning utils fix(optimizer): Fix bug in partitioning utils Feb 19, 2026
kaikalur
kaikalur previously approved these changes Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:Meta PR from Meta

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments