insertJob() public method

public insertJob ( array $args = [] ) : array
$args array
return array
Example #1
0
 /**
  * Runs a load job which loads the provided data into the table.
  *
  * Example:
  * ```
  * $table->load(fopen('/path/to/my/data.csv', 'r'));
  * ```
  *
  * @see https://cloud.google.com/bigquery/docs/reference/v2/jobs Jobs insert API Documentation.
  *
  * @param string|resource|StreamInterface $data The data to load.
  * @param array $options [optional] {
  *     Configuration options.
  *
  *     @type array $jobConfig Configuration settings for a load job are
  *           outlined in the [API Docs for `configuration.load`](https://goo.gl/j6jyHv).
  *           If not provided default settings will be used.
  * }
  * @return Job
  */
 public function load($data, array $options = [])
 {
     $response = null;
     $config = $this->buildJobConfig('load', $this->identity['projectId'], ['destinationTable' => $this->identity], $options);
     if ($data) {
         $config['data'] = $data;
         $response = $this->connection->insertJobUpload($config)->upload();
     } else {
         $response = $this->connection->insertJob($config);
     }
     return new Job($this->connection, $response['jobReference']['jobId'], $this->identity['projectId'], $response);
 }
 /**
  * Runs a BigQuery SQL query in an asynchronous fashion. Running a query
  * in this fashion requires you to poll for the status before being able
  * to access results.
  *
  * Queries constructed using
  * [standard SQL](https://cloud.google.com/bigquery/docs/reference/standard-sql/)
  * can take advantage of parametriziation. For more details and examples
  * please see {@see Google\Cloud\BigQuery\BigQueryClient::runQuery()}.
  *
  * Example:
  * ```
  * $job = $bigQuery->runQueryAsJob('SELECT commit FROM [bigquery-public-data:github_repos.commits] LIMIT 100');
  *
  * $isComplete = false;
  * $queryResults = $job->queryResults();
  *
  * while (!$isComplete) {
  *     sleep(1); // let's wait for a moment...
  *     $queryResults->reload(); // trigger a network request
  *     $isComplete = $queryResults->isComplete(); // check the query's status
  * }
  *
  * foreach ($queryResults->rows() as $row) {
  *     echo $row['commit'];
  * }
  * ```
  *
  * @see https://cloud.google.com/bigquery/docs/reference/v2/jobs/insert Jobs insert API documentation.
  *
  * @param string $query A BigQuery SQL query.
  * @param array $options [optional] {
  *     Configuration options.
  *
  *     @type array $parameters Only available for standard SQL queries.
  *           When providing a non-associative array positional parameters
  *           (`?`) will be used. When providing an associative array
  *           named parameters will be used (`@name`).
  *     @type array $jobConfig Configuration settings for a query job are
  *           outlined in the [API Docs for `configuration.query`](https://goo.gl/PuRa3I).
  *           If not provided default settings will be used.
  * }
  * @return Job
  */
 public function runQueryAsJob($query, array $options = [])
 {
     if (isset($options['parameters'])) {
         if (!isset($options['jobConfig'])) {
             $options['jobConfig'] = [];
         }
         $options['jobConfig'] += $this->formatQueryParameters($options['parameters']);
         unset($options['parameters']);
     }
     $config = $this->buildJobConfig('query', $this->projectId, ['query' => $query], $options);
     $response = $this->connection->insertJob($config);
     return new Job($this->connection, $response['jobReference']['jobId'], $this->projectId, $response, $this->mapper);
 }
 /**
  * Runs a BigQuery SQL query in an asynchronous fashion. Running a query
  * in this fashion requires you to poll for the status before being able
  * to access results.
  *
  * Example:
  * ```
  * $job = $bigQuery->runQueryAsJob('SELECT * FROM [bigquery-public-data:usa_names.usa_1910_2013]');
  *
  * $isComplete = false;
  * $queryResults = $job->queryResults();
  *
  * while (!$isComplete) {
  *     sleep(1); // let's wait for a moment...
  *     $queryResults->reload(); // trigger a network request
  *     $isComplete = $queryResults->isComplete(); // check the query's status
  * }
  *
  * foreach ($queryResults->rows() as $row) {
  *     echo $row['name'];
  * }
  * ```
  *
  * @see https://cloud.google.com/bigquery/docs/reference/v2/jobs/insert Jobs insert API documentation.
  *
  * @param string $query A BigQuery SQL query.
  * @param array $options [optional] {
  *     Configuration options.
  *
  *     @type array $jobConfig Configuration settings for a query job are
  *           outlined in the [API Docs for `configuration.query`](https://goo.gl/PuRa3I).
  *           If not provided default settings will be used.
  * }
  * @return Job
  */
 public function runQueryAsJob($query, array $options = [])
 {
     $config = $this->buildJobConfig('query', $this->projectId, ['query' => $query], $options);
     $response = $this->connection->insertJob($config);
     return new Job($this->connection, $response['jobReference']['jobId'], $this->projectId, $response);
 }