@Test public void testCreateJobWithProjectId() { JobInfo jobInfo = JobInfo.newBuilder(QUERY_JOB_CONFIGURATION.setProjectId(OTHER_PROJECT)) .setJobId(JobId.of(OTHER_PROJECT, JOB)) .build(); Capture<Map<BigQueryRpc.Option, Object>> capturedOptions = Capture.newInstance(); EasyMock.expect(bigqueryRpcMock.create(eq(jobInfo.toPb()), capture(capturedOptions))) .andReturn(jobInfo.toPb()); EasyMock.replay(bigqueryRpcMock); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); Job job = bigquery.create(jobInfo, JOB_OPTION_FIELDS); assertEquals(new Job(bigquery, new JobInfo.BuilderImpl(jobInfo)), job); String selector = (String) capturedOptions.getValue().get(JOB_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("jobReference")); assertTrue(selector.contains("configuration")); assertTrue(selector.contains("user_email")); assertEquals(37, selector.length()); }
boolean idRandom = false; if (jobInfo.getJobId() == null) { jobInfo = jobInfo.toBuilder().setJobId(idProvider.get()).build(); idRandom = true;
/** * Use standard SQL syntax for queries. * See: https://cloud.google.com/bigquery/sql-reference/ * * @param query the standard (non legacy) SQL statement * * @return a {@link BigQueryOperation} instance to be executed by the {@link BigQueryOperator} */ public BigQueryOperation<T> query(String query) { final QueryJobConfiguration queryConfig = newBuilder(query) .setUseLegacySql(false) .build(); final JobId jobId = JobId.of(UUID.randomUUID().toString()); return job(JobInfo.newBuilder(queryConfig).setJobId(jobId).build()); }
/** * Returns a builder for a {@code JobInfo} object given the job identity and configuration. Use * {@link CopyJobConfiguration} for a job that copies an existing table. Use {@link * ExtractJobConfiguration} for a job that exports a table to Google Cloud Storage. Use {@link * LoadJobConfiguration} for a job that loads data from Google Cloud Storage into a table. Use * {@link QueryJobConfiguration} for a job that runs a query. */ public static JobInfo of(JobId jobId, JobConfiguration configuration) { return newBuilder(configuration).setJobId(jobId).build(); }
JobInfo setProjectId(String projectId) { Builder builder = toBuilder(); if (jobId != null) { builder.setJobId(jobId.setProjectId(projectId)); } return builder.setConfiguration(configuration.setProjectId(projectId)).build(); }
Job queryJob = bigquery.create(JobInfo.newBuilder(queryConfig).setJobId(jobId).build());
boolean idRandom = false; if (jobInfo.getJobId() == null) { jobInfo = jobInfo.toBuilder().setJobId(idProvider.get()).build(); idRandom = true;
/** Example of running a batch query. */ public void runBatchQuery() throws TimeoutException, InterruptedException { // [START bigquery_query_batch] // BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;"; QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query) // Run at batch priority, which won't count toward concurrent rate // limit. .setPriority(QueryJobConfiguration.Priority.BATCH) .build(); // Location must match that of the dataset(s) referenced in the query. JobId jobId = JobId.newBuilder().setRandomJob().setLocation("US").build(); String jobIdString = jobId.getJob(); // API request - starts the query. bigquery.create(JobInfo.newBuilder(queryConfig).setJobId(jobId).build()); // Check on the progress by getting the job's updated state. Once the state // is `DONE`, the results are ready. Job queryJob = bigquery.getJob(JobId.newBuilder().setJob(jobIdString).setLocation("US").build()); System.out.printf( "Job %s in location %s currently in state: %s%n", queryJob.getJobId().getJob(), queryJob.getJobId().getLocation(), queryJob.getStatus().getState().toString()); // [END bigquery_query_batch] }
/** * Returns a builder for a {@code JobInfo} object given the job identity and configuration. Use * {@link CopyJobConfiguration} for a job that copies an existing table. Use {@link * ExtractJobConfiguration} for a job that exports a table to Google Cloud Storage. Use {@link * LoadJobConfiguration} for a job that loads data from Google Cloud Storage into a table. Use * {@link QueryJobConfiguration} for a job that runs a query. */ public static JobInfo of(JobId jobId, JobConfiguration configuration) { return newBuilder(configuration).setJobId(jobId).build(); }
JobInfo setProjectId(String projectId) { Builder builder = toBuilder(); if (jobId != null) { builder.setJobId(jobId.setProjectId(projectId)); } return builder.setConfiguration(configuration.setProjectId(projectId)).build(); }