Here are the examples of the java api class com.google.api.services.bigquery.Bigquery.Jobs.Insert taken from open source projects.
1. BigQueryTableRowIterator#executeQueryAndWaitForCompletion()
Project: incubator-beam
File: BigQueryTableRowIterator.java
File: BigQueryTableRowIterator.java
/** * Executes the specified query and returns a reference to the temporary BigQuery table created * to hold the results. * * @throws IOException if the query fails. */ private TableReference executeQueryAndWaitForCompletion() throws IOException, InterruptedException { // Create a temporary dataset to store results. // Starting dataset name with an "_" so that it is hidden. Random rnd = new Random(System.currentTimeMillis()); temporaryDatasetId = "_dataflow_temporary_dataset_" + rnd.nextInt(1000000); temporaryTableId = "dataflow_temporary_table_" + rnd.nextInt(1000000); createDataset(temporaryDatasetId); Job job = new Job(); JobConfiguration config = new JobConfiguration(); JobConfigurationQuery queryConfig = new JobConfigurationQuery(); config.setQuery(queryConfig); job.setConfiguration(config); queryConfig.setQuery(query); queryConfig.setAllowLargeResults(true); queryConfig.setFlattenResults(flattenResults); TableReference destinationTable = new TableReference(); destinationTable.setProjectId(projectId); destinationTable.setDatasetId(temporaryDatasetId); destinationTable.setTableId(temporaryTableId); queryConfig.setDestinationTable(destinationTable); Insert insert = client.jobs().insert(projectId, job); Job queryJob = executeWithBackOff(insert, "Error when trying to execute the job for query " + query + " :{}"); JobReference jobId = queryJob.getJobReference(); while (true) { Job pollJob = executeWithBackOff(client.jobs().get(projectId, jobId.getJobId()), "Error when trying to get status of the job for query " + query + " :{}"); JobStatus status = pollJob.getStatus(); if (status.getState().equals("DONE")) { // Job is DONE, but did not necessarily succeed. ErrorProto error = status.getErrorResult(); if (error == null) { return pollJob.getConfiguration().getQuery().getDestinationTable(); } else { // There will be no temporary table to delete, so null out the reference. temporaryTableId = null; throw new IOException("Executing query " + query + " failed: " + error.getMessage()); } } Uninterruptibles.sleepUninterruptibly(QUERY_COMPLETION_POLL_TIME.getMillis(), TimeUnit.MILLISECONDS); } }
2. BigQueryTableRowIterator#executeQueryAndWaitForCompletion()
Project: DataflowJavaSDK
File: BigQueryTableRowIterator.java
File: BigQueryTableRowIterator.java
/** * Executes the specified query and returns a reference to the temporary BigQuery table created * to hold the results. * * @throws IOException if the query fails. */ private TableReference executeQueryAndWaitForCompletion() throws IOException, InterruptedException { // Create a temporary dataset to store results. // Starting dataset name with an "_" so that it is hidden. Random rnd = new Random(System.currentTimeMillis()); temporaryDatasetId = "_dataflow_temporary_dataset_" + rnd.nextInt(1000000); temporaryTableId = "dataflow_temporary_table_" + rnd.nextInt(1000000); createDataset(temporaryDatasetId); Job job = new Job(); JobConfiguration config = new JobConfiguration(); JobConfigurationQuery queryConfig = new JobConfigurationQuery(); config.setQuery(queryConfig); job.setConfiguration(config); queryConfig.setQuery(query); queryConfig.setAllowLargeResults(true); queryConfig.setFlattenResults(flattenResults); TableReference destinationTable = new TableReference(); destinationTable.setProjectId(projectId); destinationTable.setDatasetId(temporaryDatasetId); destinationTable.setTableId(temporaryTableId); queryConfig.setDestinationTable(destinationTable); Insert insert = client.jobs().insert(projectId, job); Job queryJob = executeWithBackOff(insert, "Error when trying to execute the job for query " + query + " :{}"); JobReference jobId = queryJob.getJobReference(); while (true) { Job pollJob = executeWithBackOff(client.jobs().get(projectId, jobId.getJobId()), "Error when trying to get status of the job for query " + query + " :{}"); JobStatus status = pollJob.getStatus(); if (status.getState().equals("DONE")) { // Job is DONE, but did not necessarily succeed. ErrorProto error = status.getErrorResult(); if (error == null) { return pollJob.getConfiguration().getQuery().getDestinationTable(); } else { // There will be no temporary table to delete, so null out the reference. temporaryTableId = null; throw new IOException("Executing query " + query + " failed: " + error.getMessage()); } } Uninterruptibles.sleepUninterruptibly(QUERY_COMPLETION_POLL_TIME.getMillis(), TimeUnit.MILLISECONDS); } }