Apache Cassandra to Bigtable template

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 and Timestamp are converted to DateTime objects
  • UUID is converted to String
  • Varint is converted to BigDecimal

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

  1. Go to the Dataflow Create job from template page.
  2. Go to Create job from template
  3. In the Job name field, enter a unique job name.
  4. 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.

  5. From the Dataflow template drop-down menu, select the Cassandra to Cloud Bigtable template.
  6. In the provided parameter fields, enter your parameter values.
  7. 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 choice
  • VERSION: the version of the template that you want to use

    You can use the following values:

  • 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 located
  • BIGTABLE_INSTANCE_ID: the Bigtable instance id
  • BIGTABLE_TABLE_ID: the name of your Bigtable table name
  • CASSANDRA_HOSTS: the Apache Cassandra host list; if multiple hosts are provided, follow the instruction on how to escape commas
  • CASSANDRA_KEYSPACE: the Apache Cassandra keyspace where table is located
  • CASSANDRA_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 job
  • JOB_NAME: a unique job name of your choice
  • VERSION: the version of the template that you want to use

    You can use the following values:

  • LOCATION: the region where you want to deploy your Dataflow job—for example, us-central1
  • BIGTABLE_PROJECT_ID: your project ID where Bigtable is located
  • BIGTABLE_INSTANCE_ID: the Bigtable instance id
  • BIGTABLE_TABLE_ID: the name of your Bigtable table name
  • CASSANDRA_HOSTS: the Apache Cassandra host list; if multiple hosts are provided, follow the instruction on how to escape commas
  • CASSANDRA_KEYSPACE: the Apache Cassandra keyspace where table is located
  • CASSANDRA_TABLE: the Apache Cassandra table that needs to be migrated

What's next