airflow.contrib.operators.cassandra_to_gcs
¶
This module contains operator for copying data from Cassandra to Google cloud storage in JSON format.
Module Contents¶
-
class
airflow.contrib.operators.cassandra_to_gcs.
CassandraToGoogleCloudStorageOperator
(cql, bucket, filename, schema_filename=None, approx_max_file_size_bytes=1900000000, gzip=False, cassandra_conn_id='cassandra_default', google_cloud_storage_conn_id='google_cloud_default', delegate_to=None, *args, **kwargs)[source]¶ Bases:
airflow.models.BaseOperator
Copy data from Cassandra to Google cloud storage in JSON format
Note: Arrays of arrays are not supported.
- Parameters
cql (str) – The CQL to execute on the Cassandra table.
bucket (str) – The bucket to upload to.
filename (str) – The filename to use as the object name when uploading to Google cloud storage. A {} should be specified in the filename to allow the operator to inject file numbers in cases where the file is split due to size.
schema_filename (str) – If set, the filename to use as the object name when uploading a .json file containing the BigQuery schema fields for the table that was dumped from MySQL.
approx_max_file_size_bytes (long) – This operator supports the ability to split large table dumps into multiple files (see notes in the filename param docs above). This param allows developers to specify the file size of the splits. Check https://cloud.google.com/storage/quotas to see the maximum allowed file size for a single object.
cassandra_conn_id (str) – Reference to a specific Cassandra hook.
gzip (bool) – Option to compress file for upload
google_cloud_storage_conn_id (str) – Reference to a specific Google cloud storage hook.
delegate_to (str) – The account to impersonate, if any. For this to work, the service account making the request must have domain-wide delegation enabled.
-
_write_local_data_files
(self, cursor)[source]¶ Takes a cursor, and writes results to a local file.
- Returns
A dictionary where keys are filenames to be used as object names in GCS, and values are file handles to local files that contain the data for the GCS objects.
-
_write_local_schema_file
(self, cursor)[source]¶ Takes a cursor, and writes the BigQuery schema for the results to a local file system.
- Returns
A dictionary where key is a filename to be used as an object name in GCS, and values are file handles to local files that contains the BigQuery schema fields in .json format.
-
classmethod
convert_user_type
(cls, name, value)[source]¶ Converts a user type to RECORD that contains n fields, where n is the number of attributes. Each element in the user type class will be converted to its corresponding data type in BQ.
-
classmethod
convert_tuple_type
(cls, name, value)[source]¶ Converts a tuple to RECORD that contains n fields, each will be converted to its corresponding data type in bq and will be named ‘field_<index>’, where index is determined by the order of the tuple elements defined in cassandra.