Skip to content

refactor(native): Abstract session property provider#27253

Merged
pramodsatya merged 1 commit intoprestodb:masterfrom
pramodsatya:sp_refactor
Mar 17, 2026
Merged

refactor(native): Abstract session property provider#27253
pramodsatya merged 1 commit intoprestodb:masterfrom
pramodsatya:sp_refactor

Conversation

@pramodsatya
Copy link
Copy Markdown
Contributor

@pramodsatya pramodsatya commented Mar 3, 2026

Description

Refactors session properties provider into a base class.

Motivation and Context

Different native execution backends like cuDF can provide their own mapping of Presto to Velox configs in order to integrate Velox configs into Presto with the native session property provider (ref).
Required by #27204.

Impact

N/A.

Test Plan

Verified with existing e2e tests.

== NO RELEASE NOTE ==

Summary by Sourcery

Refactor native session properties into a reusable provider base class and reorganize related code into a dedicated properties module.

Enhancements:

  • Introduce a SessionPropertiesProvider base class encapsulating shared session property management, serialization, and Velox config mapping logic for reuse by different backends.
  • Update existing SessionProperties to inherit from the new provider and relocate session property code under a dedicated properties/session directory.
  • Extract a common bool-to-string utility into the shared Utils module for reuse across components.

Build:

  • Create a new presto_session_properties library, adjust main CMake configuration to use it, and add properties-specific CMake targets.

Tests:

  • Move native session properties tests into a dedicated properties/session test target and wire them into CMake.

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Mar 3, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Mar 3, 2026

Reviewer's Guide

Refactors native session property handling by extracting shared functionality into a reusable SessionPropertiesProvider base class, relocating session-related code into a dedicated properties/session module, and wiring build/tests and utility helpers to support backend-specific implementations.

Class diagram for refactored session properties provider hierarchy

classDiagram
  direction LR

  class SessionProperty {
    - protocol::SessionPropertyMetadata metadata_
    - std::optional<std::string> veloxConfig_
    - std::string value_
    + SessionProperty(name std::string, description std::string, typeSignature std::string, hidden bool, veloxConfig std::optional<std::string>, defaultValue std::string)
    + protocol::SessionPropertyMetadata getMetadata()
    + std::optional<std::string> getVeloxConfig()
    + std::string getValue()
    + void updateValue(value std::string)
    + bool operator==(other SessionProperty)
  }

  class SessionPropertiesProvider {
    <<abstract>>
    # std::unordered_map<std::string, std::shared_ptr<SessionProperty>> sessionProperties_
    + ~SessionPropertiesProvider()
    + std::string toVeloxConfig(name std::string)
    + json serialize()
    + bool hasVeloxConfig(key std::string)
    + void updateSessionPropertyValue(key std::string, value std::string)
    # void addSessionProperty(name std::string, description std::string, type facebook::velox::TypePtr, isHidden bool, veloxConfig std::optional<std::string>, defaultValue std::string)
  }

  class SessionProperties {
    + static SessionProperties* instance()
    + SessionProperties()
    + bool useVeloxGeospatialJoin()
    %% all k* constants omitted for brevity in diagram per instructions to avoid ellipses, but constants exist in code
  }

  SessionPropertiesProvider <|-- SessionProperties
  SessionPropertiesProvider o--> SessionProperty
Loading

File-Level Changes

Change Details Files
Extract shared session property logic into a reusable SessionPropertiesProvider base class and move SessionProperty definition there.
  • Introduce SessionPropertiesProvider interface providing addSessionProperty, toVeloxConfig, serialize, hasVeloxConfig, and updateSessionPropertyValue helpers
  • Relocate SessionProperty struct/class definition from SessionProperties.h into SessionPropertiesProvider.h for reuse by other providers
  • Implement SessionPropertiesProvider behavior in SessionPropertiesProvider.cpp, including lower-casing of type signatures and JSON serialization
presto-native-execution/presto_cpp/main/properties/session/SessionPropertiesProvider.h
presto-native-execution/presto_cpp/main/properties/session/SessionPropertiesProvider.cpp
presto-native-execution/presto_cpp/main/properties/session/SessionProperties.h
presto-native-execution/presto_cpp/main/properties/session/SessionProperties.cpp
Update SessionProperties to inherit from SessionPropertiesProvider and delegate common behavior to the base class.
  • Make SessionProperties derive from SessionPropertiesProvider and remove its local definitions of SessionProperty, addSessionProperty, toVeloxConfig, serialize, hasVeloxConfig, and updateSessionPropertyValue
  • Adjust constructor to call the inherited addSessionProperty and rely on the base class for metadata storage and mapping
  • Keep SessionProperties-specific APIs like useVeloxGeospatialJoin while using shared backing store
