Search in sources :

Example 1 with TimePartitioning

use of com.google.cloud.bigquery.TimePartitioning in project google-cloud-java by GoogleCloudPlatform.

the class ITBigQueryTest method testCreateAndGetTable.

@Test
public void testCreateAndGetTable() {
    String tableName = "test_create_and_get_table";
    TableId tableId = TableId.of(DATASET, tableName);
    TimePartitioning partitioning = TimePartitioning.of(Type.DAY);
    StandardTableDefinition tableDefinition = StandardTableDefinition.newBuilder().setSchema(TABLE_SCHEMA).setTimePartitioning(partitioning).build();
    Table createdTable = bigquery.create(TableInfo.of(tableId, tableDefinition));
    assertNotNull(createdTable);
    assertEquals(DATASET, createdTable.getTableId().getDataset());
    assertEquals(tableName, createdTable.getTableId().getTable());
    Table remoteTable = bigquery.getTable(DATASET, tableName);
    assertNotNull(remoteTable);
    assertTrue(remoteTable.getDefinition() instanceof StandardTableDefinition);
    assertEquals(createdTable.getTableId(), remoteTable.getTableId());
    assertEquals(TableDefinition.Type.TABLE, remoteTable.getDefinition().getType());
    assertEquals(TABLE_SCHEMA, remoteTable.getDefinition().getSchema());
    assertNotNull(remoteTable.getCreationTime());
    assertNotNull(remoteTable.getLastModifiedTime());
    assertNotNull(remoteTable.<StandardTableDefinition>getDefinition().getNumBytes());
    assertNotNull(remoteTable.<StandardTableDefinition>getDefinition().getNumRows());
    assertEquals(partitioning, remoteTable.<StandardTableDefinition>getDefinition().getTimePartitioning());
    assertTrue(remoteTable.delete());
}
Also used : TableId(com.google.cloud.bigquery.TableId) Table(com.google.cloud.bigquery.Table) StandardTableDefinition(com.google.cloud.bigquery.StandardTableDefinition) TimePartitioning(com.google.cloud.bigquery.TimePartitioning) Test(org.junit.Test)

Aggregations

StandardTableDefinition (com.google.cloud.bigquery.StandardTableDefinition)1 Table (com.google.cloud.bigquery.Table)1 TableId (com.google.cloud.bigquery.TableId)1 TimePartitioning (com.google.cloud.bigquery.TimePartitioning)1 Test (org.junit.Test)1