airflow.contrib.operators.gcs_to_bq

Module Contents

class airflow.contrib.operators.gcs_to_bq.GoogleCloudStorageToBigQueryOperator(bucket, source_objects, destination_project_dataset_table, schema_fields=None, schema_object=None, source_format='CSV', compression='NONE', create_disposition='CREATE_IF_NEEDED', skip_leading_rows=0, write_disposition='WRITE_EMPTY', field_delimiter=', ', max_bad_records=0, quote_character=None, ignore_unknown_values=False, allow_quoted_newlines=False, allow_jagged_rows=False, max_id_key=None, bigquery_conn_id='bigquery_default', google_cloud_storage_conn_id='google_cloud_default', delegate_to=None, schema_update_options=(), src_fmt_configs=None, external_table=False, time_partitioning=None, cluster_fields=None, autodetect=False, *args, **kwargs)[source]

Bases: airflow.models.BaseOperator

Loads files from Google cloud storage into BigQuery.

The schema to be used for the BigQuery table may be specified in one of two ways. You may either directly pass the schema fields in, or you may point the operator to a Google cloud storage object name. The object in Google cloud storage must be a JSON file with the schema fields in it.

See also

For more information on how to use this operator, take a look at the guide: GoogleCloudStorageToBigQueryOperator

Parameters
  • bucket (str) – The bucket to load from. (templated)

  • source_objects (list[str]) – List of Google cloud storage URIs to load from. (templated) If source_format is ‘DATASTORE_BACKUP’, the list must only contain a single URI.

  • destination_project_dataset_table (str) – The dotted (<project>.|<project>:)<dataset>.<table> BigQuery table to load data into. If <project> is not included, project will be the project defined in the connection json. (templated)

  • schema_fields (list) – If set, the schema field list as defined here: https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.load Should not be set when source_format is ‘DATASTORE_BACKUP’. Parameter must be defined if ‘schema_object’ is null and autodetect is False.

  • schema_object (str) – If set, a GCS object path pointing to a .json file that contains the schema for the table. (templated) Parameter must be defined if ‘schema_fields’ is null and autodetect is False.

  • source_format (str) – File format to export.

  • compression (str) – [Optional] The compression type of the data source. Possible values include GZIP and NONE. The default value is NONE. This setting is ignored for Google Cloud Bigtable, Google Cloud Datastore backups and Avro formats.

  • create_disposition (str) – The create disposition if the table doesn’t exist.

  • skip_leading_rows (int) – Number of rows to skip when loading from a CSV.

  • write_disposition (str) – The write disposition if the table already exists.

  • field_delimiter (str) – The delimiter to use when loading from a CSV.

  • max_bad_records (int) – The maximum number of bad records that BigQuery can ignore when running the job.

  • quote_character (str) – The value that is used to quote data sections in a CSV file.

  • ignore_unknown_values (bool) – [Optional] Indicates if BigQuery should allow extra values that are not represented in the table schema. If true, the extra values are ignored. If false, records with extra columns are treated as bad records, and if there are too many bad records, an invalid error is returned in the job result.

  • allow_quoted_newlines (bool) – Whether to allow quoted newlines (true) or not (false).

  • allow_jagged_rows (bool) – Accept rows that are missing trailing optional columns. The missing values are treated as nulls. If false, records with missing trailing columns are treated as bad records, and if there are too many bad records, an invalid error is returned in the job result. Only applicable to CSV, ignored for other formats.

  • max_id_key (str) – If set, the name of a column in the BigQuery table that’s to be loaded. This will be used to select the MAX value from BigQuery after the load occurs. The results will be returned by the execute() command, which in turn gets stored in XCom for future operators to use. This can be helpful with incremental loads–during future executions, you can pick up from the max ID.

  • bigquery_conn_id (str) – Reference to a specific BigQuery hook.

  • 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.

  • schema_update_options (list) – Allows the schema of the destination table to be updated as a side effect of the load job.

  • src_fmt_configs (dict) – configure optional fields specific to the source format

  • external_table (bool) – Flag to specify if the destination table should be a BigQuery external table. Default Value is False.

  • time_partitioning (dict) – configure optional time partitioning fields i.e. partition by field, type and expiration as per API specifications. Note that ‘field’ is not available in concurrency with dataset.table$partition.

  • cluster_fields (list[str]) – Request that the result of this load be stored sorted by one or more columns. This is only available in conjunction with time_partitioning. The order of columns given determines the sort order. Not applicable for external tables.

  • autodetect (bool) – [Optional] Indicates if we should automatically infer the options and schema for CSV and JSON sources. (Default: False). Parameter must be setted to True if ‘schema_fields’ and ‘schema_object’ are undefined. It is suggested to set to True if table are create outside of Airflow.

template_fields = ['bucket', 'source_objects', 'schema_object', 'destination_project_dataset_table'][source]
template_ext = ['.sql'][source]
ui_color = #f0eee4[source]
execute(self, context)[source]