Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export from Google BigQuery into CloudSQL?

I want to dump data from BigQuery (i.e. reports) into a CloudSQL database, what is the best way to achieve this programatically?

I realise I could do this manually by running a BigQuery query, downloading it as a CSV, then uploading it through the Cloud console, but I want to do this programatically, preferably in Python/SQL.

like image 618
p_mcp Avatar asked Apr 06 '16 14:04

p_mcp


People also ask

How do I export from BigQuery?

Open the BigQuery page in the Google Cloud console. In the Explorer panel, expand your project and dataset, then select the table. In the details panel, click Export and select Export to Cloud Storage.

How do I convert a BQ table to CSV?

Follow the simple steps below to effortlessly Export BigQuery Table to CSV: Step 1: Go to the Google Cloud Console in BigQuery. Step 2: Navigate to the Explorer panel and select the desired table from your project. Step 3: From the details panel, click on the Export option and select Export to Cloud Storage.

Can BigQuery do ETL?

Approach 1: ETL with BigQuery. Use this approach to perform a one-time load of a small amount of data into BigQuery for analysis. You might also use this approach to prototype your dataset before you use automation with larger or multiple datasets.


1 Answers

If you would like to dump entire tables, you can use a combination of the BigQuery and Cloud SQL APIs to achieve this.

The BigQuery documentation has an API example in python for extracting a BigQuery table to Cloud Storage.

Once the data is in Cloud Storage, you can use the Cloud SQL Admin API to import the data into a MySQL table.

If you need more granular control, you can use the BigQuery API to perform the query, fetch the results, connect to the Cloud SQL instance and insert the data. This won't perform as well if the amount of data is large.

A more complex approach is to use Dataflow to write the data you are interested in to Cloud Storage and use the Cloud SQL API to import it.

(For my own curiosity, can you describe the use case for wanting the data in Cloud SQL instead of BigQuery? It will help me/us understand how our customers are using our product and where we can improve.)

like image 62
Vadim Avatar answered Oct 19 '22 15:10

Vadim