Skip to content

Upgrade to Cassandra Java Driver 4.x#298

Merged
tdcmeehan merged 1 commit intoprestodb:masterfrom
msmygit:master
Mar 6, 2026
Merged

Upgrade to Cassandra Java Driver 4.x#298
tdcmeehan merged 1 commit intoprestodb:masterfrom
msmygit:master

Conversation

@msmygit
Copy link
Contributor

@msmygit msmygit commented Feb 15, 2026

Resolves #297

Hello team 👋🏼

This is my 1st attempt on this project and I'd appreciate if someone could validate if I've followed all the project's guidelines and help approve and merge this enhancement followed by a release that I can use in the parent prestodb/presto project to upgrade Cassandra Java Driver to 4.x in the test framework codebase. Thank you in advance!

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 15, 2026

Reviewer's Guide

Upgrades the project from Datastax Cassandra Java Driver 3.x to Apache Cassandra Java Driver 4.x and adapts the Cassandra query execution and batch loading utilities, along with build and Docker example configuration, to the new driver APIs and metadata model.

Sequence diagram for executing a Cassandra query via updated CassandraQueryExecutor

sequenceDiagram
    actor TestCode
    participant CassandraQueryExecutor
    participant CqlSession
    participant CassandraCluster

    TestCode->>CassandraQueryExecutor: new CassandraQueryExecutor(configuration)
    CassandraQueryExecutor->>CqlSession: CqlSession.builder()
    CqlSession-->>CassandraQueryExecutor: session with contact point and local datacenter

    TestCode->>CassandraQueryExecutor: executeQuery(sql)
    CassandraQueryExecutor->>CassandraQueryExecutor: checkState(!session.isClosed())
    CassandraQueryExecutor->>CqlSession: execute(sql)
    CqlSession->>CassandraCluster: send CQL query
    CassandraCluster-->>CqlSession: ResultSet
    CqlSession-->>CassandraQueryExecutor: ResultSet

    CassandraQueryExecutor->>ResultSet: getColumnDefinitions()
    CassandraQueryExecutor->>CassandraQueryExecutor: build JDBC types and column names
    CassandraQueryExecutor->>ResultSet: iterate rows
    CassandraQueryExecutor->>Row: getObject(i) for each column
    CassandraQueryExecutor-->>TestCode: QueryResult

    TestCode->>CassandraQueryExecutor: close()
    CassandraQueryExecutor->>CqlSession: close()
Loading

Class diagram for updated CassandraQueryExecutor and CassandraBatchLoader

classDiagram
    class CassandraQueryExecutor {
        - Map<DataType, JDBCType> typeMapping
        - CqlSession session
        + CassandraQueryExecutor(Configuration configuration)
        + QueryResult executeQuery(String sql) QueryExecutionException
        + CqlSession getSession()
        + List<String> getColumnNames(String keySpace, String tableName)
        + boolean tableExists(String keySpace, String tableName)
        + List<String> getTableNames(String keySpace)
        + void close()
        - static JDBCType getJDBCType(DataType type)
    }

    class CassandraBatchLoader {
        - CqlSession session
        - String insertQuery
        - int columnsCount
        - int batchRowsCount
        + CassandraBatchLoader(CqlSession session, String tableName, List<String> columnNames, int batchRowsCount)
        + void load(Iterator<List<Object>> rows)
        - static BatchStatementBuilder createBatchStatementBuilder()
    }

    class CqlSession {
        + boolean isClosed()
        + ResultSet execute(String query)
        + PreparedStatement prepare(String query)
        + Metadata getMetadata()
        + void close()
    }

    class Metadata {
        + Optional<KeyspaceMetadata> getKeyspace(String keyspaceName)
    }

    class KeyspaceMetadata {
        + Optional<TableMetadata> getTable(String tableName)
        + Map<CqlIdentifier, TableMetadata> getTables()
    }

    class TableMetadata {
        + Map<CqlIdentifier, ColumnMetadata> getColumns()
        + CqlIdentifier getName()
    }

    class ColumnMetadata {
        + CqlIdentifier getName()
    }

    class ResultSet {
        + Iterable<Row> iterator()
        + Iterable<ColumnDefinition> getColumnDefinitions()
    }

    class ColumnDefinition {
        + DataType getType()
        + CqlIdentifier getName()
    }

    class Row {
        + Object getObject(int index)
    }

    class BatchStatementBuilder {
        + BatchStatementBuilder addStatement(BoundStatement statement)
        + BatchStatement build()
    }

    CassandraQueryExecutor --> CqlSession : uses
    CassandraQueryExecutor --> Metadata : reads metadata
    CassandraQueryExecutor --> KeyspaceMetadata : reads keyspace
    CassandraQueryExecutor --> TableMetadata : reads table
    CassandraQueryExecutor --> ColumnMetadata : reads columns
    CassandraQueryExecutor --> ResultSet : executes queries
    CassandraQueryExecutor --> ColumnDefinition : inspects columns
    CassandraQueryExecutor --> Row : reads row data

    CassandraBatchLoader --> CqlSession : uses
    CassandraBatchLoader --> BatchStatementBuilder : builds batches
Loading

