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


Java QueryJobConfiguration类代码示例

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


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

示例1: createJob

import com.google.cloud.bigquery.QueryJobConfiguration; //导入依赖的package包/类
/**
 * Example of creating a query job.
 */
// [TARGET create(JobInfo, JobOption...)]
// [VARIABLE "SELECT field FROM my_dataset_name.my_table_name"]
public Job createJob(String query) {
  // [START createJob]
  Job job = null;
  JobConfiguration jobConfiguration = QueryJobConfiguration.of(query);
  JobInfo jobInfo = JobInfo.of(jobConfiguration);
  try {
    job = bigquery.create(jobInfo);
  } catch (BigQueryException e) {
    // the job was not created
  }
  // [END createJob]
  return job;
}
 
开发者ID:michael-hll,项目名称:BigQueryStudy,代码行数:19,代码来源:BigQuerySnippets.java

示例2: runQueryPermanentTable

import com.google.cloud.bigquery.QueryJobConfiguration; //导入依赖的package包/类
public static void runQueryPermanentTable(
    String queryString,
    String destinationDataset,
    String destinationTable,
    boolean allowLargeResults) throws TimeoutException, InterruptedException {
  QueryJobConfiguration queryConfig =
      QueryJobConfiguration.newBuilder(queryString)
          // Save the results of the query to a permanent table. See:
          // https://cloud.google.com/bigquery/docs/writing-results#permanent-table
          .setDestinationTable(TableId.of(destinationDataset, destinationTable))
          // Allow results larger than the maximum response size.
          // If true, a destination table must be set. See: 
          // https://cloud.google.com/bigquery/docs/writing-results#large-results
          .setAllowLargeResults(allowLargeResults)
          .build();

  runQuery(queryConfig);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:19,代码来源:QuerySample.java

示例3: runSimpleQuery

import com.google.cloud.bigquery.QueryJobConfiguration; //导入依赖的package包/类
public static void runSimpleQuery(String queryString)
    throws TimeoutException, InterruptedException {
  QueryJobConfiguration queryConfig =
      QueryJobConfiguration.newBuilder(queryString).build();

  runQuery(queryConfig);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:8,代码来源:QuerySample.java

示例4: runStandardSqlQuery

import com.google.cloud.bigquery.QueryJobConfiguration; //导入依赖的package包/类
public static void runStandardSqlQuery(String queryString)
    throws TimeoutException, InterruptedException {
  QueryJobConfiguration queryConfig =
      QueryJobConfiguration.newBuilder(queryString)
          // To use standard SQL syntax, set useLegacySql to false. See:
          // https://cloud.google.com/bigquery/docs/reference/standard-sql/enabling-standard-sql
          .setUseLegacySql(false)
          .build();

  runQuery(queryConfig);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:12,代码来源:QuerySample.java

示例5: runUncachedQuery

import com.google.cloud.bigquery.QueryJobConfiguration; //导入依赖的package包/类
public static void runUncachedQuery(String queryString)
    throws TimeoutException, InterruptedException {
  QueryJobConfiguration queryConfig =
      QueryJobConfiguration.newBuilder(queryString)
          // Do not use the query cache. Force live query evaluation. See:
          // https://cloud.google.com/bigquery/docs/cached-results#disabling_retrieval_of_cached_results
          .setUseQueryCache(false)
          .build();

  runQuery(queryConfig);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:12,代码来源:QuerySample.java

示例6: runBatchQuery

import com.google.cloud.bigquery.QueryJobConfiguration; //导入依赖的package包/类
public static void runBatchQuery(String queryString)
    throws TimeoutException, InterruptedException {
  QueryJobConfiguration queryConfig =
      QueryJobConfiguration.newBuilder(queryString)
          // Run at batch priority, which won't count toward concurrent rate
          // limit. See:
          // https://cloud.google.com/bigquery/docs/running-queries#batch
          .setPriority(QueryJobConfiguration.Priority.BATCH)
          .build();

  runQuery(queryConfig);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:13,代码来源:QuerySample.java

示例7: runQuery

import com.google.cloud.bigquery.QueryJobConfiguration; //导入依赖的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

示例8: main

import com.google.cloud.bigquery.QueryJobConfiguration; //导入依赖的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

示例9: runNamed

import com.google.cloud.bigquery.QueryJobConfiguration; //导入依赖的package包/类
/**
 * Query the Shakespeare dataset for words with count at least {@code minWordCount} in the corpus
 * {@code corpus}.
 */
// [START bigquery_query_params]
private static void runNamed(final String corpus, final long minWordCount)
    throws InterruptedException {
  BigQuery bigquery =
      new BigQueryOptions.DefaultBigqueryFactory().create(BigQueryOptions.getDefaultInstance());

  String queryString =
      "SELECT word, word_count\n"
          + "FROM `bigquery-public-data.samples.shakespeare`\n"
          + "WHERE corpus = @corpus\n"
          + "AND word_count >= @min_word_count\n"
          + "ORDER BY word_count DESC";
  QueryJobConfiguration queryRequest =
      QueryJobConfiguration.newBuilder(queryString)
          .addNamedParameter("corpus", QueryParameterValue.string(corpus))
          .addNamedParameter("min_word_count", QueryParameterValue.int64(minWordCount))
          // Standard SQL syntax is required for parameterized queries.
          // See: https://cloud.google.com/bigquery/sql-reference/
          .setUseLegacySql(false)
          .build();

  // Execute the query.
  QueryResponse response = bigquery.query(queryRequest);

  // Wait for the job to finish (if the query takes more than 10 seconds to complete).
  while (!response.jobCompleted()) {
    Thread.sleep(1000);
    response = bigquery.getQueryResults(response.getJobId());
  }

  // Check for errors.
  if (response.hasErrors()) {
    String firstError = "";
    if (response.getExecutionErrors().size() != 0) {
      firstError = response.getExecutionErrors().get(0).getMessage();
    }
    throw new RuntimeException(firstError);
  }

  // Print all pages of the results.
  QueryResult result = response.getResult();
  while (result != null) {
    for (List<FieldValue> row : result.iterateAll()) {
      System.out.printf("%s: %d\n", row.get(0).getStringValue(), row.get(1).getLongValue());
    }

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

示例10: runArray

import com.google.cloud.bigquery.QueryJobConfiguration; //导入依赖的package包/类
/**
 * Query the baby names database to find the most popular names for a gender in a list of states.
 */
// [START bigquery_query_params_arrays]
private static void runArray(String gender, String[] states) throws InterruptedException {
  BigQuery bigquery =
      new BigQueryOptions.DefaultBigqueryFactory().create(BigQueryOptions.getDefaultInstance());

  String queryString =
      "SELECT name, sum(number) as count\n"
          + "FROM `bigquery-public-data.usa_names.usa_1910_2013`\n"
          + "WHERE gender = @gender\n"
          + "AND state IN UNNEST(@states)\n"
          + "GROUP BY name\n"
          + "ORDER BY count DESC\n"
          + "LIMIT 10;";
  QueryJobConfiguration queryRequest =
      QueryJobConfiguration.newBuilder(queryString)
          .addNamedParameter("gender", QueryParameterValue.string(gender))
          .addNamedParameter("states", QueryParameterValue.array(states, String.class))
          // Standard SQL syntax is required for parameterized queries.
          // See: https://cloud.google.com/bigquery/sql-reference/
          .setUseLegacySql(false)
          .build();

  // Execute the query.
  QueryResponse response = bigquery.query(queryRequest);

  // Wait for the job to finish (if the query takes more than 10 seconds to complete).
  while (!response.jobCompleted()) {
    Thread.sleep(1000);
    response = bigquery.getQueryResults(response.getJobId());
  }

  // Check for errors.
  if (response.hasErrors()) {
    String firstError = "";
    if (response.getExecutionErrors().size() != 0) {
      firstError = response.getExecutionErrors().get(0).getMessage();
    }
    throw new RuntimeException(firstError);
  }

  // Print all pages of the results.
  QueryResult result = response.getResult();
  while (result != null) {
    for (List<FieldValue> row : result.iterateAll()) {
      System.out.printf("%s: %d\n", row.get(0).getStringValue(), row.get(1).getLongValue());
    }

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

示例11: runTimestamp

import com.google.cloud.bigquery.QueryJobConfiguration; //导入依赖的package包/类
private static void runTimestamp() throws InterruptedException {
  BigQuery bigquery =
      new BigQueryOptions.DefaultBigqueryFactory().create(BigQueryOptions.getDefaultInstance());

  DateTime timestamp = new DateTime(2016, 12, 7, 8, 0, 0, DateTimeZone.UTC);

  String queryString = "SELECT TIMESTAMP_ADD(@ts_value, INTERVAL 1 HOUR);";
  QueryJobConfiguration queryRequest =
      QueryJobConfiguration.newBuilder(queryString)
          .addNamedParameter(
              "ts_value",
              QueryParameterValue.timestamp(
                  // Timestamp takes microseconds since 1970-01-01T00:00:00 UTC
                  timestamp.getMillis() * 1000))
          // Standard SQL syntax is required for parameterized queries.
          // See: https://cloud.google.com/bigquery/sql-reference/
          .setUseLegacySql(false)
          .build();

  // Execute the query.
  QueryResponse response = bigquery.query(queryRequest);

  // Wait for the job to finish (if the query takes more than 10 seconds to complete).
  while (!response.jobCompleted()) {
    Thread.sleep(1000);
    response = bigquery.getQueryResults(response.getJobId());
  }

  // Check for errors.
  if (response.hasErrors()) {
    String firstError = "";
    if (response.getExecutionErrors().size() != 0) {
      firstError = response.getExecutionErrors().get(0).getMessage();
    }
    throw new RuntimeException(firstError);
  }

  // Print all pages of the results.
  QueryResult result = response.getResult();
  DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
  while (result != null) {
    for (List<FieldValue> row : result.iterateAll()) {
      System.out.printf(
          "%s\n",
          formatter.print(
              new DateTime(
                  // Timestamp values are returned in microseconds since 1970-01-01T00:00:00 UTC,
                  // but org.joda.time.DateTime constructor accepts times in milliseconds.
                  row.get(0).getTimestampValue() / 1000, DateTimeZone.UTC)));
    }

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


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