Skip to content

Commit

Permalink
Update Bigtable branch with latest from master (#1190)
Browse files Browse the repository at this point in the history
* Add isRacy() to SafeSearch (#1166)

The SafeSearch class included `is` functions for each SafeSearch feature (adult, spoof, medical, violence), but was missing Racy. This Pull Request adds `isRacy()` to the SafeSearch class.

* Exclude component vendor folder from snippet coverage (#1168)

cc @tmatsuo

* Allow context to handle Throwable interface (#1164)

* Add getServiceAccount to the BigQueryClient (#1167)

* Add getServiceAccount to the BigQueryClient

See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/projects/getServiceAccount

* Added $options to getServiceAccount and fixed the indent

* Use single quote

* Add snippet test

* Comment update, use self instead of $this

* Comment update

* Prepare v0.71.0 (#1169)

* Prepare v0.71.0

* patch release for Logging

* Correct version for Logging

* [Kms] Regenerate with the new gapic config (#1165)

* Update for the new gapic configuration

* Docs update for the new and nicer namespace

* Removed the files with the old namespace

* Use the new namespace in the code sample

Add back the deprecated files

* Changed the wording for the deprecation warning

* Fix firestore queries (#1161)

* Bump gax to 0.35 (#1170)

* Add an interactive release builder. (#1160)

* Add an interactive release builder.

* Create build directory if it doesn't exist

* Add getServiceAccount method to StorageClient (#1173)

* Re-generate library using Tasks/synth.py (#1174)

* Re-generate library using Tasks/synth.py

* Use new namespace in user visible area, tweak the deprecation wording

* Add support for Numeric type (#1172)

* Add support for Numeric type

* Added a cast in Numeric's constructor, added system tests

* Allow '123.' and '.123', update tests

* [Breaking Change] Add support for Document Snapshots in Firestore Query Cursors (#1162)

cc @schmidt-sebastian

Extracted from #923 and updated to address pull request comments.

Breaking change is the standardization in Query of using `InvalidArgumentException`, replacing various throws of `BadMethodCallException`.

Closes #851.

* Fix Storage Requesterpays system tests (#1180)

The requester pays system tests have been broken for some time. This change fixes them.

* Bandaid for protobuf 4761 (#1176)

* Temporary workaround for protobuf extension issue

protocolbuffers/protobuf#4761

* Bump gax to 0.36

* Configure comparators for the unit test

* Revert back to normal TestCase

* Install protobuf extension in the PHP 7.2 test runner

* Revert to TestCase

* Prepare v0.72.0 (#1181)

* Added a document for the time filter on BigQueryClient->jobs() (#1183)

* Narrowed the time filter in the system test (#1185)

* Re-generate library using BigQueryDataTransfer/synth.py (#1184)

* Re-generate library using BigQueryDataTransfer/synth.py

* Tweak the wording on the deprecation warning

Also use the new namespace in the sample code

* pin auth version until we have a way to silence warnings (#1189)
  • Loading branch information
dwsupplee authored and sduskis committed Jul 23, 2018
1 parent ed0d04d commit c2f4028
Show file tree
Hide file tree
Showing 232 changed files with 5,540 additions and 1,370 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ jobs:
- php: 7.2
install:
- pecl install grpc || echo 'Failed to install grpc'
- pecl install protobuf || echo 'Failed to install protobuf'
- pecl install stackdriver_debugger-alpha || echo 'Failed to install stackdriver_debugger'
- composer self-update
- travis_retry composer install
Expand Down
2 changes: 1 addition & 1 deletion BigQuery/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.4
1.4.0
48 changes: 47 additions & 1 deletion BigQuery/src/BigQueryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class BigQueryClient
use ClientTrait;
use RetryDeciderTrait;

const VERSION = '1.2.4';
const VERSION = '1.4.0';

const MAX_DELAY_MICROSECONDS = 32000000;

Expand Down Expand Up @@ -442,6 +442,10 @@ public function job($id, array $options = [])
* resume the loading of results from a specific point.
* @type string $stateFilter Filter for job state. Maybe be either
* `done`, `pending`, or `running`.
* @type int $maxCreationTime Milliseconds since the POSIX epoch. If set, only jobs created
* before or at this timestamp are returned.
* @type int $minCreationTime Milliseconds since the POSIX epoch. If set, only jobs created
* after or at this timestamp are returned.
* }
* @return ItemIterator<Job>
*/
Expand Down Expand Up @@ -682,4 +686,46 @@ public function timestamp(\DateTimeInterface $value)
{
return new Timestamp($value);
}

/**
* Create a Numeric object.
*
* Numeric represents a value with a data type of
* [Numeric](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#numeric-type).
*
* It supports a fixed 38 decimal digits of precision and 9 decimal digits of scale, and values
* are in the range of -99999999999999999999999999999.999999999 to
* 99999999999999999999999999999.999999999.
*
* Example:
* ```
* $numeric = $bigQuery->numeric('99999999999999999999999999999999999999.999999999');
* ```
*
* @param string|int|float $value The Numeric value.
* @return Numeric
* @throws \InvalidArgumentException
*/
public function numeric($value)
{
return new Numeric($value);
}

/**
* Get a service account for the KMS integration.
*
* Example:
* ```
* $serviceAccount = $bigQuery->getServiceAccount();
* ```
*
* @param array $options [optional] Configuration options.
*
* @return string
*/
public function getServiceAccount(array $options = [])
{
$resp = $this->connection->getServiceAccount($options + ['projectId' => $this->projectId]);
return $resp['email'];
}
}
6 changes: 6 additions & 0 deletions BigQuery/src/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,10 @@ public function insertJob(array $args = []);
* @return AbstractUploader
*/
public function insertJobUpload(array $args = []);

/**
* @param array $args
* @return array
*/
public function getServiceAccount(array $args = []);
}
9 changes: 9 additions & 0 deletions BigQuery/src/Connection/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ public function insertJobUpload(array $args = [])
);
}

/**
* @param array $args
* @return array
*/
public function getServiceAccount(array $args = [])
{
return $this->send('projects', 'getServiceAccount', $args);
}

/**
* @param array $args
* @return array
Expand Down
102 changes: 102 additions & 0 deletions BigQuery/src/Numeric.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\BigQuery;

/**
* Represents a value with a data type of
* [Numeric](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#numeric-type).
*
* It supports a fixed 38 decimal digits of precision and 9 decimal digits of scale, and values
* are in the range of -99999999999999999999999999999.999999999 to
* 99999999999999999999999999999.999999999.
*
* Example:
* ```
* use Google\Cloud\BigQuery\BigQueryClient;
*
* $bigQuery = new BigQueryClient();
*
* $numeric = $bigQuery->numeric('99999999999999999999999999999999999999.999999999');
* ```
*/
class Numeric implements ValueInterface
{
/**
* @var string
*/
private $value;

/**
* @param string|int|float $value The NUMERIC value.
* @throws \InvalidArgumentException
*/
public function __construct($value)
{
$value = (string) $value;
// allow minus sign at the beginning
// 38 or less decimal digits (or none)
// optional period and 9 or less digits of scale
$pattern = '/^-?([0-9]{1,38})?(\.([0-9]{1,9})?)?$/';
if (! preg_match($pattern, $value)) {
throw new \InvalidArgumentException(
'Numeric type only allows fixed 38 decimal digits and 9 decimal digits of scale.'
);
}
$this->value = $value;
}

/**
* Get the underlying value.
*
* @return string
*/
public function get()
{
return $this->value;
}

/**
* Get the type.
*
* @return string
*/
public function type()
{
return ValueMapper::TYPE_NUMERIC;
}

/**
* Format the value as a string.
*
* @return string
*/
public function formatAsString()
{
return $this->value;
}

/**
* Format the value as a string.
*
* @return string
*/
public function __toString()
{
return $this->value;
}
}
3 changes: 3 additions & 0 deletions BigQuery/src/ValueMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ValueMapper
const TYPE_INTEGER = 'INTEGER';
const TYPE_FLOAT64 = 'FLOAT64';
const TYPE_FLOAT = 'FLOAT';
const TYPE_NUMERIC = 'NUMERIC';
const TYPE_STRING = 'STRING';
const TYPE_BYTES = 'BYTES';
const TYPE_DATE = 'DATE';
Expand Down Expand Up @@ -95,6 +96,8 @@ public function fromBigQuery(array $value, array $schema)
: (int) $value;
case self::TYPE_FLOAT:
return (float) $value;
case self::TYPE_NUMERIC:
return new Numeric($value);
case self::TYPE_STRING:
return (string) $value;
case self::TYPE_BYTES:
Expand Down
28 changes: 28 additions & 0 deletions BigQuery/tests/Snippet/BigQueryClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\BigQuery\Bytes;
use Google\Cloud\BigQuery\Date;
use Google\Cloud\BigQuery\Numeric;
use Google\Cloud\BigQuery\Time;
use Google\Cloud\BigQuery\Timestamp;
use Google\Cloud\BigQuery\Connection\ConnectionInterface;
Expand Down Expand Up @@ -393,6 +394,16 @@ public function testInt64()
$this->assertInstanceOf(Int64::class, $res->returnVal());
}

public function testNumeric()
{
$snippet = $this->snippetFromMethod(BigQueryClient::class, 'numeric');
$snippet->addLocal('bigQuery', $this->client);
$this->client->___setProperty('connection', $this->connection->reveal());
$res = $snippet->invoke('numeric');

$this->assertInstanceOf(Numeric::class, $res->returnVal());
}

public function testTime()
{
$snippet = $this->snippetFromMethod(BigQueryClient::class, 'time');
Expand All @@ -412,6 +423,23 @@ public function testTimestamp()

$this->assertInstanceOf(Timestamp::class, $res->returnVal());
}

public function testGetServiceAccount()
{
$expectedEmail = uniqid() . '@bigquery-encryption.iam.gserviceaccount.com';
$snippet = $this->snippetFromMethod(BigQueryClient::class, 'getServiceAccount');
$snippet->addLocal('bigQuery', $this->client);
$this->connection->getServiceAccount(['projectId' => self::PROJECT_ID])
->willReturn([
"kind" => "bigquery#getServiceAccountResponse",
"email" => $expectedEmail
])
->shouldBeCalledTimes(1);
$this->client->___setProperty('connection', $this->connection->reveal());
$res = $snippet->invoke('serviceAccount');

$this->assertEquals($expectedEmail, $res->returnVal());
}
}

class BigQueryTestClient extends BigQueryClient
Expand Down
37 changes: 37 additions & 0 deletions BigQuery/tests/Snippet/NumericTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\BigQuery\Tests\Snippet;

use Google\Cloud\BigQuery\Numeric;
use Google\Cloud\Core\Testing\Snippet\SnippetTestCase;

/**
* @group bigquery
*/
class NumericTest extends SnippetTestCase
{
public function testClass()
{
$expected = new Numeric('99999999999999999999999999999999999999.999999999');
$snippet = $this->snippetFromClass(Numeric::class);
$res = $snippet->invoke('numeric');

$this->assertInstanceOf(Numeric::class, $res->returnVal());
$this->assertEquals($expected, $res->returnVal());
}
}
12 changes: 8 additions & 4 deletions BigQuery/tests/System/LoadDataAndQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace Google\Cloud\BigQuery\Tests\System;

use Google\Cloud\BigQuery\Bytes;
use Google\Cloud\BigQuery\Numeric;
use Google\Cloud\BigQuery\Date;
use Google\Cloud\Core\ExponentialBackoff;
use Google\Cloud\BigQuery\Time;
Expand Down Expand Up @@ -60,7 +61,7 @@ public function setUp()
'NextVacation' => self::$client->date(new \DateTime('2020-10-11')),
'FavoriteTime' => new \DateTime('1920-01-01 15:15:12')
],
'FavoriteNumbers' => [10, 11]
'FavoriteNumbers' => [new Numeric('.123'), new Numeric('123.')]
];
}

Expand Down Expand Up @@ -133,8 +134,8 @@ public function testRunQuery($useLegacySql)
$expectedRow = $this->row;
$expectedBytes = $expectedRow['Spells'][0]['Icon'];
$actualBytes = $actualRow['Spells'][0]['Icon'];
unset($expectedRow['ImportantDates']);
unset($expectedRow['FavoriteNumbers']);
unset($expectedRow['ImportantDates']);
unset($expectedRow['Spells'][0]['Icon']);
unset($actualRow['Spells'][0]['Icon']);

Expand Down Expand Up @@ -216,9 +217,11 @@ public function testRunQueryWithNamedParameters()
. '@datetime as datetime,'
. '@date as date,'
. '@time as time,'
. '@bytes as bytes';
. '@bytes as bytes, '
. '@numeric as numeric';

$bytes = self::$client->bytes('123');
$numeric = self::$client->numeric('9.999999999');
$params = [
'structType' => [
'hello' => 'world'
Expand All @@ -241,7 +244,8 @@ public function testRunQueryWithNamedParameters()
'datetime' => new \DateTime('2003-02-05 11:15:02.421827Z'),
'date' => self::$client->date(new \DateTime('2003-12-12')),
'time' => self::$client->time(new \DateTime('11:15:02')),
'bytes' => $bytes
'bytes' => $bytes,
'numeric' => $numeric
];
$query = self::$client->query($queryString)
->parameters($params);
Expand Down
27 changes: 27 additions & 0 deletions BigQuery/tests/System/ManageJobsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,33 @@ public function testListJobs()
return $job;
}

public function testListJobsWithTimeFilter()
{
$query = self::$client->query(sprintf(
'SELECT * FROM [%s.%s]',
self::$dataset->id(),
self::$table->id()
));
$job = self::$client->startQuery($query);
$info = $job->info();
$jobId = $job->id();
$creationTime = $info['statistics']['creationTime'];
$jobs = self::$client->jobs([
'maxCreationTime' => $creationTime + 1,
'minCreationTime' => $creationTime - 1,
]);
$job = null;

// break early to prevent subsequent requests
foreach ($jobs as $j) {
$job = $j;
break;
}

$this->assertInstanceOf(Job::class, $job);
$this->assertEquals($jobId, $job->id());
}

/**
* @depends testListJobs
*/
Expand Down
Loading

0 comments on commit c2f4028

Please sign in to comment.