Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating to Clustered Table

I have a table in BigQuery that is partitioned by day and I would like to move all rows to another table in BigQuery that is partitioned by day and also clustered by a couple fields. I know I can do this with a DML INSERT statement, but it's expensive. Is there a cheaper workaround? Thanks!

like image 716
David Weitz Avatar asked Mar 13 '26 19:03

David Weitz


1 Answers

Lazy migration, for the cost of a full table scan

CREATE TABLE x_new
PARTITION BY y
CLUSTER BY z
AS
SELECT * 
FROM x_old

Free migration, by exporting

Step 1:

CREATE TABLE x_new
PARTITION BY y
CLUSTER BY z
AS
SELECT * 
FROM x_old
LIMIT 0

Step 2: Export table x_old to GCS (Avro recommended).

Step 3: Load exported files from GCS into x_new.

like image 195
Felipe Hoffa Avatar answered Mar 16 '26 17:03

Felipe Hoffa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!