CassandraDataIterator error when lots of empty rows #25

Open
LordStephen opened this Issue Nov 2, 2012 · 0 comments

1 participant

@LordStephen

In the function CassandraDataIterator::next(), the next() function is recursivly called until it find a valid value.

Depending on the data this function can pass the maximum nesting level throwing this error:

Fatal error: Maximum function nesting level of '100' reached, aborting!

I coded this fix :

public function next() {
    $value = null;
    $beyondLastRow = false;

    if (!empty($this->buffer)) {
        $this->nextStartKey = key($this->buffer);

        $value = next($this->buffer);

        if (count(current($this->buffer)) == 0) {
            $value = $this->findNextValidValue();
        } 

        $key = key($this->buffer);
        if (isset($key)) {
            $this->rowsSeen++;

            if (
                $this->rowCountLimit !== null
                && $this->rowsSeen > $this->rowCountLimit
            ) {
                $this->isValid = false;

                return null;
            }
        } else {
            $beyondLastRow = true;
        }           
    } else {
        $beyondLastRow = true;
    }

    if ($beyondLastRow) {
        if ($this->currentPageSize < $this->expectedPageSize) {
            $this->isValid = false;
        } else {
            $this->updateBuffer();

            if (count($this->buffer) == 1) {
                $this->isValid = false;
            } else {
                $this->next();
            }
        }
    }

    return $value;
}

private function findNextValidValue(){
    $value = next($this->buffer);
    while (count(current($this->buffer)) == 0) {
        $value = next($this->buffer);
    }
    return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment