Spanner/src/Result.php
public function rows($format = self::RETURN_ASSOCIATIVE)
    {
        $bufferedResults = [];
        $call = $this->call;
        $generator = null;
        $shouldRetry = false;
        $backoff = new ExponentialBackoff($this->retries, function ($ex) {
            if ($ex instanceof ServiceException) {
                return $ex->getCode() === Grpc\STATUS_UNAVAILABLE;
            }

            return false;
        });

        $valid = $backoff->execute(function () use ($call, &$generator) {
            $generator = $call();
            return $generator->valid();
        });

        while ($valid) {
            try {
                $result = $generator->current();
                $bufferedResults[] = $result;
                $this->setResultData($result, $format);

                $empty = false;
                if (!isset($result['values']) || $this->columnCount === 0) {
                    $empty = true;
                }

                $hasResumeToken = $this->isSetAndTrue($result, 'resumeToken');
                if ($hasResumeToken || count($bufferedResults) >= self::BUFFER_RESULT_LIMIT) {
                    $chunkedResult = null;
                    if (!$empty) {
                        list($yieldableRows, $chunkedResult) = $this->parseRowsFromBufferedResults($bufferedResults);

                        foreach ($yieldableRows as $row) {
                            yield $this->mapper->decodeValues($this->columns, $row, $format);
                        }
                    }

                    // Now that we've yielded all available rows, flush the buffer.
                    $bufferedResults = [];
                    $shouldRetry = $hasResumeToken;

                    // If the last item in the buffer had a chunked value let's
                    // hold on to it so we can stitch it together into a yieldable
                    // result.
                    if ($chunkedResult) {
                        $bufferedResults[] = $chunkedResult;
                    }
                }

                $generator->next();
                $valid = $generator->valid();
            } catch (ServiceException $ex) {
                if ($shouldRetry && $ex->getCode() === Grpc\STATUS_UNAVAILABLE) {
                    // Attempt to resume using our last stored resume token. If we
                    // successfully resume, flush the buffer.
                    $generator = $backoff->execute($call, [$this->resumeToken]);
                    $bufferedResults = [];

                    continue;
                }

                throw $ex;
            }
        }

        // If there are any results remaining in the buffer, yield them.
        if ($bufferedResults) {
            list($yieldableRows, $chunkedResult) = $this->parseRowsFromBufferedResults($bufferedResults);

            foreach ($yieldableRows as $row) {
                yield $this->mapper->decodeValues($this->columns, $row, $format);
            }
        }
    }
public function rows($format = self::RETURN_ASSOCIATIVE)
    {
        $bufferedResults = [];
        $call = $this->call;
        $generator = null;
        $shouldRetry = false;
        $backoff = new ExponentialBackoff($this->retries, function ($ex) {
            if ($ex instanceof ServiceException) {
                return $ex->getCode() === Grpc\STATUS_UNAVAILABLE;
            }

            return false;
        });

        $valid = $backoff->execute(function () use ($call, &$generator) {
            $generator = $call();
            return $generator->valid();
        });

        while ($valid) {
            try {
                $result = $generator->current();
                $bufferedResults[] = $result;
                $this->setResultData($result, $format);

                $empty = false;
                if (!isset($result['values']) || $this->columnCount === 0) {
                    $empty = true;
                }

                $hasResumeToken = $this->isSetAndTrue($result, 'resumeToken');
                if ($hasResumeToken || count($bufferedResults) >= self::BUFFER_RESULT_LIMIT) {
                    $chunkedResult = null;
                    if (!$empty) {
                        list($yieldableRows, $chunkedResult) = $this->parseRowsFromBufferedResults($bufferedResults);

                        foreach ($yieldableRows as $row) {
                            yield $this->mapper->decodeValues($this->columns, $row, $format);
                        }
                    }

                    // Now that we've yielded all available rows, flush the buffer.
                    $bufferedResults = [];
                    $shouldRetry = $hasResumeToken;

                    // If the last item in the buffer had a chunked value let's
                    // hold on to it so we can stitch it together into a yieldable
                    // result.
                    if ($chunkedResult) {
                        $bufferedResults[] = $chunkedResult;
                    }
                }

                $generator->next();
                $valid = $generator->valid();
            } catch (ServiceException $ex) {
                if ($shouldRetry && $ex->getCode() === Grpc\STATUS_UNAVAILABLE) {
                    // Attempt to resume using our last stored resume token. If we
                    // successfully resume, flush the buffer.
                    $generator = $backoff->execute($call, [$this->resumeToken]);
                    $bufferedResults = [];

                    continue;
                }

                throw $ex;
            }
        }

        // If there are any results remaining in the buffer, yield them.
        if ($bufferedResults) {
            list($yieldableRows, $chunkedResult) = $this->parseRowsFromBufferedResults($bufferedResults);

            foreach ($yieldableRows as $row) {
                yield $this->mapper->decodeValues($this->columns, $row, $format);
            }
        }
    }
