The BigQuery export to Parquet template is a batch pipeline that reads data from a BigQuery table and writes it to a Cloud Storage bucket in Parquet format. This template utilizes the BigQuery Storage API to export the data.
Pipeline requirements
- The input BigQuery table must exist before running the pipeline.
- The output Cloud Storage bucket must exist before running the pipeline.
Template parameters
Required parameters
- tableRef: The BigQuery input table location. For example,
your-project:your-dataset.your-table-name
. - bucket: The Cloud Storage folder to write the Parquet files to. For example,
gs://your-bucket/export/
.
Optional parameters
- numShards: The number of output file shards. The default value is
1
. - fields: A comma-separated list of fields to select from the input BigQuery table.
- rowRestriction: Read only rows which match the specified filter, which must be a SQL expression compatible with Google standard SQL (https://cloud.google.com/bigquery/docs/reference/standard-sql). If no value is specified, then all rows are returned.
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 BigQuery export to Parquet (via Storage API) template.
- In the provided parameter fields, enter your parameter values.
- Click Run job.
gcloud
In your shell or terminal, run the template:
gcloud dataflow flex-template run JOB_NAME \ --project=PROJECT_ID \ --template-file-gcs-location=gs://dataflow-templates-REGION_NAME/VERSION/flex/BigQuery_to_Parquet \ --region=REGION_NAME \ --parameters \ tableRef=BIGQUERY_TABLE,\ bucket=OUTPUT_DIRECTORY,\ numShards=NUM_SHARDS,\ fields=FIELDS
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/
REGION_NAME
: the region where you want to deploy your Dataflow job—for example,us-central1
BIGQUERY_TABLE
: your BigQuery table nameOUTPUT_DIRECTORY
: your Cloud Storage folder for output filesNUM_SHARDS
: the desired number of output file shardsFIELDS
: the comma-separated list of fields to select from the input BigQuery table
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/flexTemplates:launch { "launch_parameter": { "jobName": "JOB_NAME", "parameters": { "tableRef": "BIGQUERY_TABLE", "bucket": "OUTPUT_DIRECTORY", "numShards": "NUM_SHARDS", "fields": "FIELDS" }, "containerSpecGcsPath": "gs://dataflow-templates-LOCATION/VERSION/flex/BigQuery_to_Parquet", } }
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
BIGQUERY_TABLE
: your BigQuery table nameOUTPUT_DIRECTORY
: your Cloud Storage folder for output filesNUM_SHARDS
: the desired number of output file shardsFIELDS
: the comma-separated list of fields to select from the input BigQuery table
What's next
- Learn about Dataflow templates.
- See the list of Google-provided templates.