Skip to content

[FLINK-41444][Connectors/Cassandra] Upgrade Cassandra Java driver from 3.11.2 to 4.19.4 - #53

Draft
msmygit wants to merge 4 commits into
apache:mainfrom
msmygit:FLINK-41444-driver-4.19.4
Draft

msmygit wants to merge 4 commits into
apache:mainfrom
msmygit:FLINK-41444-driver-4.19.4

Conversation

@msmygit

@msmygit msmygit commented Nov 12, 2026

Copy link
Copy Markdown

Purpose of the change

Upgrade Cassandra Java Driver to 4.19.4, see FLINK-41444.

Brief change log

  • Connection API: ClusterBuilder is replaced by CassandraSessionBuilder (buildSession(CqlSessionBuilder)), and setClusterBuilder by setSessionBuilder. The SQL option cluster-builder-class is now
    session-builder-class.
  • POJO mapping: the connector maps @Entity / @CqlName classes itself at runtime, since the 4.x driver mapper only works through an annotation processor. MapperOptions and SimpleMapperOptions are replaced by
    CassandraMapperOptions.
  • Local datacenter: new local-datacenter SQL option and CassandraSinkBuilder.setLocalDatacenter. When unset, the datacenter is inferred from the hosts, so existing setHost jobs and SQL tables keep working.
  • Driver options: SQL options prefixed with driver. are passed straight to the driver configuration.
  • Astra: new secure-connect-bundle SQL option; when set, hosts, port and local datacenter are ignored.
  • java.util.Date: still works for timestamp columns through a codec the connector registers.
  • Partition key: the source's token-range queries now keep partition-key column order and quote case-sensitive names.
  • Docs: both the English and content.zh pages are updated, with new sections on connecting, driver configuration, POJO mapping, cloud databases and migrating from driver 3.

Things to know

  • Tuple reads change type: CassandraInputFormat now returns Instant, java.time.LocalDate and LocalTime for temporal columns, because the 3.x types no longer exist. This is in the migration section of the docs.
  • Mapper limitation: a nested @Entity property maps to a UDT, but collections of entities are rejected at startup with a clear error.

Verifying this change

Ran the CI build locally; mvn clean verify passes on both JDK 11 and JDK 17: 135 unit tests and 41 integration tests against a 2-node Cassandra 4.1.12, plus checkstyle, spotless, RAT, enforcer, japicmp and ArchUnit.

Impact and documentation


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code (Claude Fable 5.2)

@boring-cyborg