File-Level Changes

Change Details Files
Migrate CassandraQueryExecutor from Cluster/Session API to CqlSession and the 4.x metadata/types APIs.
  • Replace Cluster/Session fields with a single CqlSession and update construction to use CqlSession.builder with InetSocketAddress and a hard-coded local datacenter.
  • Update DataType-to-JDBCType mapping to use the new DataTypes constants and fix null-check to guard against unsupported Cassandra types.
  • Adjust executeQuery to validate session state via isClosed, iterate ColumnDefinitions via the new iterable API, convert column and table names from objects to strings, and use row.getObject(i) instead of token-based access.
  • Rewrite metadata accessors (getColumnNames, tableExists, getTableNames) to use the new Metadata, KeyspaceMetadata, and TableMetadata Optional-based APIs with explicit error handling when keyspaces/tables are missing.
  • Simplify lifecycle management by closing the CqlSession directly in close() and removing the ensureConnected/Cluster lifecycle logic.
tempto-core/src/main/java/io/prestodb/tempto/internal/query/CassandraQueryExecutor.java
Adapt CassandraBatchLoader to the 4.x driver batch and session APIs.
  • Change the loader to depend on CqlSession instead of the old Session type for preparing and executing statements.
  • Replace BatchStatement usage with BatchStatementBuilder and DefaultBatchType.UNLOGGED, tracking batch size manually to enforce the configured batchRowsCount.
  • Retain existing validation of row column counts while updating bind/execution calls to work with the new batch builder API.
tempto-core/src/main/java/io/prestodb/tempto/internal/fulfillment/table/cassandra/CassandraBatchLoader.java
Update build and example Docker configuration to align with Cassandra driver 4.x and a newer Cassandra image.
  • Bump the Cassandra Java driver version property from 3.4.0 to 4.19.2 and switch the Maven coordinate to org.apache.cassandra:java-driver-core.
  • Upgrade the example Docker Cassandra image from cassandra:2.1.15 to cassandra:3.11.19 to better match the newer driver.
build.gradle
tempto-examples/docker/docker-compose.yml

Assessment against linked issues

Issue Objective Addressed Explanation
#297 Update the Cassandra Java driver dependency to a fully supported 4.x release using the new Apache Maven coordinates.
#297 Refactor Tempto's Cassandra integration code (query execution and batch loading) to use the Cassandra Java Driver 4.x API so that functionality remains working with the upgraded driver.
#297 Align example/testing Cassandra environment with the upgraded driver (e.g., compatible Cassandra Docker image version).

Possibly linked issues


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

Copy link

@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:

  • The CqlSession is built with a hardcoded local datacenter ("datacenter1"); consider wiring this through configuration (with a sensible default) so the code can work against clusters that don’t use that name.
  • The Maven coordinates for the 4.x driver are usually com.datastax.oss:java-driver-core; double-check that org.apache.cassandra:java-driver-core:${versions.cassandra} is the intended artifact and compatible with the rest of the stack.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `CqlSession` is built with a hardcoded local datacenter (`"datacenter1"`); consider wiring this through configuration (with a sensible default) so the code can work against clusters that don’t use that name.
- The Maven coordinates for the 4.x driver are usually `com.datastax.oss:java-driver-core`; double-check that `org.apache.cassandra:java-driver-core:${versions.cassandra}` is the intended artifact and compatible with the rest of the stack.

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR upgrades the Cassandra Java Driver from the outdated and End-of-Life 3.x series to the latest supported 4.x series. The driver has been donated to the Apache Foundation and moved to new Maven coordinates. This upgrade is necessary to allow the parent prestodb/presto project to modernize its testing framework dependencies.

Changes:

  • Updated Cassandra Java Driver dependency from DataStax 3.4.0 to Apache 4.19.2
  • Migrated from deprecated Cluster/Session API to the new CqlSession API
  • Updated Docker Cassandra image from 2.1.15 to 3.11.19 for compatibility

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
build.gradle Updated Cassandra driver Maven coordinates and version from com.datastax.cassandra:cassandra-driver-core:3.4.0 to org.apache.cassandra:java-driver-core:4.19.2
tempto-examples/docker/docker-compose.yml Upgraded Cassandra Docker image from 2.1.15 to 3.11.19 to support Driver 4.x requirements
tempto-core/src/main/java/io/prestodb/tempto/internal/query/CassandraQueryExecutor.java Migrated from Cluster/Session to CqlSession API, updated DataType constants, converted metadata APIs to Optional-based pattern, and fixed bug in getJDBCType method
tempto-core/src/main/java/io/prestodb/tempto/internal/fulfillment/table/cassandra/CassandraBatchLoader.java Migrated BatchStatement from mutable to builder pattern, updated session type to CqlSession

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@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 @msmygit. Have some comments.

Copy link

@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 @msmygit

@pdabre12
Copy link

pdabre12 commented Mar 5, 2026

@tdcmeehan Can you please have a look?

@tdcmeehan tdcmeehan merged commit 0da8dcf into prestodb:master Mar 6, 2026
3 checks passed
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.

Upgrade Cassandra Java Driver to the latest and fully supported 4.x series

4 participants