https://cloud.google.com/bigquery/docs/creating-partitioned-tables shows how to create partitioned table in Python. I've been there, I've done that.
Now the question is, how to do the same thing with Java API? What is the corresponding Java code doing the same thing as the Python one below:
{
"tableReference": {
"projectId": "myProject",
"tableId": "table1",
"datasetId": "mydataset"
},
"timePartitioning": {
"type": "DAY"
}
}
Java with missing partitioning:
Job createTableJob = new Job();
JobConfiguration jobConfiguration = new JobConfiguration();
JobConfigurationLoad loadConfiguration = new JobConfigurationLoad();
createTableJob.setConfiguration(jobConfiguration);
jobConfiguration.setLoad(loadConfiguration);
TableReference tableReference = new TableReference()
.setProjectId("myProject")
.setDatasetId("mydataset")
.setTableId("table1");
loadConfiguration.setDestinationTable(tableReference);
// what should be place here to set DAY timePartitioning?
I'm using the newest api version from Maven Central Repository: com.google.apis:google-api-services-bigquery:v2-rev326-1.22.0
.
https://cloud.google.com/bigquery/docs/reference/v2/tables/insert https://cloud.google.com/bigquery/docs/reference/v2/tables#resource
Example Java code:
String projectId = "";
String datasetId = "";
Table content = new Table();
TimePartitioning timePartitioning = new TimePartitioning();
timePartitioning.setType("DAY");
timePartitioning.setExpirationMs(1L);
content.setTimePartitioning(timePartitioning);
Bigquery.Tables.Insert request = bigquery.tables().insert(projectId, datasetId, content);
Table response = request.execute();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With