presto icon indicating copy to clipboard operation
presto copied to clipboard

Implements #26762 : adds support for connecting to Astra DB

Open arvy opened this issue 1 week ago • 2 comments

Description

adds a new parameter to facilitate connecting to Astra DB

Motivation and Context

Ability to query data in Astra DB

Impact

none

Test Plan

Unit test: used mocked Cluster.Builder to verify parameter is handled properly. Functional test (manual): verified ability to query data in Astra DB via presto-cli

Contributor checklist

  • [x] Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • [x] 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.
  • [x] 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.

== RELEASE NOTES ==

Cassandra Connector Changes
* adds support for Astra DB (via new configuration property ``cassandra.astra-secure-connect-bundle-path``)

arvy avatar Dec 10 '25 06:12 arvy

Reviewer's Guide

Adds Astra DB support to the Cassandra connector by introducing a new configuration property for secure connect bundles, updating session creation to handle either contact points or Astra bundles, and adding focused tests and dependencies to validate the new behavior.

Sequence diagram for Cassandra session creation with Astra DB support

sequenceDiagram
    participant Connector as CassandraConnector
    participant Module as CassandraClientModule
    participant Config as CassandraClientConfig
    participant Builder as Cluster_Builder
    participant Cluster as Cluster
    participant Session as NativeCassandraSession
    participant RCluster as ReopeningCluster

    Connector->>Module: createCassandraSession(connectorId, config, extraColumnMetadataCodec)
    Module->>Cluster: builder()
    Cluster-->>Module: Builder
    Module->>Builder: withProtocolVersion(config.getProtocolVersion())
    Module->>Config: getAstraSecureConnectBundlePath()
    Config-->>Module: astraSecureConnectBundlePath

    alt astraSecureConnectBundlePath is null
        Module->>Config: getContactPoints()
        Config-->>Module: contactPoints
        Module->>Module: check contactPoints not empty
        loop for each contactPoint
            Module->>Builder: addContactPoint(contactPoint)
        end
    else astraSecureConnectBundlePath is set
        Module->>Module: assert contactPoints is null or empty
        Module->>Builder: withCloudSecureConnectBundle(File(astraSecureConnectBundlePath))
    end

    Module->>Builder: withPort(config.getNativeProtocolPort())
    Module->>Builder: withReconnectionPolicy(ExponentialReconnectionPolicy)
    Module->>Builder: withRetryPolicy(config.getRetryPolicy().getPolicy())
    Module->>Builder: withLoadBalancingPolicy(RoundRobinPolicy or DCAwareRoundRobinPolicy)
    Module->>Builder: withQueryOptions(QueryOptions)
    Module->>Builder: build()
    Builder-->>Module: Cluster

    Module->>RCluster: new ReopeningCluster(() -> Cluster)
    Module->>Session: new NativeCassandraSession(connectorId, extraColumnMetadataCodec, RCluster, noHostAvailableRetryTimeout, caseSensitiveNameMatchingEnabled)
    Module-->>Connector: CassandraSession

Class diagram for updated Cassandra client configuration and session creation

