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
33 changes: 31 additions & 2 deletions BigQuery/src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,23 @@ public function insertRows(array $rows, array $options = [])
*
* @see https://cloud.google.com/bigquery/docs/reference/rest/v2/tables Tables resource documentation.
*
* @param array $options [optional] Configuration options.
* @param array $options [optional] {
* Configuration options.
*
* @type string $selectedFields List of table schema fields to return
* (comma-separated). If unspecified, all fields are returned.
* @type string $view Specifies the view that determines which table
* information is returned. Acceptable values are defined in
* {@see \Google\Cloud\BigQuery\TableMetadataView}. By default,
* basic table information and storage statistics (STORAGE_STATS)
* are returned.
*
* **Note:** If metadata is already cached, $options will be ignored.
* Use {@see Table::reload()} to force a refresh with specific options.
*
* More information:
Comment thread
Hectorhammett marked this conversation as resolved.
* https://docs.cloud.google.com/bigquery/docs/reference/rest/v2/tables/get#query-parameters
* }
* @return array
*/
public function info(array $options = [])
Expand All @@ -741,7 +757,20 @@ public function info(array $options = [])
*
* @see https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/get Tables get API documentation.
*
* @param array $options [optional] Configuration options.
* @param array $options [optional] {
* Configuration options.
*
* @type string $selectedFields List of table schema fields to return
* (comma-separated). If unspecified, all fields are returned.
* @type string $view Specifies the view that determines which table
* information is returned. Acceptable values are defined in
* {@see \Google\Cloud\BigQuery\TableMetadataView}. By default,
* basic table information and storage statistics (STORAGE_STATS)
* are returned.
*
* More information:
* https://docs.cloud.google.com/bigquery/docs/reference/rest/v2/tables/get#query-parameters
Comment thread
Hectorhammett marked this conversation as resolved.
* }
* @return array
*/
public function reload(array $options = [])
Expand Down
45 changes: 45 additions & 0 deletions BigQuery/src/TableMetadataView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright 2026 Google Inc. All Rights Reserved.
*
* 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.
*/

namespace Google\Cloud\BigQuery;

class TableMetadataView
{
/**
* Includes basic table information including schema and partitioning specification.
* This view does not include storage statistics such as numRows or numBytes.
* This view is significantly more efficient and should be used to support high query rates.
*/
public const BASIC = 'BASIC';

/**
* Includes all table information, including storage statistics.
* It returns same information as STORAGE_STATS view, but may contain additional information in the future.
*/
public const FULL = 'FULL';

/**
* Includes all information in the BASIC view as well as storage statistics
* (numBytes, numLongTermBytes, numRows and lastModifiedTime).
*/
public const STORAGE_STATS = 'STORAGE_STATS';

/**
* The default value. Default to the STORAGE_STATS view.
*/
public const UNSPECIFIED = 'TABLE_METADATA_VIEW_UNSPECIFIED';
}
30 changes: 30 additions & 0 deletions BigQuery/tests/System/ManageTablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\BigQuery\Table;
use Google\Cloud\BigQuery\TableMetadataView;
use Google\Cloud\Core\ExponentialBackoff;
use Google\Cloud\Core\Exception\FailedPreconditionException;

Expand Down Expand Up @@ -454,4 +455,33 @@ public function referenceFileSchemaTestUris()
],
];
}

public function testTableView()
{
$id = uniqid(self::TESTING_PREFIX);
$table = self::$dataset->createTable($id, [
'schema' => [
'fields' => [
['name' => 'column', 'type' => 'STRING']
]
]
]);

$this->runJob($table->load('{"column": "test"}' . PHP_EOL, [
'configuration' => [
'load' => [
'sourceFormat' => 'NEWLINE_DELIMITED_JSON'
]
]
]));

// BASIC view should not include storage statistics
$info = $table->reload(['view' => TableMetadataView::BASIC]);
$this->assertArrayNotHasKey('numRows', $info);

// FULL view should include storage statistics
$info = $table->reload(['view' => TableMetadataView::FULL]);
$this->assertArrayHasKey('numRows', $info);
$this->assertEquals(1, $info['numRows']);
}
}
Loading