本文整理匯總了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]
}