Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions bigquery/api/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
</logging>
<filter>
<whitelist>
<directory suffix=".php">./snippets</directory>
<exclude>
<directory suffix=".php">./src</directory>
<exclude>
<directory>./vendor</directory>
</exclude>
</whitelist>
Expand Down
54 changes: 54 additions & 0 deletions bigquery/api/src/dry_run_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Copyright 2022 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.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 3) {
return printf("Usage: php %s PROJECT_ID SQL_QUERY\n", __FILE__);
}
list($_, $projectId, $query) = $argv;

# [START bigquery_query_dry_run]
use Google\Cloud\BigQuery\BigQueryClient;

/** Uncomment and populate these variables in your code */
// $projectId = 'The Google project ID';
// $query = 'SELECT id, view_count FROM `bigquery-public-data.stackoverflow.posts_questions`';

// Construct a BigQuery client object.
$bigQuery = new BigQueryClient([
'projectId' => $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]
59 changes: 59 additions & 0 deletions bigquery/api/src/query_no_cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Copyright 2022 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.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 3) {
return printf("Usage: php %s PROJECT_ID SQL_QUERY\n", __FILE__);
}
list($_, $projectId, $query) = $argv;

# [START bigquery_query_no_cache]
use Google\Cloud\BigQuery\BigQueryClient;

/** Uncomment and populate these variables in your code */
// $projectId = 'The Google project ID';
// $query = 'SELECT id, view_count FROM `bigquery-public-data.stackoverflow.posts_questions`';

// Construct a BigQuery client object.
$bigQuery = new BigQueryClient([
'projectId' => $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]
26 changes: 26 additions & 0 deletions bigquery/api/test/bigqueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down