Create a clustered table in BigQuery from existing table with _PARTITIONTIME
up vote
0
down vote
favorite
I am trying to make a new clustered table, db.new_table
, that have the same data and schema as an existing table, db.old_table
, in BigQuery. The existing table have a pseudo column _PARTITIONTIME
, and I would like the new table to have this _PARTITIONTIME
pseudo column as well.
I have tried using DDL, with query like:
CREATE TABLE `db.new_table`
PARTITION BY DATE(_PARTITIONTIME)
CLUSTER BY field1, field2
AS SELECT * FROM `db.old_table`
WHERE _PARTITIONTIME > '1990-01-01'
However it failed because we cannot use PARTITION BY DATE(_PARTITIONTIME)
followed by AS SELECT ...
. as stated in https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
Is there a methods to do this? (create a new clustered table with the same exact schema and data from an old table partitioned by pseudo column _PARTITIONTIME )
Any answer and comment is appreciated, thanks.
Notes:
I can create a similar table without _PARTITIONTIME with query like:
CREATE TABLE `db.new_table`
PARTITION BY partition_date
CLUSTER BY field1, field2
AS SELECT DATE(_PARTITIONTIME) AS partition_date, * FROM `db.old_table`
WHERE _PARTITIONTIME > '1990-01-01'
However since a lot of things in the system depend on db.old_table
, the change in partition field from _PARTITIONTIME
to partition_date
would cause a lot of query changes... Therefore it would be much preferable if we can create the clustered table with exactly same schema and data.
google-bigquery ddl
add a comment |
up vote
0
down vote
favorite
I am trying to make a new clustered table, db.new_table
, that have the same data and schema as an existing table, db.old_table
, in BigQuery. The existing table have a pseudo column _PARTITIONTIME
, and I would like the new table to have this _PARTITIONTIME
pseudo column as well.
I have tried using DDL, with query like:
CREATE TABLE `db.new_table`
PARTITION BY DATE(_PARTITIONTIME)
CLUSTER BY field1, field2
AS SELECT * FROM `db.old_table`
WHERE _PARTITIONTIME > '1990-01-01'
However it failed because we cannot use PARTITION BY DATE(_PARTITIONTIME)
followed by AS SELECT ...
. as stated in https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
Is there a methods to do this? (create a new clustered table with the same exact schema and data from an old table partitioned by pseudo column _PARTITIONTIME )
Any answer and comment is appreciated, thanks.
Notes:
I can create a similar table without _PARTITIONTIME with query like:
CREATE TABLE `db.new_table`
PARTITION BY partition_date
CLUSTER BY field1, field2
AS SELECT DATE(_PARTITIONTIME) AS partition_date, * FROM `db.old_table`
WHERE _PARTITIONTIME > '1990-01-01'
However since a lot of things in the system depend on db.old_table
, the change in partition field from _PARTITIONTIME
to partition_date
would cause a lot of query changes... Therefore it would be much preferable if we can create the clustered table with exactly same schema and data.
google-bigquery ddl
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to make a new clustered table, db.new_table
, that have the same data and schema as an existing table, db.old_table
, in BigQuery. The existing table have a pseudo column _PARTITIONTIME
, and I would like the new table to have this _PARTITIONTIME
pseudo column as well.
I have tried using DDL, with query like:
CREATE TABLE `db.new_table`
PARTITION BY DATE(_PARTITIONTIME)
CLUSTER BY field1, field2
AS SELECT * FROM `db.old_table`
WHERE _PARTITIONTIME > '1990-01-01'
However it failed because we cannot use PARTITION BY DATE(_PARTITIONTIME)
followed by AS SELECT ...
. as stated in https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
Is there a methods to do this? (create a new clustered table with the same exact schema and data from an old table partitioned by pseudo column _PARTITIONTIME )
Any answer and comment is appreciated, thanks.
Notes:
I can create a similar table without _PARTITIONTIME with query like:
CREATE TABLE `db.new_table`
PARTITION BY partition_date
CLUSTER BY field1, field2
AS SELECT DATE(_PARTITIONTIME) AS partition_date, * FROM `db.old_table`
WHERE _PARTITIONTIME > '1990-01-01'
However since a lot of things in the system depend on db.old_table
, the change in partition field from _PARTITIONTIME
to partition_date
would cause a lot of query changes... Therefore it would be much preferable if we can create the clustered table with exactly same schema and data.
google-bigquery ddl
I am trying to make a new clustered table, db.new_table
, that have the same data and schema as an existing table, db.old_table
, in BigQuery. The existing table have a pseudo column _PARTITIONTIME
, and I would like the new table to have this _PARTITIONTIME
pseudo column as well.
I have tried using DDL, with query like:
CREATE TABLE `db.new_table`
PARTITION BY DATE(_PARTITIONTIME)
CLUSTER BY field1, field2
AS SELECT * FROM `db.old_table`
WHERE _PARTITIONTIME > '1990-01-01'
However it failed because we cannot use PARTITION BY DATE(_PARTITIONTIME)
followed by AS SELECT ...
. as stated in https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
Is there a methods to do this? (create a new clustered table with the same exact schema and data from an old table partitioned by pseudo column _PARTITIONTIME )
Any answer and comment is appreciated, thanks.
Notes:
I can create a similar table without _PARTITIONTIME with query like:
CREATE TABLE `db.new_table`
PARTITION BY partition_date
CLUSTER BY field1, field2
AS SELECT DATE(_PARTITIONTIME) AS partition_date, * FROM `db.old_table`
WHERE _PARTITIONTIME > '1990-01-01'
However since a lot of things in the system depend on db.old_table
, the change in partition field from _PARTITIONTIME
to partition_date
would cause a lot of query changes... Therefore it would be much preferable if we can create the clustered table with exactly same schema and data.
google-bigquery ddl
google-bigquery ddl
asked Nov 15 at 9:15
Yosua Michael
51
51
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You can just pre-create your day-partitioned, clustered table (on whatever fields) named db.new_table
using either BQ UI or bq
command.
Once the table is there, you can populate "for each day" as:
bq query --allow_large_results --append_table --noflatten_results --destination_table 'db.new_table$19900101' "select field1, field2, field3 from db.old_table where _PARTITIONTIME = '1990-01-01'";
Notice two things:
- You have to run this query for each day separately (which will cost you pretty much the same so don't worry about it).
- The
db.new_table$19900101
points to the partition of1990-01-01
indb.new_table
.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You can just pre-create your day-partitioned, clustered table (on whatever fields) named db.new_table
using either BQ UI or bq
command.
Once the table is there, you can populate "for each day" as:
bq query --allow_large_results --append_table --noflatten_results --destination_table 'db.new_table$19900101' "select field1, field2, field3 from db.old_table where _PARTITIONTIME = '1990-01-01'";
Notice two things:
- You have to run this query for each day separately (which will cost you pretty much the same so don't worry about it).
- The
db.new_table$19900101
points to the partition of1990-01-01
indb.new_table
.
add a comment |
up vote
0
down vote
accepted
You can just pre-create your day-partitioned, clustered table (on whatever fields) named db.new_table
using either BQ UI or bq
command.
Once the table is there, you can populate "for each day" as:
bq query --allow_large_results --append_table --noflatten_results --destination_table 'db.new_table$19900101' "select field1, field2, field3 from db.old_table where _PARTITIONTIME = '1990-01-01'";
Notice two things:
- You have to run this query for each day separately (which will cost you pretty much the same so don't worry about it).
- The
db.new_table$19900101
points to the partition of1990-01-01
indb.new_table
.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You can just pre-create your day-partitioned, clustered table (on whatever fields) named db.new_table
using either BQ UI or bq
command.
Once the table is there, you can populate "for each day" as:
bq query --allow_large_results --append_table --noflatten_results --destination_table 'db.new_table$19900101' "select field1, field2, field3 from db.old_table where _PARTITIONTIME = '1990-01-01'";
Notice two things:
- You have to run this query for each day separately (which will cost you pretty much the same so don't worry about it).
- The
db.new_table$19900101
points to the partition of1990-01-01
indb.new_table
.
You can just pre-create your day-partitioned, clustered table (on whatever fields) named db.new_table
using either BQ UI or bq
command.
Once the table is there, you can populate "for each day" as:
bq query --allow_large_results --append_table --noflatten_results --destination_table 'db.new_table$19900101' "select field1, field2, field3 from db.old_table where _PARTITIONTIME = '1990-01-01'";
Notice two things:
- You have to run this query for each day separately (which will cost you pretty much the same so don't worry about it).
- The
db.new_table$19900101
points to the partition of1990-01-01
indb.new_table
.
answered Nov 19 at 19:00
khan
1,78383051
1,78383051
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315974%2fcreate-a-clustered-table-in-bigquery-from-existing-table-with-partitiontime%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown