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

Introduce BigQuery Regionalization Support #971

Merged
merged 4 commits into from
Apr 3, 2018
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
55 changes: 50 additions & 5 deletions BigQuery/src/BigQueryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class BigQueryClient
*/
protected $connection;

/**
* @var string The default geographic location.
*/
private $location;

/**
* @var ValueMapper Maps values between PHP and BigQuery.
*/
Expand Down Expand Up @@ -97,10 +102,18 @@ class BigQueryClient
* @type bool $returnInt64AsObject If true, 64 bit integers will be
* returned as a {@see Google\Cloud\Core\Int64} object for 32 bit
* platform compatibility. **Defaults to** false.
* @type string $location If provided, determines the default geographic
* location used when creating datasets and managing jobs. Please
* note: This is only required for jobs started outside of the US
* and EU regions. Also, if location metadata has already been

This comment was marked as spam.

This comment was marked as spam.

* fetched over the network it will take precedent over this
* setting (by calling
* {@see Google\Cloud\BigQuery\Table::reload()}, for example).
* }
*/
public function __construct(array $config = [])
{
$this->location = $this->pluck('location', $config, false);
$this->setHttpRetryCodes([502]);
$this->setHttpRetryMessages([
'rateLimitExceeded',
Expand Down Expand Up @@ -164,6 +177,13 @@ public function __construct(array $config = [])
* );
* ```
*
* ```
* // Set a region to run the job in.
* $queryJobConfig = $bigQuery->query(
* 'SELECT name FROM `my_project.users_dataset.users` LIMIT 100'
* )->location('asia-northeast1');
* ```
*
* @param string $query A BigQuery SQL query.
* @param array $options [optional] Please see the
* [API documentation for Job configuration](https://goo.gl/vSTbGp)
Expand All @@ -175,7 +195,8 @@ public function query($query, array $options = [])
return (new QueryJobConfiguration(
$this->mapper,
$this->projectId,
$options
$options,
$this->location
))->query($query);
}

Expand Down Expand Up @@ -368,11 +389,28 @@ public function startQuery(JobConfigurationInterface $query, array $options = []
* ```
*
* @param string $id The id of the already run or running job to request.
* @param array $options [optional] {
* Configuration options.
*
* @type string $location The geographic location of the job. Required
* for jobs started outside of the US and EU regions.
* **Defaults to** a location specified in the client
* configuration.
* }
* @return Job
*/
public function job($id)
public function job($id, array $options = [])
{
return new Job($this->connection, $id, $this->projectId, $this->mapper);
return new Job(
$this->connection,
$id,
$this->projectId,
$this->mapper,
[],
isset($options['location'])
? $options['location']
: $this->location
);
}

/**
Expand Down Expand Up @@ -451,7 +489,9 @@ public function dataset($id)
$this->connection,
$id,
$this->projectId,
$this->mapper
$this->mapper,
[],
$this->location
);
}

Expand Down Expand Up @@ -511,7 +551,8 @@ function (array $dataset) {
* Creates a dataset.
*
* Please note that by default the library will not attempt to retry this
* call on your behalf.
* call on your behalf. Additionally, if a default location is provided in
* the client configuration it will be used when creating the dataset.
*
* Example:
* ```
Expand All @@ -537,6 +578,10 @@ public function createDataset($id, array $options = [])
unset($options['metadata']);
}

if ($this->location && !isset($options['location'])) {
$options['location'] = $this->location;
}

$response = $this->connection->insertDataset(
[
'projectId' => $this->projectId,
Expand Down
Loading