BigQuery/src/Table.php
public function insertRows(array $rows, array $options = [])
    {
        if (count($rows) === 0) {
            throw new \InvalidArgumentException('Must provide at least a single row.');
        }

        foreach ($rows as $row) {
            if (!isset($row['data'])) {
                throw new \InvalidArgumentException('A row must have a data key.');
            }

            if (!isset($options['retries']) && !isset($row['insertId'])) {
                $options['retries'] = 0;
            }

            foreach ($row['data'] as $key => $item) {
                $row['data'][$key] = $this->mapper->toBigQuery($item);
            }

            $row['json'] = $row['data'];
            unset($row['data']);
            $options['rows'][] = $row;
        }

        return new InsertResponse(
            $this->handleInsert($options),
            $options['rows']
        );
    }
public function insertRows(array $rows, array $options = [])
    {
        if (count($rows) === 0) {
            throw new \InvalidArgumentException('Must provide at least a single row.');
        }

        foreach ($rows as $row) {
            if (!isset($row['data'])) {
                throw new \InvalidArgumentException('A row must have a data key.');
            }

            if (!isset($options['retries']) && !isset($row['insertId'])) {
                $options['retries'] = 0;
            }

            foreach ($row['data'] as $key => $item) {
                $row['data'][$key] = $this->mapper->toBigQuery($item);
            }

            $row['json'] = $row['data'];
            unset($row['data']);
            $options['rows'][] = $row;
        }

        return new InsertResponse(
            $this->handleInsert($options),
            $options['rows']
        );
    }
public function insertRows ( array $ rows , array $ options = [ ] ) { if ( count ( $ rows ) === 0 ) { throw new \ InvalidArgumentException ( 'Must provide at least a single row.' ) ; } foreach ( $ rows as $ row ) { if ( ! isset ( $ row [ 'data' ] ) ) { throw new \ InvalidArgumentException ( 'A row must have a data key.' ) ; } if ( ! isset ( $ options [ 'retries' ] ) && ! isset ( $ row [ 'insertId' ] ) ) { $ options [ 'retries' ] = 0 ; } foreach ( $ row [ 'data' ] as $ key => $ item ) { $ row [ 'data' ] [ $ key ] = $ this -> mapper -> toBigQuery ( $ item ) ; } $ row [ 'json' ] = $ row [ 'data' ] ; unset ( $ row [ 'data' ] ) ; $ options [ 'rows' ] [ ] = $ row ; } return new InsertResponse ( $ this -> handleInsert ( $ options ) , $ options [ 'rows' ] ) ; }
Insert records into the table without running a load job.

Please note that by default the library will not automatically retry this
call on your behalf unless an `insertId` is set.

Example:
```
$rows = [
[
'insertId' => '1',
'data' => [
'city' => 'Detroit',
'state' => 'MI'
]
],
[
'insertId' => '2',
'data' => [
'city' => 'New York',
'state' => 'NY'
]
]
];

$insertResponse = $table->insertRows($rows);

if (!$insertResponse->isSuccessful()) {
foreach ($insertResponse->failedRows() as $row) {
print_r($row['rowData']);

foreach ($row['errors'] as $error) {
echo $error['reason'] . ': ' . $error['message'] . PHP_EOL;
}
}
}
```

@codingStandardsIgnoreStart
@see https://cloud.google.com/bigquery/docs/reference/v2/tabledata/insertAll Tabledata insertAll API Documentation.
@see https://cloud.google.com/bigquery/streaming-data-into-bigquery Streaming data into BigQuery.

@param array $rows The rows to insert. Each item in the array must
contain a `data` key which is to hold a key/value array with data
matching the schema of the table. Optionally, one may also provide
an `insertId` key which will be used to
[ensure data consistency](https://cloud.google.com/bigquery/streaming-data-into-bigquery#dataconsistency).
@param array $options [optional] {
Configuration options.

@type bool $autoCreate Whether or not to attempt to automatically
create the table in the case it does not exist. Please note, it
will be required to provide a schema through
$tableMetadata['schema'] in the case the table does not already
exist. **Defaults to** `false`.
@type array $tableMetadata Metadata to apply to table to be created. The
full set of metadata are outlined at the
[Table Resource API docs](https://cloud.google.com/bigquery/docs/reference/v2/tables#resource).
Only applies when `autoCreate` is `true`.
@type int $maxRetries The maximum number of times to attempt creating the
table in the case of failure. Please note, each retry attempt
may take up to two minutes. Only applies when `autoCreate` is
`true`. **Defaults to** `100`.
@type bool $skipInvalidRows Insert all valid rows of a request, even
if invalid rows exist. The default value is `false`, which
causes the entire request to fail if any invalid rows exist.
**Defaults to** `false`.
@type bool $ignoreUnknownValues Accept rows that contain values that
do not match the schema. The unknown values are ignored.
The default value is `false`, which treats unknown values as errors.
**Defaults to** `false`.
@type string $templateSuffix If specified, treats the destination
table as a base template, and inserts the rows into an instance
table named "{destination}{templateSuffix}". BigQuery will
manage creation of the instance table, using the schema of the
base template table. See
[Creating tables automatically using template tables](https://cloud.google.com/bigquery/streaming-data-into-bigquery#template-tables)
for considerations when working with templates tables.
}
@return InsertResponse
@throws \InvalidArgumentException If a provided row does not contain a
`data` key, if a schema is not defined when `autoCreate` is
`true`, or if less than 1 row is provided.
@codingStandardsIgnoreEnd
Insert records into the table without running a load job .