The Apache Cassandra to Bigtable template copies a table from Apache Cassandra to Bigtable. This template requires minimal configuration and replicates the table structure in Cassandra as closely as possible in Bigtable.
The Apache Cassandra to Bigtable template is useful for the following:
- Migrating Apache Cassandra database when short downtime is acceptable.
- Periodically replicating Cassandra tables to Bigtable for global serving.
Pipeline requirements
- The target Bigtable table must exist before running the pipeline.
- Network connection between Dataflow workers and Apache Cassandra nodes.
Type conversion
The Apache Cassandra to Bigtable template automatically converts Apache Cassandra data types to Bigtable's data types.
Most primitives are represented the same way in Bigtable and Apache Cassandra; however, the following primitives are represented differently:
Date
andTimestamp
are converted toDateTime
objectsUUID
is converted toString
Varint
is converted toBigDecimal
Apache Cassandra also natively supports more complex types such as Tuple
, List
, Set
and Map
.
Tuples are not supported by this pipeline as there is no corresponding type in the Apache Beam.
For example, in Apache Cassandra you can have a column of type List
called "mylist" and values like those in the following table:
row | mylist |
---|---|
1 | (a,b,c) |
The pipeline expands the list column into three different columns (known in Bigtable as column qualifiers). The name of the columns is "mylist" but the pipeline appends the index of the item in the list, such as "mylist[0]".
row | mylist[0] | mylist[1] | mylist[2] |
---|---|---|---|
1 | a | b | c |
The pipeline handles sets the same way as lists but adds a suffix to denote if the cell is a key or a value.
row | mymap |
---|---|
1 | {"first_key":"first_value","another_key":"different_value"} |
After transformation, table appears as follows:
row | mymap[0].key | mymap[0].value | mymap[1].key | mymap[1].value |
---|---|---|---|---|
1 | first_key | first_value | another_key | different_value |
Primary key conversion
In Apache Cassandra, a primary key is defined using data definition language. The primary key is either simple, composite, or compound with the clustering columns. Bigtable supports manual row-key construction, ordered lexicographically on a byte array. The pipeline automatically collects information about the type of key and constructs a key based on best practices for building row-keys based on multiple values.
Template parameters
Required parameters
- cassandraHosts: The hosts of the Apache Cassandra nodes in a comma-separated list.
- cassandraKeyspace: The Apache Cassandra keyspace where the table is located.
- cassandraTable: The Apache Cassandra table to copy.
- bigtableProjectId: The Google Cloud project ID associated with the Bigtable instance.
- bigtableInstanceId: The ID of the Bigtable instance that the Apache Cassandra table is copied to.
- bigtableTableId: The name of the Bigtable table that the Apache Cassandra table is copied to.
Optional parameters
- cassandraPort: The TCP port to use to reach Apache Cassandra on the nodes. The default value is
9042
. - defaultColumnFamily: The name of the column family of the Bigtable table. The default value is
default
. - rowKeySeparator: The separator used to build row-keys. The default value is
#
. - splitLargeRows: The flag for enabling splitting of large rows into multiple MutateRows requests. Note that when a large row is split between multiple API calls, the updates to the row are not atomic. .
Run the template
Console
- Go to the Dataflow Create job from template page. Go to Create job from template
- In the Job name field, enter a unique job name.
- Optional: For Regional endpoint, select a value from the drop-down menu. The default
region is
us-central1
.For a list of regions where you can run a Dataflow job, see Dataflow locations.
- From the Dataflow template drop-down menu, select the Cassandra to Cloud Bigtable template.
- In the provided parameter fields, enter your parameter values.
- Click Run job.
gcloud
In your shell or terminal, run the template:
gcloud dataflow jobs run JOB_NAME \ --gcs-location gs://dataflow-templates-REGION_NAME/VERSION/Cassandra_To_Cloud_Bigtable \ --region REGION_NAME \ --parameters \ bigtableProjectId=BIGTABLE_PROJECT_ID,\ bigtableInstanceId=BIGTABLE_INSTANCE_ID,\ bigtableTableId=BIGTABLE_TABLE_ID,\ cassandraHosts=CASSANDRA_HOSTS,\ cassandraKeyspace=CASSANDRA_KEYSPACE,\ cassandraTable=CASSANDRA_TABLE
Replace the following:
JOB_NAME
: a unique job name of your choiceVERSION
: the version of the template that you want to useYou can use the following values:
latest
to use the latest version of the template, which is available in the non-dated parent folder in the bucket— gs://dataflow-templates-REGION_NAME/latest/- the version name, like
2023-09-12-00_RC00
, to use a specific version of the template, which can be found nested in the respective dated parent folder in the bucket— gs://dataflow-templates-REGION_NAME/
REGION_NAME
: the region where you want to deploy your Dataflow job—for example,us-central1
BIGTABLE_PROJECT_ID
: your project ID where Bigtable is locatedBIGTABLE_INSTANCE_ID
: the Bigtable instance idBIGTABLE_TABLE_ID
: the name of your Bigtable table nameCASSANDRA_HOSTS
: the Apache Cassandra host list; if multiple hosts are provided, follow the instruction on how to escape commasCASSANDRA_KEYSPACE
: the Apache Cassandra keyspace where table is locatedCASSANDRA_TABLE
: the Apache Cassandra table that needs to be migrated
API
To run the template using the REST API, send an HTTP POST request. For more information on the
API and its authorization scopes, see
projects.templates.launch
.
POST https://dataflow.googleapis.com/v1b3/projects/PROJECT_ID/locations/LOCATION/templates:launch?gcsPath=gs://dataflow-templates-LOCATION/VERSION/Cassandra_To_Cloud_Bigtable { "jobName": "JOB_NAME", "parameters": { "bigtableProjectId": "BIGTABLE_PROJECT_ID", "bigtableInstanceId": "BIGTABLE_INSTANCE_ID", "bigtableTableId": "BIGTABLE_TABLE_ID", "cassandraHosts": "CASSANDRA_HOSTS", "cassandraKeyspace": "CASSANDRA_KEYSPACE", "cassandraTable": "CASSANDRA_TABLE" }, "environment": { "zone": "us-central1-f" } }
Replace the following:
PROJECT_ID
: the Google Cloud project ID where you want to run the Dataflow jobJOB_NAME
: a unique job name of your choiceVERSION
: the version of the template that you want to useYou can use the following values:
latest
to use the latest version of the template, which is available in the non-dated parent folder in the bucket— gs://dataflow-templates-REGION_NAME/latest/- the version name, like
2023-09-12-00_RC00
, to use a specific version of the template, which can be found nested in the respective dated parent folder in the bucket— gs://dataflow-templates-REGION_NAME/
LOCATION
: the region where you want to deploy your Dataflow job—for example,us-central1
BIGTABLE_PROJECT_ID
: your project ID where Bigtable is locatedBIGTABLE_INSTANCE_ID
: the Bigtable instance idBIGTABLE_TABLE_ID
: the name of your Bigtable table nameCASSANDRA_HOSTS
: the Apache Cassandra host list; if multiple hosts are provided, follow the instruction on how to escape commasCASSANDRA_KEYSPACE
: the Apache Cassandra keyspace where table is locatedCASSANDRA_TABLE
: the Apache Cassandra table that needs to be migrated
What's next
- Learn about Dataflow templates.
- See the list of Google-provided templates.