Cassandra
Cassandra source connector
Description
Read data from Apache Cassandra in batch mode.
The Cassandra source supports two read modes:
- Single-table read with
cql. - Multi-table read with
tables_configs, where each entry contains onecql.
The source gets column names and data types from the result set returned by the configured CQL, so the CQL should return the columns that downstream steps need.
Key features
Data Type Mapping
| Cassandra Data Type | SeaTunnel Data Type |
|---|---|
| ascii | STRING |
| varchar/text | STRING |
| varint | STRING |
| uuid/timeuuid | STRING |
| inet | STRING |
| tinyint | BYTE |
| smallint | SHORT |
| int | INT |
| bigint/counter | LONG |
| float | FLOAT |
| double/decimal | DOUBLE |
| boolean | BOOLEAN |
| time | TIME |
| date | DATE |
| timestamp | TIMESTAMP |
| blob | ARRAY\<BYTE> |
| list | ARRAY |
| set | ARRAY |
| map | MAP |
Options
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| host | String | Yes | - | Cassandra cluster address. Use host:port, and separate multiple hosts with commas. |
| keyspace | String | Yes | - | Cassandra keyspace used by the session. |
| cql | String | No * | - | CQL used to read one table. |
| tables_configs | List\<Map> | No * | - | Multi-table read configuration. Each item must contain one cql. |
| username | String | No | - | Cassandra username. Configure it together with password. |
| password | String | No | - | Cassandra password. Configure it together with username. |
| datacenter | String | No | datacenter1 | Local datacenter name used by the Cassandra Java driver. |
| consistency_level | String | No | LOCAL_ONE | Read consistency level, such as LOCAL_ONE, ONE, QUORUM, or LOCAL_QUORUM. |
| common-options | No | - | Source plugin common parameters, such as plugin_output. |
* Exactly one of
cqlortables_configsmust be provided.
host [string]
Cassandra cluster address, the format is host:port , allowing multiple hosts to be specified. Such as
"cassandra1:9042,cassandra2:9042".
keyspace [string]
The Cassandra keyspace.
cql [String]
The query CQL used to read data from Cassandra. Use this for single-table reads. It is mutually
exclusive with tables_configs.
The connector uses the CQL result metadata to build the output schema. In normal cases, use a query
that returns real table columns, for example select * from source_table or
select id, name from source_table.
tables_configs [List\<Map>]
Multi-table read configuration. Each entry must contain a cql field with the query for that table.
It is mutually exclusive with root-level cql.
Do not configure the same source table more than once in tables_configs; the connector checks for
duplicate table names during startup.
Example entry:
{
cql = "SELECT id, name FROM keyspace.table1"
}
username [string]
Cassandra user username.
password [string]
Cassandra user password.
datacenter [String]
The Cassandra datacenter, default is datacenter1.
consistency_level [String]
The Cassandra read consistency level, default is LOCAL_ONE.
common-options
Source plugin common parameters. For details, see Source Common Options.
Notes
usernameandpasswordare a pair. Configure both when authentication is enabled; omit both when the cluster does not require authentication.datacentermust match the Cassandra cluster local datacenter name. The default isdatacenter1, which is also the common Testcontainers default.cqlandtables_configsare mutually exclusive. Usecqlfor one result table andtables_configswhen one source should read multiple Cassandra tables.- The source is a batch source. It reads the current query result and then finishes.
- A single CQL query is read as one source split. Increasing job parallelism does not split one Cassandra table scan automatically.
Examples
Single-table read
env {
parallelism = 1
job.mode = "BATCH"
}
source {
Cassandra {
host = "localhost:9042"
username = "cassandra"
password = "cassandra"
datacenter = "datacenter1"
keyspace = "test"
cql = "SELECT * FROM test.source_table"
plugin_output = "source_table"
}
}
sink {
Console {}
}
Multi-table read
env {
parallelism = 1
job.mode = "BATCH"
}
source {
Cassandra {
host = "localhost:9042"
username = "cassandra"
password = "cassandra"
datacenter = "datacenter1"
keyspace = "test"
tables_configs = [
{
cql = "select id, c_int from mt_source_a"
},
{
cql = "select id, c_int from mt_source_b"
}
]
}
}
sink {
Cassandra {
host = "localhost:9042"
username = "cassandra"
password = "cassandra"
datacenter = "datacenter1"
keyspace = "test"
table = "mt_sink_table"
}
}
Changelog
Change Log
| Change | Commit | Version |
|---|---|---|
| [improve] cassandra connector options (#8608) | https://github.com/apache/seatunnel/commit/d9201108cf | 2.3.10 |
| [Feature][Restapi] Allow metrics information to be associated to logical plan nodes (#7786) | https://github.com/apache/seatunnel/commit/6b7c53d03c | 2.3.9 |
| [Improve] Improve some connectors prepare check error message (#7465) | https://github.com/apache/seatunnel/commit/6930a25edd | 2.3.8 |
| [Improve][Common] Introduce new error define rule (#5793) | https://github.com/apache/seatunnel/commit/9d1b2582b2 | 2.3.4 |
[Improve] Remove use SeaTunnelSink::getConsumedType method and mark it as deprecated (#5755) | https://github.com/apache/seatunnel/commit/8de7408100 | 2.3.4 |
| [Feature][Connector V2] expose configurable options in Cassandra (#3681) | https://github.com/apache/seatunnel/commit/73f63a5044 | 2.3.2 |
| [Improve][build] Give the maven module a human readable name (#4114) | https://github.com/apache/seatunnel/commit/d7cd601051 | 2.3.1 |
| [Improve][Project] Code format with spotless plugin. (#4101) | https://github.com/apache/seatunnel/commit/a2ab166561 | 2.3.1 |
| [Feature][API & Connector & Doc] add parallelism and column projection interface (#3829) | https://github.com/apache/seatunnel/commit/b9164b8ba1 | 2.3.1 |
| [Improve][Connector-V2] The log outputs detailed exception stack information (#3805) | https://github.com/apache/seatunnel/commit/d0c6217f27 | 2.3.1 |
| [Improve][Connector-V2][Cassandra] Unified exception for cassandra source & sink connector (#3435) | https://github.com/apache/seatunnel/commit/28868797b7 | 2.3.0 |
| [Feature][Connector-V2][Cassandra] Add Cassandra Source And Sink Connector (#3229) | https://github.com/apache/seatunnel/commit/12268a6f4b | 2.3.0 |