public function rows ( $ format = self :: RETURN_ASSOCIATIVE ) { $ bufferedResults = [ ] ; $ call = $ this -> call ; $ generator = null ; $ shouldRetry = false ; $ backoff = new ExponentialBackoff ( $ this -> retries , function ( $ ex ) { if ( $ ex instanceof ServiceException ) { return $ ex -> getCode ( ) === Grpc \ STATUS_UNAVAILABLE ; } return false ; } ) ; $ valid = $ backoff -> execute ( function ( ) use ( $ call , & $ generator ) { $ generator = $ call ( ) ; return $ generator -> valid ( ) ; } ) ; while ( $ valid ) { try { $ result = $ generator -> current ( ) ; $ bufferedResults [ ] = $ result ; $ this -> setResultData ( $ result , $ format ) ; $ empty = false ; if ( ! isset ( $ result [ 'values' ] ) || $ this -> columnCount === 0 ) { $ empty = true ; } $ hasResumeToken = $ this -> isSetAndTrue ( $ result , 'resumeToken' ) ; if ( $ hasResumeToken || count ( $ bufferedResults ) >= self :: BUFFER_RESULT_LIMIT ) { $ chunkedResult = null ; if ( ! $ empty ) { list ( $ yieldableRows , $ chunkedResult ) = $ this -> parseRowsFromBufferedResults ( $ bufferedResults ) ; foreach ( $ yieldableRows as $ row ) { yield $ this -> mapper -> decodeValues ( $ this -> columns , $ row , $ format ) ; } } // Now that we've yielded all available rows, flush the buffer. $ bufferedResults = [ ] ; $ shouldRetry = $ hasResumeToken ; // If the last item in the buffer had a chunked value let's // hold on to it so we can stitch it together into a yieldable // result. if ( $ chunkedResult ) { $ bufferedResults [ ] = $ chunkedResult ; } } $ generator -> next ( ) ; $ valid = $ generator -> valid ( ) ; } catch ( ServiceException $ ex ) { if ( $ shouldRetry && $ ex -> getCode ( ) === Grpc \ STATUS_UNAVAILABLE ) { // Attempt to resume using our last stored resume token. If we // successfully resume, flush the buffer. $ generator = $ backoff -> execute ( $ call , [ $ this -> resumeToken ] ) ; $ bufferedResults = [ ] ; continue ; } throw $ ex ; } } // If there are any results remaining in the buffer, yield them. if ( $ bufferedResults ) { list ( $ yieldableRows , $ chunkedResult ) = $ this -> parseRowsFromBufferedResults ( $ bufferedResults ) ; foreach ( $ yieldableRows as $ row ) { yield $ this -> mapper -> decodeValues ( $ this -> columns , $ row , $ format ) ; } } }
Return the formatted and decoded rows. If the stream is interrupted and
a resume token is available, attempts will be made on your behalf to
resume.

Example:
```
$rows = $result->rows();
```

@param string $format Determines the format in which rows are returned.
`Result::RETURN_NAME_VALUE_PAIR` returns items as a
multi-dimensional array containing a name and a value key.
Ex: `[0 => ['name' => 'column1', 'value' => 'my_value']]`.
`Result::RETURN_ASSOCIATIVE` returns items as an associative array
with the column name as the key. Please note with this option, if
duplicate column names are present a `\RuntimeException` will be
thrown. `Result::RETURN_ZERO_INDEXED` returns items as a 0 indexed
array, with the key representing the column number as found by
executing {@see Google\Cloud\Spanner\Result::columns()}. Ex:
`[0 => 'my_value']`. **Defaults to** `Result::RETURN_ASSOCIATIVE`.
@return \Generator
@throws \InvalidArgumentException When an invalid format is provided.
@throws \RuntimeException When duplicate column names exist with a
selected format of `Result::RETURN_ASSOCIATIVE`.
Return the formatted and decoded rows . If the stream is interrupted and a resume token is available attempts will be made on your behalf to resume .