Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a partitioned table in BigQuery from java?

I would like to create a partitioned table(partition by field which is of DATE type) in BigQuery from java. I searched a lot but there is not much information on 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 couple of questions

  1. Should we use TimePartitioning even if we want to partition by date?
  2. I am not able to see the column name near 'Partitioned on field' in the BigQuery UI. I used this as reference. I had to use TimePartitioning class and not TimePartitioningBuilder because setTimePartitioning() accepts TimePartitioning only.
like image 981
Abhishanth Padarthy Avatar asked Jan 26 '26 19:01

Abhishanth Padarthy


1 Answers

Easiest way would be to issue a standard query - if you can query from Java (which you already do?), 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
like image 89
Felipe Hoffa Avatar answered Jan 29 '26 07:01

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!