diff --git a/bigquery/api/phpunit.xml.dist b/bigquery/api/phpunit.xml.dist index fc657b7c2f..b038a4558e 100644 --- a/bigquery/api/phpunit.xml.dist +++ b/bigquery/api/phpunit.xml.dist @@ -25,8 +25,8 @@ - ./snippets - + ./src + ./vendor diff --git a/bigquery/api/src/dry_run_query.php b/bigquery/api/src/dry_run_query.php new file mode 100644 index 0000000000..5b98237dab --- /dev/null +++ b/bigquery/api/src/dry_run_query.php @@ -0,0 +1,54 @@ + $projectId, +]); + +// Set job configs +$jobConfig = $bigQuery->query($query); +$jobConfig->useQueryCache(false); +$jobConfig->dryRun(true); + +// Extract query results +$queryJob = $bigQuery->startJob($jobConfig); +$info = $queryJob->info(); + +printf('This query will process %s bytes' . PHP_EOL, $info['statistics']['totalBytesProcessed']); +# [END bigquery_query_dry_run] diff --git a/bigquery/api/src/query_no_cache.php b/bigquery/api/src/query_no_cache.php new file mode 100644 index 0000000000..16569f838f --- /dev/null +++ b/bigquery/api/src/query_no_cache.php @@ -0,0 +1,59 @@ + $projectId, +]); + +// Set job configs +$jobConfig = $bigQuery->query($query); +$jobConfig->useQueryCache(false); + +// Extract query results +$queryResults = $bigQuery->runQuery($jobConfig); + +$i = 0; +foreach ($queryResults as $row) { + printf('--- Row %s ---' . PHP_EOL, ++$i); + foreach ($row as $column => $value) { + printf('%s: %s' . PHP_EOL, $column, json_encode($value)); + } +} +printf('Found %s row(s)' . PHP_EOL, $i); +# [END bigquery_query_no_cache] diff --git a/bigquery/api/test/bigqueryTest.php b/bigquery/api/test/bigqueryTest.php index 97c2a3fecb..8aed3397c9 100644 --- a/bigquery/api/test/bigqueryTest.php +++ b/bigquery/api/test/bigqueryTest.php @@ -287,6 +287,32 @@ public function testRunQueryAsJob() $this->assertStringContainsString('Found 1 row(s)', $output); } + public function testDryRunQuery() + { + $tableId = $this->createTempTable(); + $query = sprintf( + 'SELECT * FROM `%s.%s` LIMIT 1', + self::$datasetId, + $tableId + ); + + $output = $this->runSnippet('dry_run_query', [$query]); + $this->assertStringContainsString('This query will process 126 bytes', $output); + } + + public function testQueryNoCache() + { + $tableId = $this->createTempTable(); + $query = sprintf( + 'SELECT * FROM `%s.%s` LIMIT 1', + self::$datasetId, + $tableId + ); + + $output = $this->runSnippet('query_no_cache', [$query]); + $this->assertStringContainsString('Found 1 row(s)', $output); + } + public function testQueryLegacy() { $output = $this->runSnippet('query_legacy');