2016-10-24 6 views
2

https://cloud.google.com/bigquery/docs/creating-partitioned-tables zeigt, wie partitionierte Tabelle in Python erstellen. Ich war dort, das habe ich getan.Wie erstellt partitionierte BigQuery-Tabelle in Java

Jetzt ist die Frage, wie das Gleiche mit Java API zu tun? Was ist die entsprechende Java-Code das gleiche wie das unten Python tun:

{ 
    "tableReference": { 
    "projectId": "myProject", 
    "tableId": "table1", 
    "datasetId": "mydataset" 
    }, 
    "timePartitioning": { 
    "type": "DAY" 
    } 
} 

Java mit fehlenden Partitionierung:

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? 

ich die neueste Version von api Maven Zentrales Repository bin mit: com.google.apis:google-api-services-bigquery:v2-rev326-1.22.0.

Antwort

2

https://cloud.google.com/bigquery/docs/reference/v2/tables/insert https://cloud.google.com/bigquery/docs/reference/v2/tables#resource

Beispiel 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(); 
0

Bitte lassen Sie mich einen aktuelleren Art und Weise teilen partitionierten Tabellen zu erstellen (funktioniert mit Java API 0,32):

Schema schema = Schema.of(newFields); 
TimePartitioning timePartitioning = TimePartitioning.of(TimePartitioning.Type.DAY); 
TableDefinition tableDefinition = StandardTableDefinition.newBuilder() 
     .setSchema(schema) 
     .setTimePartitioning(timePartitioning) 
     .build(); 

TableId tableId = TableId.of(projectName, datasetName, tableName) 
TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build(); 
bigQuery.create(tableInfo); 
Verwandte Themen