presto-native-execution/presto_cpp/main/properties/session/SessionProperties.h
presto-native-execution/presto_cpp/main/properties/session/SessionProperties.cpp
Reorganize session properties code under a new properties/session module and update includes, linkage, and tests accordingly.
  • Move SessionProperties.* and SessionPropertiesTest.cpp into main/properties/session and point all includes (server, query config, planner, tests) to the new path
  • Introduce CMakeLists for properties and properties/session, define presto_session_properties library there, and update main CMakeLists to add the new subdirectory
  • Split test wiring so session properties tests are built and run from the new module and remove the old test source from main/tests CMakeLists
presto-native-execution/presto_cpp/main/CMakeLists.txt
presto-native-execution/presto_cpp/main/properties/CMakeLists.txt
presto-native-execution/presto_cpp/main/properties/session/CMakeLists.txt
presto-native-execution/presto_cpp/main/properties/session/tests/CMakeLists.txt
presto-native-execution/presto_cpp/main/PrestoServer.cpp
presto-native-execution/presto_cpp/main/PrestoToVeloxQueryConfig.cpp
presto-native-execution/presto_cpp/main/QueryContextManager.cpp
presto-native-execution/presto_cpp/main/types/PrestoToVeloxQueryPlan.cpp
presto-native-execution/presto_cpp/main/tests/CMakeLists.txt
presto-native-execution/presto_cpp/main/properties/session/tests/SessionPropertiesTest.cpp
Centralize boolean-to-string conversion utility and reuse it in session properties initialization.
  • Add util::boolToString helper and declaration to common Utils.{h,cpp}
  • Replace local boolToString lambda in SessionProperties.cpp with calls to facebook::presto::util::boolToString for all boolean default values
presto-native-execution/presto_cpp/main/common/Utils.h
presto-native-execution/presto_cpp/main/common/Utils.cpp
presto-native-execution/presto_cpp/main/properties/session/SessionProperties.cpp

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

@pramodsatya pramodsatya marked this pull request as ready for review March 3, 2026 19:06
@pramodsatya pramodsatya requested review from a team as code owners March 3, 2026 19:06
@prestodb-ci prestodb-ci requested a review from a team March 3, 2026 19:06
@pramodsatya pramodsatya requested review from majetideepak and removed request for a team March 3, 2026 19:06
@prestodb-ci prestodb-ci requested review from ScrapCodes and libianoss and removed request for a team March 3, 2026 19:06
Copy link
Copy Markdown
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.

Repository not found

@pramodsatya
Copy link
Copy Markdown
Contributor Author

@majetideepak, could you please help review this change?

@majetideepak majetideepak requested review from czentgr and pdabre12 March 4, 2026 10:21
pdabre12
pdabre12 previously approved these changes Mar 4, 2026
Copy link
Copy Markdown
Contributor

@pdabre12 pdabre12 left a comment

Choose a reason for hiding this comment

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

Thanks @pramodsatya

/// Note: This interface should align with java coordinator.
class SessionProperty {
public:
SessionProperty(
Copy link
Copy Markdown
Contributor

@czentgr czentgr Mar 6, 2026

Choose a reason for hiding this comment

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

We had issues with this class where users did not call the constructor correctly.
For example, additions were made where the "hidden" column was set to a numeric default value. This is allowed due to implicit casting and wasn't caught at the time.
Now that we are refactoring this maybe we can a property builder replacing the addSessionProperty function with a builder scheme?

This would add to this PR. Maybe it would be left to another PR but probably won't gain too much traction if not done here?

@majetideepak @pdabre12 What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion @czentgr, I agree this is a pending cleanup, we could go with a builder, or have presto protocol generate the cpp class for us by modifying https://github.com/prestodb/presto/blob/master/presto-spi/src/main/java/com/facebook/presto/spi/session/PropertyMetadata.java.
However as you pointed out this cleanup is orthogonal to the PR and I would prefer to take it up separately and get this refactor in first. Getting this refactor in would help unblock #27204.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Created issue to track this: #27288.

pdabre12
pdabre12 previously approved these changes Mar 6, 2026
Copy link
Copy Markdown
Contributor

@pdabre12 pdabre12 left a comment

Choose a reason for hiding this comment

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

Thanks @pramodsatya.
Please address @czentgr 's suggestions in a follow-up PR.

@pramodsatya
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @czentgr, addressed the comments, could you please take another look?

@pramodsatya pramodsatya requested a review from czentgr March 7, 2026 03:12
@pramodsatya pramodsatya force-pushed the sp_refactor branch 2 times, most recently from b0329c3 to dbbb52f Compare March 10, 2026 18:41
majetideepak
majetideepak previously approved these changes Mar 17, 2026
@majetideepak
Copy link
Copy Markdown
Collaborator

@pramodsatya can you please rebase this with master? Thanks.

@pramodsatya
Copy link
Copy Markdown
Contributor Author

Thanks @majetideepak, rebased with master, could you please review/approve again?

@pramodsatya pramodsatya merged commit a26d4d8 into prestodb:master Mar 17, 2026
83 checks passed
@pramodsatya pramodsatya deleted the sp_refactor branch March 17, 2026 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants