From 0efa28dac08318fe748da2b5fe863c223b6db02d Mon Sep 17 00:00:00 2001 From: hectorhammett Date: Wed, 6 May 2026 20:20:13 +0000 Subject: [PATCH 1/2] Add documentation for the new view option on the table resource --- BigQuery/src/Table.php | 21 ++++++++++++++-- BigQuery/tests/System/ManageTablesTest.php | 29 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/BigQuery/src/Table.php b/BigQuery/src/Table.php index 46e74f4b905..70d8eccf9a5 100644 --- a/BigQuery/src/Table.php +++ b/BigQuery/src/Table.php @@ -41,6 +41,10 @@ class Table { const MAX_RETRIES = 100; const INSERT_CREATE_MAX_DELAY_MICROSECONDS = 60000000; + public const BASIC_METADATA_VIEW = 'BASIC'; + public const FULL_METADATA_VIEW = 'FULL'; + public const STORAGE_STATS_METADATA_VIEW = 'STORAGE_STATS'; + public const UNSPECIFIED_METADATA_VIEW = 'TABLE_METADATA_VIEW_UNSPECIFIED'; use ArrayTrait; use ConcurrencyControlTrait; @@ -717,7 +721,15 @@ 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. + * + * **Note:** If metadata is already cached, $options will be ignored. + * Use {@see Table::reload()} to force a refresh with specific options. + * + * More information: + * https://docs.cloud.google.com/bigquery/docs/reference/rest/v2/tables/get#query-parameters + * } * @return array */ public function info(array $options = []) @@ -741,7 +753,12 @@ 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. + * + * More information: + * https://docs.cloud.google.com/bigquery/docs/reference/rest/v2/tables/get#query-parameters + * } * @return array */ public function reload(array $options = []) diff --git a/BigQuery/tests/System/ManageTablesTest.php b/BigQuery/tests/System/ManageTablesTest.php index c2ffe13d690..4feb0ad697e 100644 --- a/BigQuery/tests/System/ManageTablesTest.php +++ b/BigQuery/tests/System/ManageTablesTest.php @@ -454,4 +454,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' => Table::BASIC_METADATA_VIEW]); + $this->assertArrayNotHasKey('numRows', $info); + + // FULL view should include storage statistics + $info = $table->reload(['view' => Table::FULL_METADATA_VIEW]); + $this->assertArrayHasKey('numRows', $info); + $this->assertEquals(1, $info['numRows']); + } } From f43423231a07bdeb0dcab8b71db49562797993c8 Mon Sep 17 00:00:00 2001 From: hectorhammett Date: Mon, 11 May 2026 18:53:15 +0000 Subject: [PATCH 2/2] Add the documentation for each possible view parameter --- BigQuery/src/Table.php | 20 ++++++++-- BigQuery/src/TableMetadataView.php | 45 ++++++++++++++++++++++ BigQuery/tests/System/ManageTablesTest.php | 5 ++- 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 BigQuery/src/TableMetadataView.php diff --git a/BigQuery/src/Table.php b/BigQuery/src/Table.php index 70d8eccf9a5..09e2b7cabe3 100644 --- a/BigQuery/src/Table.php +++ b/BigQuery/src/Table.php @@ -41,10 +41,6 @@ class Table { const MAX_RETRIES = 100; const INSERT_CREATE_MAX_DELAY_MICROSECONDS = 60000000; - public const BASIC_METADATA_VIEW = 'BASIC'; - public const FULL_METADATA_VIEW = 'FULL'; - public const STORAGE_STATS_METADATA_VIEW = 'STORAGE_STATS'; - public const UNSPECIFIED_METADATA_VIEW = 'TABLE_METADATA_VIEW_UNSPECIFIED'; use ArrayTrait; use ConcurrencyControlTrait; @@ -724,6 +720,14 @@ public function insertRows(array $rows, array $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. * @@ -756,6 +760,14 @@ public function info(array $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 * } diff --git a/BigQuery/src/TableMetadataView.php b/BigQuery/src/TableMetadataView.php new file mode 100644 index 00000000000..3fce7183fb8 --- /dev/null +++ b/BigQuery/src/TableMetadataView.php @@ -0,0 +1,45 @@ +reload(['view' => Table::BASIC_METADATA_VIEW]); + $info = $table->reload(['view' => TableMetadataView::BASIC]); $this->assertArrayNotHasKey('numRows', $info); // FULL view should include storage statistics - $info = $table->reload(['view' => Table::FULL_METADATA_VIEW]); + $info = $table->reload(['view' => TableMetadataView::FULL]); $this->assertArrayHasKey('numRows', $info); $this->assertEquals(1, $info['numRows']); }