listTableData() public method

public listTableData ( array $args = [] ) : array
$args array
return array
Example #1
0
 /**
  * Retrieves the rows associated with the table and merges them together
  * with the schema.
  *
  * Example:
  * ```
  * foreach ($table->rows() as $row) {
  *     echo $row['name'];
  * }
  * ```
  *
  * @see https://cloud.google.com/bigquery/docs/reference/v2/tabledata/list Tabledata list API Documentation.
  *
  * @param array $options [optional] {
  *     Configuration options.
  *
  *     @type int $maxResults Maximum number of results to return.
  *     @type int $startIndex Zero-based index of the starting row.
  * }
  * @return \Generator<array>
  */
 public function rows(array $options = [])
 {
     $options['pageToken'] = null;
     $schema = $this->info()['schema']['fields'];
     do {
         $response = $this->connection->listTableData($options + $this->identity);
         if (!isset($response['rows'])) {
             return;
         }
         foreach ($response['rows'] as $rows) {
             $row = [];
             foreach ($rows['f'] as $key => $field) {
                 $row[$schema[$key]['name']] = $field['v'];
             }
             (yield $row);
         }
         $options['pageToken'] = isset($response['nextPageToken']) ? $response['nextPageToken'] : null;
     } while ($options['pageToken']);
 }