Skip to content

Commit

Permalink
Added a document for the time filter on BigQueryClient->jobs() (#1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
Takashi Matsuo authored and dwsupplee committed Jul 20, 2018
1 parent 42e0b9f commit c358e8c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions BigQuery/src/BigQueryClient.php
Original file line number Diff line number Diff line change
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
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 + 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
*/
Expand Down
25 changes: 25 additions & 0 deletions BigQuery/tests/Unit/BigQueryClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c358e8c

Please sign in to comment.