From c358e8c86ddd705a9753c3e2e69855d4f7b4c639 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Fri, 20 Jul 2018 06:19:57 -0700 Subject: [PATCH] Added a document for the time filter on BigQueryClient->jobs() (#1183) --- BigQuery/src/BigQueryClient.php | 4 ++++ BigQuery/tests/System/ManageJobsTest.php | 27 ++++++++++++++++++++++ BigQuery/tests/Unit/BigQueryClientTest.php | 25 ++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/BigQuery/src/BigQueryClient.php b/BigQuery/src/BigQueryClient.php index 824a5bff0c97..231ce39593ed 100644 --- a/BigQuery/src/BigQueryClient.php +++ b/BigQuery/src/BigQueryClient.php @@ -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 */ diff --git a/BigQuery/tests/System/ManageJobsTest.php b/BigQuery/tests/System/ManageJobsTest.php index a41e5e87aeb2..a618920fce2e 100644 --- a/BigQuery/tests/System/ManageJobsTest.php +++ b/BigQuery/tests/System/ManageJobsTest.php @@ -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 + 1000, + 'minCreationTime' => $creationTime - 1000, + ]); + $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 */ diff --git a/BigQuery/tests/Unit/BigQueryClientTest.php b/BigQuery/tests/Unit/BigQueryClientTest.php index c765c62858ad..dca5f11f1e63 100644 --- a/BigQuery/tests/Unit/BigQueryClientTest.php +++ b/BigQuery/tests/Unit/BigQueryClientTest.php @@ -257,6 +257,31 @@ public function testGetsJobsWithToken() $this->assertEquals(self::JOB_ID, $job[1]->id()); } + public function testGetsJobsWithTimeFilter() + { + $client = $this->getClient(); + $now = round(microtime(true) * 1000); + $max = $now + 1000; + $min = $now - 1000; + $token = 'token'; + $this->connection->listJobs([ + 'projectId' => self::PROJECT_ID, + 'maxCreationTime' => $max, + 'minCreationTime' => $min + ])->willReturn([ + 'jobs' => [ + ['jobReference' => ['jobId' => self::JOB_ID]] + ] + ])->shouldBeCalledTimes(1); + $client->___setProperty('connection', $this->connection->reveal()); + $job = iterator_to_array($client->jobs([ + 'minCreationTime' => $min, + 'maxCreationTime' => $max, + ])); + + $this->assertEquals(self::JOB_ID, $job[0]->id()); + } + public function testGetsDataset() { $client = $this->getClient();