本文整理汇总了Java中com.google.cloud.bigquery.Job.getStatistics方法的典型用法代码示例。如果您正苦于以下问题:Java Job.getStatistics方法的具体用法?Java Job.getStatistics怎么用?Java Job.getStatistics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.cloud.bigquery.Job
的用法示例。
在下文中一共展示了Job.getStatistics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeToTable
import com.google.cloud.bigquery.Job; //导入方法依赖的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]
}
示例2: writeFileToTable
import com.google.cloud.bigquery.Job; //导入方法依赖的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]
}