Skip to content

Commit 19c2147

Browse files
feat(BigQuery): Add documentation and constants for the view option on table resources (#9170)
1 parent d2977c9 commit 19c2147

3 files changed

Lines changed: 106 additions & 2 deletions

File tree

BigQuery/src/Table.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,23 @@ public function insertRows(array $rows, array $options = [])
717717
*
718718
* @see https://cloud.google.com/bigquery/docs/reference/rest/v2/tables Tables resource documentation.
719719
*
720-
* @param array $options [optional] Configuration options.
720+
* @param array $options [optional] {
721+
* Configuration options.
722+
*
723+
* @type string $selectedFields List of table schema fields to return
724+
* (comma-separated). If unspecified, all fields are returned.
725+
* @type string $view Specifies the view that determines which table
726+
* information is returned. Acceptable values are defined in
727+
* {@see \Google\Cloud\BigQuery\TableMetadataView}. By default,
728+
* basic table information and storage statistics (STORAGE_STATS)
729+
* are returned.
730+
*
731+
* **Note:** If metadata is already cached, $options will be ignored.
732+
* Use {@see Table::reload()} to force a refresh with specific options.
733+
*
734+
* More information:
735+
* https://docs.cloud.google.com/bigquery/docs/reference/rest/v2/tables/get#query-parameters
736+
* }
721737
* @return array
722738
*/
723739
public function info(array $options = [])
@@ -741,7 +757,20 @@ public function info(array $options = [])
741757
*
742758
* @see https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/get Tables get API documentation.
743759
*
744-
* @param array $options [optional] Configuration options.
760+
* @param array $options [optional] {
761+
* Configuration options.
762+
*
763+
* @type string $selectedFields List of table schema fields to return
764+
* (comma-separated). If unspecified, all fields are returned.
765+
* @type string $view Specifies the view that determines which table
766+
* information is returned. Acceptable values are defined in
767+
* {@see \Google\Cloud\BigQuery\TableMetadataView}. By default,
768+
* basic table information and storage statistics (STORAGE_STATS)
769+
* are returned.
770+
*
771+
* More information:
772+
* https://docs.cloud.google.com/bigquery/docs/reference/rest/v2/tables/get#query-parameters
773+
* }
745774
* @return array
746775
*/
747776
public function reload(array $options = [])

BigQuery/src/TableMetadataView.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright 2026 Google Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Google\Cloud\BigQuery;
19+
20+
class TableMetadataView
21+
{
22+
/**
23+
* Includes basic table information including schema and partitioning specification.
24+
* This view does not include storage statistics such as numRows or numBytes.
25+
* This view is significantly more efficient and should be used to support high query rates.
26+
*/
27+
public const BASIC = 'BASIC';
28+
29+
/**
30+
* Includes all table information, including storage statistics.
31+
* It returns same information as STORAGE_STATS view, but may contain additional information in the future.
32+
*/
33+
public const FULL = 'FULL';
34+
35+
/**
36+
* Includes all information in the BASIC view as well as storage statistics
37+
* (numBytes, numLongTermBytes, numRows and lastModifiedTime).
38+
*/
39+
public const STORAGE_STATS = 'STORAGE_STATS';
40+
41+
/**
42+
* The default value. Default to the STORAGE_STATS view.
43+
*/
44+
public const UNSPECIFIED = 'TABLE_METADATA_VIEW_UNSPECIFIED';
45+
}

BigQuery/tests/System/ManageTablesTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use Google\Cloud\BigQuery\BigQueryClient;
2121
use Google\Cloud\BigQuery\Table;
22+
use Google\Cloud\BigQuery\TableMetadataView;
2223
use Google\Cloud\Core\ExponentialBackoff;
2324
use Google\Cloud\Core\Exception\FailedPreconditionException;
2425

@@ -454,4 +455,33 @@ public function referenceFileSchemaTestUris()
454455
],
455456
];
456457
}
458+
459+
public function testTableView()
460+
{
461+
$id = uniqid(self::TESTING_PREFIX);
462+
$table = self::$dataset->createTable($id, [
463+
'schema' => [
464+
'fields' => [
465+
['name' => 'column', 'type' => 'STRING']
466+
]
467+
]
468+
]);
469+
470+
$this->runJob($table->load('{"column": "test"}' . PHP_EOL, [
471+
'configuration' => [
472+
'load' => [
473+
'sourceFormat' => 'NEWLINE_DELIMITED_JSON'
474+
]
475+
]
476+
]));
477+
478+
// BASIC view should not include storage statistics
479+
$info = $table->reload(['view' => TableMetadataView::BASIC]);
480+
$this->assertArrayNotHasKey('numRows', $info);
481+
482+
// FULL view should include storage statistics
483+
$info = $table->reload(['view' => TableMetadataView::FULL]);
484+
$this->assertArrayHasKey('numRows', $info);
485+
$this->assertEquals(1, $info['numRows']);
486+
}
457487
}

0 commit comments

Comments
 (0)