本文整理汇总了Java中com.google.cloud.bigquery.TableId.of方法的典型用法代码示例。如果您正苦于以下问题:Java TableId.of方法的具体用法?Java TableId.of怎么用?Java TableId.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.cloud.bigquery.TableId
的用法示例。
在下文中一共展示了TableId.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteTableFromId
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
/**
* Example of deleting a table.
*/
// [TARGET delete(TableId)]
// [VARIABLE "my_project_id"]
// [VARIABLE "my_dataset_name"]
// [VARIABLE "my_table_name"]
public Boolean deleteTableFromId(String projectId, String datasetName, String tableName) {
// [START deleteTableFromId]
TableId tableId = TableId.of(projectId, datasetName, tableName);
Boolean deleted = bigquery.delete(tableId);
if (deleted) {
// the table was deleted
} else {
// the table was not found
}
// [END deleteTableFromId]
return deleted;
}
示例2: createTable
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
/**
* Example of creating a table.
*/
// [TARGET create(TableInfo, TableOption...)]
// [VARIABLE "my_dataset_name"]
// [VARIABLE "my_table_name"]
// [VARIABLE "string_field"]
public Table createTable(String datasetName, String tableName, Schema schema) {
// [START createTable]
TableId tableId = TableId.of(datasetName, tableName);
// Table field definition
//Field field = Field.of(fieldNames[0], Field.Type.string());
TableDefinition tableDefinition = StandardTableDefinition.of(schema);
TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build();
Table table = bigquery.create(tableInfo);
// [END createTable]
return table;
}
示例3: listTableDataFromId
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
/**
* Example of listing table rows, specifying the page size.
*/
// [TARGET listTableData(TableId, TableDataListOption...)]
// [VARIABLE "my_dataset_name"]
// [VARIABLE "my_table_name"]
public Page<List<FieldValue>> listTableDataFromId(String datasetName, String tableName) {
// [START listTableDataFromId]
TableId tableIdObject = TableId.of(datasetName, tableName);
Page<List<FieldValue>> tableData =
bigquery.listTableData(tableIdObject, TableDataListOption.pageSize(100));
Iterator<List<FieldValue>> rowIterator = tableData.iterateAll();
while (rowIterator.hasNext()) {
List<FieldValue> row = rowIterator.next();
// do something with the row
}
// [END listTableDataFromId]
return tableData;
}
示例4: testRetrieveSchema
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
@Test
public void testRetrieveSchema() throws Exception {
final TableId table = TableId.of("test", "kafka_topic");
final String testTopic = "kafka-topic";
final String testSubject = "kafka-topic-value";
final String testAvroSchemaString =
"{\"type\": \"record\", "
+ "\"name\": \"testrecord\", "
+ "\"fields\": [{\"name\": \"f1\", \"type\": \"string\"}]}";
final SchemaMetadata testSchemaMetadata = new SchemaMetadata(1, 1, testAvroSchemaString);
SchemaRegistryClient schemaRegistryClient = mock(SchemaRegistryClient.class);
when(schemaRegistryClient.getLatestSchemaMetadata(testSubject)).thenReturn(testSchemaMetadata);
SchemaRegistrySchemaRetriever testSchemaRetriever = new SchemaRegistrySchemaRetriever(
schemaRegistryClient,
new AvroData(0)
);
Schema expectedKafkaConnectSchema =
SchemaBuilder.struct().field("f1", Schema.STRING_SCHEMA).name("testrecord").build();
assertEquals(expectedKafkaConnectSchema, testSchemaRetriever.retrieveSchema(table, testTopic));
}
示例5: testTableIdBuilder
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
@Test
public void testTableIdBuilder() {
final String project = "project";
final String dataset = "dataset";
final String table = "table";
final TableId tableId = TableId.of(project, dataset, table);
final PartitionedTableId partitionedTableId = new PartitionedTableId.Builder(tableId).build();
Assert.assertEquals(project, partitionedTableId.getProject());
Assert.assertEquals(dataset, partitionedTableId.getDataset());
Assert.assertEquals(table, partitionedTableId.getBaseTableName());
Assert.assertEquals(table, partitionedTableId.getFullTableName());
Assert.assertEquals(tableId, partitionedTableId.getBaseTableId());
Assert.assertEquals(tableId, partitionedTableId.getFullTableId());
}
示例6: testWithPartition
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
@Test
public void testWithPartition() {
final String dataset = "dataset";
final String table = "table";
final LocalDate partitionDate = LocalDate.of(2016, 9, 21);
final PartitionedTableId partitionedTableId =
new PartitionedTableId.Builder(dataset, table).setDayPartition(partitionDate).build();
final String expectedPartition = "20160921";
Assert.assertEquals(dataset, partitionedTableId.getDataset());
Assert.assertEquals(table, partitionedTableId.getBaseTableName());
Assert.assertEquals(table + "$" + expectedPartition, partitionedTableId.getFullTableName());
final TableId expectedBaseTableId = TableId.of(dataset, table);
final TableId expectedFullTableId = TableId.of(dataset, table + "$" + expectedPartition);
Assert.assertEquals(expectedBaseTableId, partitionedTableId.getBaseTableId());
Assert.assertEquals(expectedFullTableId, partitionedTableId.getFullTableId());
}
示例7: testWithEpochTimePartition
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
@Test
public void testWithEpochTimePartition() {
final String dataset = "dataset";
final String table = "table";
final long utcTime = 1509007584334L;
final PartitionedTableId partitionedTableId =
new PartitionedTableId.Builder(dataset, table).setDayPartition(utcTime).build();
final String expectedPartition = "20171026";
Assert.assertEquals(dataset, partitionedTableId.getDataset());
Assert.assertEquals(table, partitionedTableId.getBaseTableName());
Assert.assertEquals(table + "$" + expectedPartition, partitionedTableId.getFullTableName());
final TableId expectedBaseTableId = TableId.of(dataset, table);
final TableId expectedFullTableId = TableId.of(dataset, table + "$" + expectedPartition);
Assert.assertEquals(expectedBaseTableId, partitionedTableId.getBaseTableId());
Assert.assertEquals(expectedFullTableId, partitionedTableId.getFullTableId());
}
示例8: testNonAutoCreateTablesFailure
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
@Test(expected = BigQueryConnectException.class)
public void testNonAutoCreateTablesFailure() {
final String dataset = "scratch";
final String existingTableTopic = "topic-with-existing-table";
final String nonExistingTableTopic = "topic-without-existing-table";
final TableId existingTable = TableId.of(dataset, "topic_with_existing_table");
final TableId nonExistingTable = TableId.of(dataset, "topic_without_existing_table");
Map<String, String> properties = propertiesFactory.getProperties();
properties.put(BigQuerySinkConnectorConfig.TABLE_CREATE_CONFIG, "false");
properties.put(BigQuerySinkConfig.SANITIZE_TOPICS_CONFIG, "true");
properties.put(BigQuerySinkConfig.DATASETS_CONFIG, String.format(".*=%s", dataset));
properties.put(
BigQuerySinkConfig.TOPICS_CONFIG,
String.format("%s, %s", existingTableTopic, nonExistingTableTopic)
);
BigQuery bigQuery = mock(BigQuery.class);
Table fakeTable = mock(Table.class);
when(bigQuery.getTable(existingTable)).thenReturn(fakeTable);
when(bigQuery.getTable(nonExistingTable)).thenReturn(null);
BigQuerySinkConnector testConnector = new BigQuerySinkConnector(bigQuery);
testConnector.start(properties);
}
示例9: getTableFromId
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
/**
* 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;
}
示例10: writeToTable
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
/**
* Example of creating a channel with which to write to a table.
*/
// [TARGET writer(WriteChannelConfiguration)]
// [VARIABLE "my_dataset_name"]
// [VARIABLE "my_table_name"]
// [VARIABLE "StringValue1\nStringValue2\n"]
public long writeToTable(String datasetName, String tableName, String csvData)
throws IOException, InterruptedException, TimeoutException {
// [START writeToTable]
TableId tableId = TableId.of(datasetName, tableName);
WriteChannelConfiguration writeChannelConfiguration =
WriteChannelConfiguration.newBuilder(tableId)
.setFormatOptions(FormatOptions.csv())
.build();
TableDataWriteChannel writer = bigquery.writer(writeChannelConfiguration);
// Write data to writer
try {
writer.write(ByteBuffer.wrap(csvData.getBytes(Charsets.UTF_8)));
} finally {
writer.close();
}
// Get load job
Job job = writer.getJob();
job = job.waitFor();
LoadStatistics stats = job.getStatistics();
return stats.getOutputRows();
// [END writeToTable]
}
示例11: writeFileToTable
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
/**
* Example of riting a local file to a table.
*/
// [TARGET writer(WriteChannelConfiguration)]
// [VARIABLE "my_dataset_name"]
// [VARIABLE "my_table_name"]
// [VARIABLE FileSystems.getDefault().getPath(".", "my-data.csv")]
public long writeFileToTable(String datasetName, String tableName, Path fileFullPath, FormatOptions formatOptions)
throws IOException, InterruptedException, TimeoutException {
// [START writeFileToTable]
TableId tableId = TableId.of(datasetName, tableName);
WriteChannelConfiguration writeChannelConfiguration =
WriteChannelConfiguration.newBuilder(tableId)
.setFormatOptions(formatOptions)
.build();
TableDataWriteChannel writer = bigquery.writer(writeChannelConfiguration);
// Write data to writer
try (OutputStream stream = Channels.newOutputStream(writer)) {
Files.copy(fileFullPath, stream);
}
// Get load job
Job job = writer.getJob();
job = job.waitFor();
if(job.getStatus().getExecutionErrors() != null){
String errors = "";
for(BigQueryError error : job.getStatus().getExecutionErrors()){
errors += "error: " + error.getMessage() + ", reason: " + error.getReason() + ", location: " + error.getLocation() + "; ";
}
throw new IOException(errors);
}
LoadStatistics stats = job.getStatistics();
return stats.getOutputRows();
// [END writeFileToTable]
}
示例12: insertAll
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
/**
* Example of inserting rows into a table without running a load job.
*/
// [TARGET insertAll(InsertAllRequest)]
// [VARIABLE "my_dataset_name"]
// [VARIABLE "my_table_name"]
public InsertAllResponse insertAll(String datasetName, String tableName) {
// [START insertAll]
TableId tableId = TableId.of(datasetName, tableName);
// Values of the row to insert
Map<String, Object> rowContent = new HashMap<String, Object>();
rowContent.put("booleanField", true);
// Bytes are passed in base64
rowContent.put("bytesField", "Cg0NDg0="); // 0xA, 0xD, 0xD, 0xE, 0xD in base64
// Records are passed as a map
Map<String, Object> recordsContent = new HashMap<String, Object>();
recordsContent.put("stringField", "Hello, World!");
rowContent.put("recordField", recordsContent);
InsertAllResponse response = bigquery.insertAll(InsertAllRequest.newBuilder(tableId)
.addRow("rowId", rowContent)
// More rows can be added in the same RPC by invoking .addRow() on the builder
.build());
if (response.hasErrors()) {
// If any of the insertions failed, this lets you inspect the errors
for (Entry<Long, List<BigQueryError>> entry : response.getInsertErrors().entrySet()) {
// inspect row error
}
}
// [END insertAll]
return response;
}
示例13: testBasicBuilder
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
@Test
public void testBasicBuilder() {
final String dataset = "dataset";
final String table = "table";
final PartitionedTableId tableId = new PartitionedTableId.Builder(dataset, table).build();
Assert.assertEquals(dataset, tableId.getDataset());
Assert.assertEquals(table, tableId.getBaseTableName());
Assert.assertEquals(table, tableId.getFullTableName());
TableId expectedTableId = TableId.of(dataset, table);
Assert.assertEquals(expectedTableId, tableId.getBaseTableId());
Assert.assertEquals(expectedTableId, tableId.getFullTableId());
}
示例14: testBQTableDescription
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
@Test
public void testBQTableDescription() {
final String testTableName = "testTable";
final String testDatasetName = "testDataset";
final String testDoc = "test doc";
final TableId tableId = TableId.of(testDatasetName, testTableName);
SchemaRetriever mockSchemaRetriever = mock(SchemaRetriever.class);
@SuppressWarnings("unchecked")
SchemaConverter<com.google.cloud.bigquery.Schema> mockSchemaConverter =
(SchemaConverter<com.google.cloud.bigquery.Schema>) mock(SchemaConverter.class);
BigQuery mockBigQuery = mock(BigQuery.class);
SchemaManager schemaManager = new SchemaManager(mockSchemaRetriever,
mockSchemaConverter,
mockBigQuery);
Schema mockKafkaSchema = mock(Schema.class);
// we would prefer to mock this class, but it is final.
com.google.cloud.bigquery.Schema fakeBigQuerySchema =
com.google.cloud.bigquery.Schema.of(Field.of("mock field", Field.Type.string()));
when(mockSchemaConverter.convertSchema(mockKafkaSchema)).thenReturn(fakeBigQuerySchema);
when(mockKafkaSchema.doc()).thenReturn(testDoc);
TableInfo tableInfo = schemaManager.constructTableInfo(tableId, mockKafkaSchema);
Assert.assertEquals("Kafka doc does not match BigQuery table description",
testDoc, tableInfo.getDescription());
}
示例15: testAutoCreateTables
import com.google.cloud.bigquery.TableId; //导入方法依赖的package包/类
@Test
public void testAutoCreateTables() {
final String dataset = "scratch";
final String existingTableTopic = "topic-with-existing-table";
final String nonExistingTableTopic = "topic-without-existing-table";
final TableId existingTable = TableId.of(dataset, "topic_with_existing_table");
final TableId nonExistingTable = TableId.of(dataset, "topic_without_existing_table");
Map<String, String> properties = propertiesFactory.getProperties();
properties.put(BigQuerySinkConnectorConfig.TABLE_CREATE_CONFIG, "true");
properties.put(BigQuerySinkConfig.SCHEMA_RETRIEVER_CONFIG, MockSchemaRetriever.class.getName());
properties.put(BigQuerySinkConfig.SANITIZE_TOPICS_CONFIG, "true");
properties.put(BigQuerySinkConfig.DATASETS_CONFIG, String.format(".*=%s", dataset));
properties.put(
BigQuerySinkConfig.TOPICS_CONFIG,
String.format("%s, %s", existingTableTopic, nonExistingTableTopic)
);
BigQuery bigQuery = mock(BigQuery.class);
Table fakeTable = mock(Table.class);
when(bigQuery.getTable(existingTable)).thenReturn(fakeTable);
when(bigQuery.getTable(nonExistingTable)).thenReturn(null);
SchemaManager schemaManager = mock(SchemaManager.class);
BigQuerySinkConnector testConnector = new BigQuerySinkConnector(bigQuery, schemaManager);
testConnector.start(properties);
verify(bigQuery).getTable(existingTable);
verify(bigQuery).getTable(nonExistingTable);
verify(schemaManager, never()).createTable(existingTable, existingTableTopic);
verify(schemaManager).createTable(nonExistingTable, nonExistingTableTopic);
}