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

Update Bigtable branch with latest from master #1190

Merged
merged 21 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5b7fac0
Add isRacy() to SafeSearch (#1166)
RobLoach Jul 10, 2018
8d95287
Exclude component vendor folder from snippet coverage (#1168)
jdpedrie Jul 10, 2018
84d4761
Allow context to handle Throwable interface (#1164)
dwsupplee Jul 10, 2018
1234daf
Add getServiceAccount to the BigQueryClient (#1167)
Jul 10, 2018
b47d699
Prepare v0.71.0 (#1169)
Jul 11, 2018
aa17757
[Kms] Regenerate with the new gapic config (#1165)
Jul 12, 2018
8f3de64
Fix firestore queries (#1161)
jdpedrie Jul 12, 2018
19072fe
Bump gax to 0.35 (#1170)
Jul 12, 2018
c846ba5
Add an interactive release builder. (#1160)
jdpedrie Jul 16, 2018
0991cfb
Add getServiceAccount method to StorageClient (#1173)
dwsupplee Jul 16, 2018
2070cd4
Re-generate library using Tasks/synth.py (#1174)
dpebot Jul 17, 2018
3c5c274
Add support for Numeric type (#1172)
Jul 17, 2018
0488b2d
[Breaking Change] Add support for Document Snapshots in Firestore Que…
jdpedrie Jul 18, 2018
6eb5bad
Fix Storage Requesterpays system tests (#1180)
jdpedrie Jul 18, 2018
a9d8ff2
Bandaid for protobuf 4761 (#1176)
Jul 19, 2018
42e0b9f
Prepare v0.72.0 (#1181)
Jul 19, 2018
c358e8c
Added a document for the time filter on BigQueryClient->jobs() (#1183)
Jul 20, 2018
bc22ba1
Narrowed the time filter in the system test (#1185)
Jul 20, 2018
2e224af
Re-generate library using BigQueryDataTransfer/synth.py (#1184)
dpebot Jul 23, 2018
4a49232
pin auth version until we have a way to silence warnings (#1189)
dwsupplee Jul 23, 2018
e8d893d
Merge remote-tracking branch 'origin/master' into bigtable
dwsupplee Jul 23, 2018
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
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