classDiagram
    class CassandraClientConfig {
        - ConsistencyLevel consistencyLevel
        - int fetchSize
        - List~String~ contactPoints
        - String astraSecureConnectBundlePath
        - int nativeProtocolPort
        - int partitionSizeForBatchSelect
        - int splitSize
        - boolean caseSensitiveNameMatchingEnabled
        + List~String~ getContactPoints()
        + CassandraClientConfig setContactPoints(String contactPoints)
        + String getAstraSecureConnectBundlePath()
        + setAstraSecureConnectBundlePath(String astraSecureConnectBundlePath)
        + int getNativeProtocolPort()
    }

    class CassandraClientModule {
        + configure(Binder binder)
        + createCassandraSession(CassandraConnectorId connectorId, CassandraClientConfig config, JsonCodec extraColumnMetadataCodec) CassandraSession
        + createCassandraSession(ClusterBuilder clusterBuilder, CassandraConnectorId connectorId, CassandraClientConfig config, JsonCodec extraColumnMetadataCodec) CassandraSession
    }

    class CassandraSession {
    }

    class NativeCassandraSession {
        + NativeCassandraSession(String connectorId, JsonCodec extraColumnMetadataCodec, ReopeningCluster reopeningCluster, Duration noHostAvailableRetryTimeout, boolean caseSensitiveNameMatchingEnabled)
    }

    class ReopeningCluster {
        + ReopeningCluster(ClusterFactory clusterFactory)
    }

    class Cluster {
        + static ClusterBuilder builder()
    }

    class ClusterBuilder {
        + ClusterBuilder withProtocolVersion(ProtocolVersion protocolVersion)
        + ClusterBuilder addContactPoint(String contactPoint)
        + ClusterBuilder withCloudSecureConnectBundle(File secureConnectBundle)
        + ClusterBuilder withPort(int port)
        + ClusterBuilder withReconnectionPolicy(ReconnectionPolicy policy)
        + ClusterBuilder withRetryPolicy(RetryPolicy policy)
        + ClusterBuilder withLoadBalancingPolicy(LoadBalancingPolicy policy)
        + ClusterBuilder withQueryOptions(QueryOptions options)
        + Cluster build()
    }

    CassandraClientModule --> CassandraClientConfig : uses
    CassandraClientModule --> CassandraSession : creates
    CassandraClientModule --> NativeCassandraSession : instantiates
    CassandraClientModule --> ReopeningCluster : wraps Cluster
    CassandraClientModule --> ClusterBuilder : configures
    CassandraClientConfig --> ClusterBuilder : provides connection configuration
    NativeCassandraSession --> ReopeningCluster : depends on
    ReopeningCluster --> Cluster : builds

File-Level Changes

Change Details Files
Extend Cassandra session creation to support Astra secure connect bundle configuration in addition to traditional contact points, with mutual exclusivity validation.
  • Refactor createCassandraSession to introduce an overload that accepts a Cluster.Builder, delegating from the original method
  • Configure Cluster.Builder with protocol version, reconnection and retry policies, and load balancing as before, but conditionally add contact points only when no Astra secure connect bundle path is configured
  • Add validation to prohibit simultaneous use of contact points and Astra secure connect bundle path
  • Use withCloudSecureConnectBundle when an Astra secure connect bundle path is provided
  • Build the Cluster once and pass it to ReopeningCluster instead of re-adding contact points on reopen
presto-cassandra/src/main/java/com/facebook/presto/cassandra/CassandraClientModule.java
Introduce Astra secure connect bundle configuration to Cassandra client configuration.
  • Add astraSecureConnectBundlePath field and corresponding getter
  • Add @Config("cassandra.astra-secure-connect-bundle-path") setter to bind the new configuration property
  • Remove @Size(min = 1) constraint from contactPoints to allow empty contact points when using Astra bundles
presto-cassandra/src/main/java/com/facebook/presto/cassandra/CassandraClientConfig.java
Add unit tests for Astra bundle vs contact point behavior and supporting test dependencies.
  • Add Mockito core and inline dependencies to the Cassandra module pom for testing
  • Introduce CassandraClientModuleTest to verify: contact-points-only mode adds all contact points; specifying both contact points and Astra bundle throws IllegalArgumentException; Astra-bundle-only mode invokes withCloudSecureConnectBundle
  • Mock Cluster.Builder with RETURNS_SELF to support fluent API verification
presto-cassandra/pom.xml
presto-cassandra/src/test/java/com/facebook/presto/cassandra/CassandraClientModuleTest.java
Update embedded Cassandra test container version.
  • Bump Cassandra Docker image in CassandraServer test helper from 2.1.16 to 3.11.19
presto-cassandra/src/test/java/com/facebook/presto/cassandra/CassandraServer.java

Possibly linked issues

  • #26762: PR adds the Astra secure connect bundle config and logic exactly as requested in the Astra DB issue.

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

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Dec 10 '25 06:12 sourcery-ai[bot]

CLA Missing ID CLA Not Signed

  • :x: The email address for the commit (e8cd1b1374870e988ae84b0ad76ebf128f36691a) is not linked to the GitHub account, preventing the EasyCLA check. Consult this Help Article and GitHub Help to resolve. (To view the commit's email address, add .patch at the end of this PR page's URL.) For further assistance with EasyCLA, please submit a support request ticket.