当前位置: 首页>>代码示例>>Java>>正文


Java Job.getStatistics方法代码示例

本文整理汇总了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]
  }
 
开发者ID:michael-hll,项目名称:BigQueryStudy,代码行数:30,代码来源:BigQuerySnippets.java

示例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]
}
 
开发者ID:michael-hll,项目名称:BigQueryStudy,代码行数:35,代码来源:BigQuerySnippets.java


注:本文中的com.google.cloud.bigquery.Job.getStatistics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。