use of com.google.cloud.bigquery.Table in project google-cloud-java by GoogleCloudPlatform.
the class BigQuerySnippets method getTableFromId.
/**
* Example of getting a table.
*/
// [TARGET getTable(TableId, TableOption...)]
// [VARIABLE "my_project_id"]
// [VARIABLE "my_dataset_name"]
// [VARIABLE "my_table_name"]
public Table getTableFromId(String projectId, String datasetName, String tableName) {
// [START getTableFromId]
TableId tableId = TableId.of(projectId, datasetName, tableName);
Table table = bigquery.getTable(tableId);
// [END getTableFromId]
return table;
}
use of com.google.cloud.bigquery.Table in project google-cloud-java by GoogleCloudPlatform.
the class BigQuerySnippets method listTablesFromId.
/**
* Example of listing the tables in a dataset.
*/
// [TARGET listTables(DatasetId, TableListOption...)]
// [VARIABLE "my_project_id"]
// [VARIABLE "my_dataset_name"]
public Page<Table> listTablesFromId(String projectId, String datasetName) {
// [START listTablesFromId]
DatasetId datasetId = DatasetId.of(projectId, datasetName);
Page<Table> tables = bigquery.listTables(datasetId, TableListOption.pageSize(100));
for (Table table : tables.iterateAll()) {
// do something with the table
}
// [END listTablesFromId]
return tables;
}
use of com.google.cloud.bigquery.Table in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQueryTest method testUpdateTableWithSelectedFields.
@Test
public void testUpdateTableWithSelectedFields() {
String tableName = "test_update_with_selected_fields_table";
StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition);
Table createdTable = bigquery.create(tableInfo);
assertNotNull(createdTable);
Table updatedTable = bigquery.update(tableInfo.toBuilder().setDescription("newDescr").build(), TableOption.fields(TableField.DESCRIPTION));
assertTrue(updatedTable.getDefinition() instanceof StandardTableDefinition);
assertEquals(DATASET, updatedTable.getTableId().getDataset());
assertEquals(tableName, updatedTable.getTableId().getTable());
assertEquals("newDescr", updatedTable.getDescription());
assertNull(updatedTable.getDefinition().getSchema());
assertNull(updatedTable.getLastModifiedTime());
assertNull(updatedTable.<StandardTableDefinition>getDefinition().getNumBytes());
assertNull(updatedTable.<StandardTableDefinition>getDefinition().getNumRows());
assertTrue(createdTable.delete());
}
use of com.google.cloud.bigquery.Table in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQueryTest method testCopyJob.
@Test
public void testCopyJob() throws InterruptedException, TimeoutException {
String sourceTableName = "test_copy_job_source_table";
String destinationTableName = "test_copy_job_destination_table";
TableId sourceTable = TableId.of(DATASET, sourceTableName);
StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition);
Table createdTable = bigquery.create(tableInfo);
assertNotNull(createdTable);
assertEquals(DATASET, createdTable.getTableId().getDataset());
assertEquals(sourceTableName, createdTable.getTableId().getTable());
TableId destinationTable = TableId.of(DATASET, destinationTableName);
CopyJobConfiguration configuration = CopyJobConfiguration.of(destinationTable, sourceTable);
Job remoteJob = bigquery.create(JobInfo.of(configuration));
remoteJob = remoteJob.waitFor();
assertNull(remoteJob.getStatus().getError());
Table remoteTable = bigquery.getTable(DATASET, destinationTableName);
assertNotNull(remoteTable);
assertEquals(destinationTable.getDataset(), remoteTable.getTableId().getDataset());
assertEquals(destinationTableName, remoteTable.getTableId().getTable());
assertEquals(TABLE_SCHEMA, remoteTable.getDefinition().getSchema());
assertTrue(createdTable.delete());
assertTrue(remoteTable.delete());
}
use of com.google.cloud.bigquery.Table in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQueryTest method testCreateAndGetTableWithSelectedField.
@Test
public void testCreateAndGetTableWithSelectedField() {
String tableName = "test_create_and_get_selected_fields_table";
TableId tableId = TableId.of(DATASET, tableName);
StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA);
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, TableOption.fields(TableField.CREATION_TIME));
assertNotNull(remoteTable);
assertTrue(remoteTable.getDefinition() instanceof StandardTableDefinition);
assertEquals(createdTable.getTableId(), remoteTable.getTableId());
assertEquals(TableDefinition.Type.TABLE, remoteTable.getDefinition().getType());
assertNotNull(remoteTable.getCreationTime());
assertNull(remoteTable.getDefinition().getSchema());
assertNull(remoteTable.getLastModifiedTime());
assertNull(remoteTable.<StandardTableDefinition>getDefinition().getNumBytes());
assertNull(remoteTable.<StandardTableDefinition>getDefinition().getNumRows());
assertNull(remoteTable.<StandardTableDefinition>getDefinition().getTimePartitioning());
assertTrue(remoteTable.delete());
}
Aggregations