boring-cyborg Bot commented Nov 12, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! Please check out our contributing guidelines. (https://flink.apache.org/contributing/how-to-contribute.html)

@MartijnVisser MartijnVisser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The next release targets Flink 2.3 and 2.4 only, where the SinkFunction sinks don't compile. I would prefer to switch main to 2.3 and drop those sinks first (FLINK-41536), then land this without the sink ports. Can you rebase once that's in?

Comment thread pom.xml
<!-- For dependency convergence -->
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CI fails on dependency convergence. Pinning metrics-core 4.1.18 and jsr305 1.3.9 here fixes it, I checked with -Pcheck-convergence on 1.20.5.

this.cluster = clusterBuilder.getCluster();
this.maxSplitMemorySize = maxSplitMemorySize;
this.session = cluster.newSession();
this.session = sessionBuilder.getSession();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

getSession() connects, where cluster.newSession() didn't, and this runs on the coordinator thread. Can you open the session in prepareSplits instead?

* limitations under the License.
*/

package org.apache.flink.streaming.connectors.cassandra;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this and CassandraMapperOptions should move to org.apache.flink.connector.cassandra while we're breaking anyway, next to the source and the Sink V2 sink.

* @param <T> the type of the mapped POJO
* @return the mapper
*/
public static <T> PojoMapper<T> create(Class<T> pojoClass) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Naming and transients match the driver's generated code for the entities I tried, but @HierarchyScanStrategy is silently ignored and @PropertyStrategy fails with a misleading error. Please reject unsupported mapper annotations by name.

* Returns the partition key columns formatted to be used in a CQL query, in the order of the
* partition key. The names of the case-sensitive columns are double-quoted.
*/
public static String getPartitionKeyString(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Both cases fail on main with InvalidQueryException, so I've filed FLINK-41537 for a v3.3 backport. Can you move this fix to a separate commit for that ticket? Through SQL a quoted key still fails on a 2.3 cluster, the select list in CassandraTableFactory isn't quoted.

@msmygit
msmygit marked this pull request as draft November 20, 2026 14:42
Madhavan and others added 2 commits November 21, 2026 20:18
…y columns and keep their order in the split queries
…m 3.11.2 to 4.19.4

The connector now uses the Java Driver for Apache Cassandra 4.19.4
(org.apache.cassandra:java-driver-*), whose API is not compatible with
the version 3 of the driver.

Breaking changes:
- ClusterBuilder#buildCluster(Cluster.Builder) is replaced by
  CassandraSessionBuilder#buildSession(CqlSessionBuilder) and
  setClusterBuilder by setSessionBuilder. The SQL option
  'cluster-builder-class' is renamed to 'session-builder-class'.
- MapperOptions and SimpleMapperOptions are replaced by
  CassandraMapperOptions.
- POJOs are annotated with the annotations of the driver mapper
  (@entity, @CqlName). As the mapper of the driver only works with
  an annotation processor, the connector maps the POJOs at runtime.
- CassandraSinkBase#send returns a CompletionStage, Guava is not
  exposed by the driver anymore and is not bundled.
- CQL date, time and timestamp are mapped to the java.time types.
  java.util.Date is still supported for timestamp columns.

New options:
- 'local-datacenter' SQL option and CassandraSinkBuilder#setLocalDatacenter.
  When it is not set, the local datacenter is inferred from the hosts.
- 'driver.*' SQL options are passed to the driver configuration.
- 'secure-connect-bundle' SQL option to connect to a cloud database,
  the hosts and the local datacenter are then ignored.

The partition key columns used to build the token range queries of
the source now keep the order of the partition key and are quoted
when they are case-sensitive. This only changes the queries of the
tables with a composite or a case-sensitive partition key.

Generated-by: Claude Code (Claude Fable 5.2)
@msmygit
msmygit force-pushed the FLINK-41444-driver-4.19.4 branch from 656a4b5 to 812d088 Compare November 22, 2026 01:38

@MartijnVisser MartijnVisser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All five points from the last round are in, thanks. Can you rebase onto #56 and #54 once they're in and drop a39fca7? #54 covers FLINK-41537 including the SQL select list, on driver 4 that quoting is CqlIdentifier.fromInternal(name).asCql(true).

: new HashSet<>(Arrays.asList(transientProperties.value()));

final List<Property> properties = new ArrayList<>();
for (PropertyDescriptor descriptor : getPropertyDescriptors(pojoClass)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The driver's annotation processor maps 7 of 19 test entities differently: Boolean isX() and protected getters are dropped, and @CqlName, @Transient, @NamingStrategy and @TransientProperties on a superclass or interface are ignored. On reads that leaves fields unset without an error. Can the scan follow the processor, with it as the oracle in PojoMapperTest?

}
final String name = descriptor.getName();
final Field field = findField(pojoClass, name);
checkNoUnsupportedAnnotation(pojoClass, getter.getAnnotations());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Only the class-level check is tested, PojoMapperTest stays green with the getter, setter and field checks removed.

continue;
}
final Computed computed = getAnnotation(Computed.class, getter, field);
if (setter == null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The driver skips a getter without a setter, a derived getFullName() fails only here.

return doubleQuote(
Character.toUpperCase(javaName.charAt(0)) + javaName.substring(1));
case SNAKE_CASE_INSENSITIVE:
return toSnakeCase(javaName).toLowerCase();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs Locale.ROOT, with a Turkish default locale userId becomes user_ıd and the mapper throws.

}

/** @deprecated Use {@link #builder()} instead. */
@Deprecated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These signatures change anyway, so I'd drop the deprecated constructors in 4.0 instead of porting them.

* CQL `date`, `time` and `timestamp` are mapped to `java.time.LocalDate`, `java.time.LocalTime` and `java.time.Instant`,
see [temporal types](https://apache.github.io/cassandra-java-driver/4.19.0/core/temporal_types/). `java.util.Date` is still supported for `timestamp` columns.
Tuples read with `CassandraInputFormat` contain the `java.time` types.
* The request timeout of the driver, set by the SQL option `read-timeout`, now covers a request including its retries.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

setHost and custom builders go from driver 3's 12 s read timeout to a 2 s request timeout, I think that belongs here too.

- com.datastax.oss:native-protocol:1.5.2
- com.typesafe:config:1.4.1
- io.dropwizard.metrics:metrics-core:4.1.18
- org.apache.cassandra:java-driver-core-shaded:4.19.4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The shaded driver bundles relocated netty 4.1.138 and jackson 2.20.1, those need listing, and its BSD Protocol Buffers code needs licenses/LICENSE.protobuf.

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.

2 participants