/** Example of updating a table by changing its expiration. */ // [TARGET update(TableInfo, TableOption...)] // [VARIABLE "my_dataset_name"] // [VARIABLE "my_table_name"] public Table updateTableExpiration(String datasetName, String tableName) { // [START bigquery_update_table_expiration] Table beforeTable = bigquery.getTable(datasetName, tableName); // Set table to expire 5 days from now. long expirationMillis = DateTime.now().plusDays(5).getMillis(); TableInfo tableInfo = beforeTable.toBuilder().setExpirationTime(expirationMillis).build(); Table afterTable = bigquery.update(tableInfo); // [END bigquery_update_table_expiration] return afterTable; }
@Test public void testUpdate() { initializeExpectedTable(4); Table expectedUpdatedTable = expectedTable.toBuilder().setDescription("Description").build(); expect(bigquery.getOptions()).andReturn(mockOptions); expect(bigquery.update(eq(expectedTable))).andReturn(expectedUpdatedTable); replay(bigquery); initializeTable(); Table actualUpdatedTable = table.update(); compareTable(expectedUpdatedTable, actualUpdatedTable); }
@Test public void testUpdateWithOptions() { initializeExpectedTable(4); Table expectedUpdatedTable = expectedTable.toBuilder().setDescription("Description").build(); expect(bigquery.getOptions()).andReturn(mockOptions); expect(bigquery.update(eq(expectedTable), eq(BigQuery.TableOption.fields()))) .andReturn(expectedUpdatedTable); replay(bigquery); initializeTable(); Table actualUpdatedTable = table.update(BigQuery.TableOption.fields()); compareTable(expectedUpdatedTable, actualUpdatedTable); }
.setTimePartitioning(TimePartitioning.of(Type.DAY, 42L)) .build()) .build() .update(BigQuery.TableOption.fields(BigQuery.TableField.TIME_PARTITIONING)); assertThat( .setTimePartitioning(TimePartitioning.of(Type.DAY)) .build()) .build() .update(BigQuery.TableOption.fields(BigQuery.TableField.TIME_PARTITIONING)); assertThat(
@Test public void testUpdateTable() { String tableName = "test_update_table"; StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA); TableInfo tableInfo = TableInfo.newBuilder(TableId.of(DATASET, tableName), tableDefinition) .setDescription("Some Description") .setLabels(Collections.singletonMap("a", "b")) .build(); Table createdTable = bigquery.create(tableInfo); assertThat(createdTable.getDescription()).isEqualTo("Some Description"); assertThat(createdTable.getLabels()).containsExactly("a", "b"); Map<String, String> updateLabels = new HashMap<>(); updateLabels.put("x", "y"); updateLabels.put("a", null); Table updatedTable = bigquery.update( createdTable .toBuilder() .setDescription("Updated Description") .setLabels(updateLabels) .build()); assertThat(updatedTable.getDescription()).isEqualTo("Updated Description"); assertThat(updatedTable.getLabels()).containsExactly("x", "y"); updatedTable = bigquery.update(updatedTable.toBuilder().setLabels(null).build()); assertThat(updatedTable.getLabels()).isEmpty(); assertThat(createdTable.delete()).isTrue(); }
@Test public void testBuilder() { initializeExpectedTable(2); replay(bigquery); Table builtTable = new Table.Builder(serviceMockReturnsOptions, TABLE_ID1, TABLE_DEFINITION) .setCreationTime(CREATION_TIME) .setDescription(DESCRIPTION) .setEtag(ETAG) .setExpirationTime(EXPIRATION_TIME) .setFriendlyName(FRIENDLY_NAME) .setGeneratedId(GENERATED_ID) .setLastModifiedTime(LAST_MODIFIED_TIME) .setSelfLink(SELF_LINK) .build(); assertEquals(TABLE_ID1, builtTable.getTableId()); assertEquals(CREATION_TIME, builtTable.getCreationTime()); assertEquals(DESCRIPTION, builtTable.getDescription()); assertEquals(ETAG, builtTable.getEtag()); assertEquals(EXPIRATION_TIME, builtTable.getExpirationTime()); assertEquals(FRIENDLY_NAME, builtTable.getFriendlyName()); assertEquals(GENERATED_ID, builtTable.getGeneratedId()); assertEquals(LAST_MODIFIED_TIME, builtTable.getLastModifiedTime()); assertEquals(TABLE_DEFINITION, builtTable.getDefinition()); assertEquals(SELF_LINK, builtTable.getSelfLink()); assertSame(serviceMockReturnsOptions, builtTable.getBigQuery()); }
@Test public void testToBuilder() { initializeExpectedTable(4); replay(bigquery); compareTable(expectedTable, expectedTable.toBuilder().build()); }
/** Example of updating the table's information. */ // [TARGET update(TableOption...)] public Table update() { // [START ] Table updatedTable = table.toBuilder().setDescription("new description").build().update(); // [END ] return updatedTable; }
/** Example of updating a table by changing its description. */ public Table updateTableDescription(String datasetName, String tableName, String newDescription) { // [START bigquery_update_table_description] // String datasetName = "my_dataset_name"; // String tableName = "my_table_name"; // String newDescription = "new_description"; Table beforeTable = bigquery.getTable(datasetName, tableName); TableInfo tableInfo = beforeTable.toBuilder().setDescription(newDescription).build(); Table afterTable = bigquery.update(tableInfo); // [END bigquery_update_table_description] return afterTable; }