Google\Cloud\BigQuery\BigQueryClient::runQueryAsJob PHP Method

runQueryAsJob() public method

Queries constructed using 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 also: https://cloud.google.com/bigquery/docs/reference/v2/jobs/insert Jobs insert API documentation.
public runQueryAsJob ( string $query, array $options = [] ) : Job
$query string A BigQuery SQL query.
$options array [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);
    }