Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BC Break] Switch to standard SQL by default #640

Merged
merged 4 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions src/BigQuery/BigQueryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function __construct(array $config = [])
*
* Queries constructed using
* [standard SQL](https://cloud.google.com/bigquery/docs/reference/standard-sql/)
* can take advantage of parametriziation.
* can take advantage of parameterization.
*
* Refer to the table below for a guide on how parameter types are mapped to
* their BigQuery equivalents.
Expand All @@ -138,7 +138,7 @@ public function __construct(array $config = [])
*
* Example:
* ```
* $queryResults = $bigQuery->runQuery('SELECT commit FROM [bigquery-public-data:github_repos.commits] LIMIT 100');
* $queryResults = $bigQuery->runQuery('SELECT commit FROM `bigquery-public-data.github_repos.commits` LIMIT 100');
*
* foreach ($queryResults->rows() as $row) {
* echo $row['commit'];
Expand Down Expand Up @@ -193,10 +193,10 @@ public function __construct(array $config = [])
* query has completed. **Defaults to** `100`.
* @type bool $useQueryCache Whether to look for the result in the query
* cache.
* @type bool $useLegacySql Specifies whether to use BigQuery's legacy
* SQL dialect for this query. **Defaults to** `true`. If set to
* false, the query will use
* [BigQuery's standard SQL](https://cloud.google.com/bigquery/sql-reference).
* @type bool $useLegacySql If set to true the query will use
* [BigQuery's legacy SQL](https://cloud.google.com/bigquery/docs/reference/legacy-sql),
* otherwise [BigQuery's standard SQL](https://cloud.google.com/bigquery/sql-reference).
* **Defaults to** `false`.
* @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
Expand All @@ -209,7 +209,8 @@ public function __construct(array $config = [])
public function runQuery($query, array $options = [])
{
$options += [
'maxRetries' => 100
'maxRetries' => 100,
'useLegacySql' => false
];

if (isset($options['parameters'])) {
Expand Down Expand Up @@ -257,12 +258,12 @@ public function runQuery($query, array $options = [])
*
* Queries constructed using
* [standard SQL](https://cloud.google.com/bigquery/docs/reference/standard-sql/)
* can take advantage of parametriziation. For more details and examples
* can take advantage of parameterization. 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');
* $job = $bigQuery->runQueryAsJob('SELECT commit FROM `bigquery-public-data.github_repos.commits` LIMIT 100');
*
* $isComplete = false;
* $queryResults = $job->queryResults();
Expand Down Expand Up @@ -290,21 +291,28 @@ public function runQuery($query, array $options = [])
* 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.
* If not provided default settings will be used, with the exception
* of `configuration.query.useLegacySql`, which defaults to `false`
* in this client.
* }
* @return Job
*/
public function runQueryAsJob($query, array $options = [])
{
if (isset($options['parameters'])) {
if (!isset($options['jobConfig'])) {
$options['jobConfig'] = [];
}
$options += [
'jobConfig' => []
];

if (isset($options['parameters'])) {
$options['jobConfig'] += $this->formatQueryParameters($options['parameters']);

unset($options['parameters']);
}

$options['jobConfig'] += [
'useLegacySql' => false
];

$config = $this->buildJobConfig(
'query',
$this->projectId,
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/BigQuery/BigQueryClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public function queryDataProvider()
[],
[
'projectId' => $this->projectId,
'query' => $query
'query' => $query,
'useLegacySql' => false
]
],
[
Expand Down