diff --git a/BigQuery/src/Table.php b/BigQuery/src/Table.php index 46e74f4b905..09e2b7cabe3 100644 --- a/BigQuery/src/Table.php +++ b/BigQuery/src/Table.php @@ -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: + * https://docs.cloud.google.com/bigquery/docs/reference/rest/v2/tables/get#query-parameters + * } * @return array */ public function info(array $options = []) @@ -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 + * } * @return array */ public function reload(array $options = []) 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 @@ +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']); + } }