How do I create a partition table in BigQuery from Java?… here is a solution to the problem.
How do I create a partition table in BigQuery from Java?
I want to create a partitioned table (partitioned by fields of type DATE) from java in BigQuery. I searched a lot but didn’t have much information about this. The code I used is
TimePartitioning timePartitioning = TimePartitioning.of(TimePartitioning.Type.DAY);
timePartitioning.toBuilder().setField("col3");
TableDefinition tableDefinition = StandardTableDefinition.newBuilder().setSchema(schema2).setTimePartitioning(timePartitioning).build();
TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build();
bigquery.create(tableInfo);
Here, I have a few questions
- Even if we want to partition by date, should we use TimePartitioning?
- I can’t see the column names near “Partition Fields” in the BigQuery user interface. I used this As a reference. I have to use the TimePartitioning class instead of TimePartitioningBuilder because setTimePartitioning() only accepts TimePartitioning.
Solution
The easiest way to do this is to issue a standard query – if you can query from Java (have you already done this?). ), just send a query like this:
#standardSQL
CREATE TABLE `project.dataset.table`
(
x INT64 OPTIONS(description="An optional INTEGER field"),
y STRUCT<
a ARRAY<STRING> OPTIONS(description="A repeated STRING field"),
b BOOL
>,
date_column DATE
)
PARTITION BY date_column
CLUSTER BY i_recommend_you_to_choose_a_clustering_column