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


Java BigQuery.create方法代码示例

本文整理汇总了Java中com.google.cloud.bigquery.BigQuery.create方法的典型用法代码示例。如果您正苦于以下问题:Java BigQuery.create方法的具体用法?Java BigQuery.create怎么用?Java BigQuery.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.cloud.bigquery.BigQuery的用法示例。


在下文中一共展示了BigQuery.create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.google.cloud.bigquery.BigQuery; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {
  // Instantiate a client. If you don't specify credentials when constructing a client, the
  // client library will look for credentials in the environment, such as the
  // GOOGLE_APPLICATION_CREDENTIALS environment variable.
  BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();

  // The name for the new dataset
  String datasetName = "my_new_dataset";

  // Prepares a new dataset
  Dataset dataset = null;
  DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build();

  // Creates the dataset
  dataset = bigquery.create(datasetInfo);

  System.out.printf("Dataset %s created.%n", dataset.getDatasetId().getDataset());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:19,代码来源:QuickstartSample.java

示例2: runQuery

import com.google.cloud.bigquery.BigQuery; //导入方法依赖的package包/类
public static void runQuery(QueryJobConfiguration queryConfig)
    throws TimeoutException, InterruptedException {
  BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();

  // Create a job ID so that we can safely retry.
  JobId jobId = JobId.of(UUID.randomUUID().toString());
  Job queryJob = bigquery.create(JobInfo.newBuilder(queryConfig).setJobId(jobId).build());

  // Wait for the query to complete.
  queryJob = queryJob.waitFor();

  // Check for errors
  if (queryJob == null) {
    throw new RuntimeException("Job no longer exists");
  } else if (queryJob.getStatus().getError() != null) {
    // You can also look at queryJob.getStatus().getExecutionErrors() for all
    // errors, not just the latest one.
    throw new RuntimeException(queryJob.getStatus().getError().toString());
  }

  // Get the results.
  QueryResponse response = bigquery.getQueryResults(jobId);
  QueryResult result = response.getResult();

  // Print all pages of the results.
  while (result != null) {
    for (List<FieldValue> row : result.iterateAll()) {
      for (FieldValue val : row) {
        System.out.printf("%s,", val.toString());
      }
      System.out.printf("\n");
    }

    result = result.getNextPage();
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:37,代码来源:QuerySample.java

示例3: initDatasetAndTable

import com.google.cloud.bigquery.BigQuery; //导入方法依赖的package包/类
@BeforeClass
public static void initDatasetAndTable() throws IOException {
    BigQuery bigquery = BigQueryConnection.createClient(createDatastore());
    for (String dataset : datasets) {
        DatasetId datasetId = DatasetId.of(BigQueryTestConstants.PROJECT, dataset);
        bigquery.create(DatasetInfo.of(datasetId));
    }

    for (String table : tables) {
        TableDefinition tableDefinition = StandardTableDefinition.of(Schema.of(Field.of("test", Field.Type.string())));
        TableId tableId = TableId.of(BigQueryTestConstants.PROJECT, datasets.get(0), table);
        bigquery.create(TableInfo.of(tableId, tableDefinition));
    }
}
 
开发者ID:Talend,项目名称:components,代码行数:15,代码来源:BigQueryDatasetRuntimeTestIT.java

示例4: main

import com.google.cloud.bigquery.BigQuery; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {
  // [START bigquery_simple_app_client]
  BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
  // [END bigquery_simple_app_client]
  // [START bigquery_simple_app_query]
  QueryJobConfiguration queryConfig =
      QueryJobConfiguration.newBuilder(
        "SELECT "
            + "CONCAT('https://stackoverflow.com/questions/', CAST(id as STRING)) as url, "
            + "view_count "
            + "FROM `bigquery-public-data.stackoverflow.posts_questions` "
            + "WHERE tags like '%google-bigquery%' "
            + "ORDER BY favorite_count DESC LIMIT 10")
          // Use standard SQL syntax for queries.
          // See: https://cloud.google.com/bigquery/sql-reference/
          .setUseLegacySql(false)
          .build();

  // Create a job ID so that we can safely retry.
  JobId jobId = JobId.of(UUID.randomUUID().toString());
  Job queryJob = bigquery.create(JobInfo.newBuilder(queryConfig).setJobId(jobId).build());

  // Wait for the query to complete.
  queryJob = queryJob.waitFor();

  // Check for errors
  if (queryJob == null) {
    throw new RuntimeException("Job no longer exists");
  } else if (queryJob.getStatus().getError() != null) {
    // You can also look at queryJob.getStatus().getExecutionErrors() for all
    // errors, not just the latest one.
    throw new RuntimeException(queryJob.getStatus().getError().toString());
  }
  // [END bigquery_simple_app_query]

  // [START bigquery_simple_app_print]
  // Get the results.
  QueryResponse response = bigquery.getQueryResults(jobId);

  QueryResult result = response.getResult();

  // Print all pages of the results.
  for (FieldValueList row : result.iterateAll()) {
    String url = row.get("url").getStringValue();
    long viewCount = row.get("view_count").getLongValue();
    System.out.printf("url: %s views: %d%n", url, viewCount);
  }
  // [END bigquery_simple_app_print]
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:50,代码来源:SimpleApp.java

示例5: createTestDataset

import com.google.cloud.bigquery.BigQuery; //导入方法依赖的package包/类
private static final void createTestDataset() {
  BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
  DatasetId datasetId = DatasetId.of(TEST_DATASET);
  bigquery.create(DatasetInfo.newBuilder(datasetId).build());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:6,代码来源:QuerySampleIT.java

示例6: initDataset

import com.google.cloud.bigquery.BigQuery; //导入方法依赖的package包/类
@BeforeClass
public static void initDataset() throws IOException {
    BigQuery bigquery = BigQueryConnection.createClient(createDatastore());
    DatasetId datasetId = DatasetId.of(BigQueryTestConstants.PROJECT, datasetName);
    bigquery.create(DatasetInfo.of(datasetId));
}
 
开发者ID:Talend,项目名称:components,代码行数:7,代码来源:BigQueryBeamRuntimeTestIT.java


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