Reputation: 179
I'm new to Google Cloud and would like to know best use cases on how to schedule queries and export them to Google Cloud Storage. I've seen documentations on how to manually export data but couldn't find anything specific on doing it in an automated way. Is there any best way on how to approach this ?
Thanks
Upvotes: 15
Views: 12570
Reputation: 1297
It is possible to create scheduled export jobs with the scheduled queries feature and EXPORT DATA
statement. For example, this script below backups data daily to GCS as Parquet files with SNAPPY compression. Each time the job is executed it takes all the data from the day before.
DECLARE backup_date DATE DEFAULT DATE_SUB(@run_date, INTERVAL 1 day);
EXPORT DATA
OPTIONS ( uri = CONCAT('gs://my-bucket/', CAST(backup_date AS STRING), '/*.parquet'),
format='PARQUET',
compression='SNAPPY',
overwrite=FALSE ) AS
SELECT
*
FROM
`my-project.my-dataset.my-table`
WHERE
DATE(timestamp) = backup_date
From the BiqQuery UI you can then create a scheduled query and set the trigger frequency and trigger time.
Upvotes: 10
Reputation: 131
Upvotes: 5