BigQueryCreateEmptyTableOperator

Google

Creates a new, empty table in the specified BigQuery dataset, optionally with schema.

View Source

Last Updated: May. 7, 2021

Access Instructions

Install the Google provider package into your Airflow environment.

Import the module into your DAG file and instantiate it with your desired params.

Parameters

project_idstrThe project to create the table into. (templated)
dataset_idstrThe dataset to create the table into. (templated)
table_idstrThe Name of the table to be created. (templated)
table_resourceDict[str, Any]Table resource as described in documentation: https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#Table If provided all other parameters are ignored.
schema_fieldslistIf set, the schema field list as defined here: https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.load.schemaExample:schema_fields=[{"name": "emp_name", "type": "STRING", "mode": "REQUIRED"}, {"name": "salary", "type": "INTEGER", "mode": "NULLABLE"}]
gcs_schema_objectstrFull path to the JSON file containing schema (templated). For example: gs://test-bucket/dir1/dir2/employee_schema.json
time_partitioningdictconfigure optional time partitioning fields i.e. partition by field, type and expiration as per API specifications.
bigquery_conn_idstr[Optional] The connection ID used to connect to Google Cloud and interact with the Bigquery service.
google_cloud_storage_conn_idstr[Optional] The connection ID used to connect to Google Cloud. and interact with the Google Cloud Storage service.
delegate_tostrThe account to impersonate using domain-wide delegation of authority, if any. For this to work, the service account making the request must have domain-wide delegation enabled.
labelsdicta dictionary containing labels for the table, passed to BigQueryExample (with schema JSON in GCS):CreateTable = BigQueryCreateEmptyTableOperator( task_id='BigQueryCreateEmptyTableOperator_task', dataset_id='ODS', table_id='Employees', project_id='internal-gcp-project', gcs_schema_object='gs://schema-bucket/employee_schema.json', bigquery_conn_id='airflow-conn-id', google_cloud_storage_conn_id='airflow-conn-id' )Corresponding Schema file (employee_schema.json):[ { "mode": "NULLABLE", "name": "emp_name", "type": "STRING" }, { "mode": "REQUIRED", "name": "salary", "type": "INTEGER" } ]Example (with schema in the DAG):CreateTable = BigQueryCreateEmptyTableOperator( task_id='BigQueryCreateEmptyTableOperator_task', dataset_id='ODS', table_id='Employees', project_id='internal-gcp-project', schema_fields=[{"name": "emp_name", "type": "STRING", "mode": "REQUIRED"}, {"name": "salary", "type": "INTEGER", "mode": "NULLABLE"}], bigquery_conn_id='airflow-conn-id-account', google_cloud_storage_conn_id='airflow-conn-id' )
viewdict[Optional] A dictionary containing definition for the view. If set, it will create a view instead of a table:
encryption_configurationdict[Optional] Custom encryption configuration (e.g., Cloud KMS keys). Example:encryption_configuration = { "kmsKeyName": "projects/testp/locations/us/keyRings/test-kr/cryptoKeys/test-key" }
locationstrThe location used for the operation.
cluster_fieldslist[Optional] The fields used for clustering. BigQuery supports clustering for both partitioned and non-partitioned tables.
impersonation_chainUnion[str, Sequence[str]]Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated).

Documentation

Creates a new, empty table in the specified BigQuery dataset, optionally with schema.

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. You can also create a table without schema.

See also

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

Was this page helpful?