public function testRunQueryAsJobWithNamedParameters()
{
$date = '2000-01-01';
$query = 'WITH data AS' . '(SELECT "Dave" as name, DATE("1999-01-01") as date, 1.1 as floatNum, 1 as intNum, true as boolVal ' . 'UNION ALL ' . 'SELECT "John" as name, DATE("2000-01-01") as date, 1.2 as floatNum, 2 as intNum, false as boolVal) ' . 'SELECT * FROM data ' . 'WHERE name = @name AND date >= @date AND floatNum = @numbers.floatNum AND intNum = @numbers.intNum AND boolVal = @boolVal';
$job = self::$client->runQueryAsJob($query, ['parameters' => ['name' => 'John', 'date' => self::$client->date(new \DateTime($date)), 'numbers' => ['floatNum' => 1.2, 'intNum' => 2], 'boolVal' => false]]);
$results = $job->queryResults();
$backoff = new ExponentialBackoff(8);
$backoff->execute(function () use($results) {
$results->reload();
if (!$results->isComplete()) {
throw new \Exception();
}
});
if (!$results->isComplete()) {
$this->fail('Query did not complete within the allotted time.');
}
$actualRows = iterator_to_array($results->rows());
$expectedRows = [['name' => 'John', 'floatNum' => 1.2, 'intNum' => 2, 'boolVal' => false, 'date' => new Date(new \DateTime($date))]];
$this->assertEquals($expectedRows, $actualRows);
}