// next reads the next row from the input. It returns io.EOF if the input stream
// has ended.
171455
func (n *nextRow) next() error {
	var err error
	n.row, err = n.rowReader.Next()
	if err != nil {
		return err
	}
	if n.row == nil {
		return io.EOF
	}
	return nil
}
501686
func (r *RestartableResultReader) Next() (*sqltypes.Result, error) {
	result, err := r.output.Recv()
	if err != nil && err != io.EOF {
		// We start the retries only on the second attempt to avoid the cost
		// of starting a timer (for the retry timeout) for every Next() call
		// when no error occurs.
		alias := topoproto.TabletAliasString(r.tablet.Alias)
		statsStreamingQueryErrorsCounters.Add(alias, 1)
		log.V(2).Infof("tablet=%v table=%v chunk=%v: Failed to read next rows from active streaming query. Trying to restart stream on the same tablet. Original Error: %v", alias, r.td.Name, r.chunk, err)
		result, err = r.nextWithRetries()
	}
	if result != nil && len(result.Rows) > 0 {
		r.lastRow = result.Rows[len(result.Rows)-1]
	}
	return result, err
}
88480
func (rows *Rows) Next() bool {
	if rows.total >= rows.current+1 {
		rows.current++
		return true
	}
	return false
}
1005373
func (d *Decoder) Next() ([]byte, error) {
	defer func() { d.n++ }()

	raw := bytes.NewBuffer(nil)
	frame := io.TeeReader(d.r, raw)
	h, err := readFrameHeader(frame, d.StreamInfo)
	if err == io.EOF {
		return nil, err
	} else if err != nil {
		return nil, errors.New("Failed to read the frame header: " + err.Error())
	}

	br := bit.NewReader(frame)
	data := make([][]int32, h.channelAssignment.nChannels())
	for ch := range data {
		if data[ch], err = readSubFrame(br, h, ch); err != nil {
			return nil, err
		}
	}

	// The bit.Reader buffers up to the next byte, so reading from frame occurs
	// on the next byte boundary.  That takes care of the padding to align to the
	// next byte.
	var crc16 [2]byte
	if _, err := io.ReadFull(frame, crc16[:]); err != nil {
		return nil, err
	}
	if err = verifyCRC16(raw.Bytes()); err != nil {
		return nil, err
	}

	fixChannels(data, h.channelAssignment)
	return interleave(data, d.BitsPerSample)
}
749856
func (it *ReaderIteratorImpl) Next() (v int64, err error) {
	nextValues, err := it.nextN(1)
	if err != nil {
		return 0, err
	}
	assert(len(nextValues) > 0)
	return nextValues[0], nil
}
429883
func (r *charIter) next() (byte, byte, bool) {
	// we have reached the last string in the index, end
	if r.isEnd() {
		return 0, 0, false
	}

	b := r.seq[r.si][r.i]
	sep := r.sep[r.si]
	r.i++

	// current string index exceeded the last char of the current string
	// move to the next string if it's present
	if r.i >= len(r.seq[r.si]) && r.si < len(r.seq)-1 {
		r.si++
		r.i = 0
	}

	return b, sep, true
}
388646
func (r *walReader) next() bool {
	if r.cur >= len(r.files) {
		return false
	}
	cf := r.files[r.cur]

	// Remember the offset after the last correctly read entry. If the next one
	// is corrupted, this is where we can safely truncate.
	r.lastOffset, r.err = cf.Seek(0, io.SeekCurrent)
	if r.err != nil {
		return false
	}

	et, flag, b, err := r.entry(cf)
	// If we reached the end of the reader, advance to the next one
	// and close.
	// Do not close on the last one as it will still be appended to.
	if err == io.EOF {
		if r.cur == len(r.files)-1 {
			return false
		}
		// Current reader completed, close and move to the next one.
		if err := cf.Close(); err != nil {
			r.err = err
			return false
		}
		r.cur++
		return r.next()
	}
	if err != nil {
		r.err = err
		return false
	}

	r.curType = et
	r.curFlag = flag
	r.curBuf = b
	return r.err == nil
}
257087
func (e *StringDecoder) Next() bool {
	if e.err != nil {
		return false
	}

	e.i += e.l
	return e.i < len(e.b)
}
67898
func (i *Uint32) Next() uint32 {
	i.lock.Lock()
	defer i.lock.Unlock()
	i.increment++
	return i.increment
}
1021288
func (rows *Rows) Next() bool {
	if rows.closed {
		return false
	}

	rows.rowCount++
	rows.columnIdx = 0

	for {
		msg, err := rows.conn.rxMsg()
		if err != nil {
			rows.fatal(err)
			return false
		}

		switch msg := msg.(type) {
		case *pgproto3.RowDescription:
			rows.fields = rows.conn.rxRowDescription(msg)
			for i := range rows.fields {
				if dt, ok := rows.conn.ConnInfo.DataTypeForOID(rows.fields[i].DataType); ok {
					rows.fields[i].DataTypeName = dt.Name
					rows.fields[i].FormatCode = TextFormatCode
				} else {
					fd := rows.fields[i]
					rows.fatal(errors.Errorf("unknown oid: %d, name: %s", fd.DataType, fd.Name))
					return false
				}
			}
		case *pgproto3.DataRow:
			if len(msg.Values) != len(rows.fields) {
				rows.fatal(ProtocolError(fmt.Sprintf("Row description field count (%v) and data row field count (%v) do not match", len(rows.fields), len(msg.Values))))
				return false
			}

			rows.values = msg.Values
			return true
		case *pgproto3.CommandComplete:
			if rows.batch != nil {
				rows.batch.pendingCommandComplete = false
			}
			rows.Close()
			return false

		default:
			err = rows.conn.processContextFreeMsg(msg)
			if err != nil {
				rows.fatal(err)
				return false
			}
		}
	}
}
613851
func (r *resultSet) Next() bool {
	if r == nil {
		return false
	}

	row := r.cur.Next()
	if row == nil {
		return false
	}

	r.row = *row

	return true
}
779134
func (s *sequences) next(seq string) int {
	if s.s == nil {
		s.s = make(map[string]int, 1)
	}
	v := s.s[seq] + 1
	s.s[seq] = v
	return v
}
1048894
func (ics *IterateCloserStruct) Next(key, val SophieReader) error {
	if ics.NextF != nil {
		return ics.NextF(key, val)
	}
	return io.EOF
}
938777
func (bg *Writer) Next() (int, error) {
	if bg.closed {
		return 0, ErrClosed
	}
	if err := bg.Error(); err != nil {
		return 0, err
	}

	return bg.active.next, nil
}
722577
func (c *indexSeriesCursor) Next() *reads.SeriesRow {
	if c.eof {
		return nil
	}

	// next series key
	sr, err := c.sqry.Next()
	if err != nil {
		c.err = err
		c.Close()
		return nil
	} else if sr == nil {
		c.Close()
		return nil
	}

	if len(sr.Tags) < 2 {
		// Invariant broken.
		c.err = fmt.Errorf("attempted to emit key with only tags: %s", sr.Tags)
		return nil
	}

	c.row.Name = sr.Name
	//TODO(edd): check this.
	c.row.SeriesTags = copyTags(c.row.SeriesTags, sr.Tags)
	c.row.Tags = copyTags(c.row.Tags, sr.Tags)
	fv := c.row.Tags.Get(models.FieldKeyTagKeyBytes)
	c.row.Field = string(fv)

	if c.cond != nil && c.hasValueExpr {
		// TODO(sgc): lazily evaluate valueCond
		c.row.ValueCond = influxql.Reduce(c.cond, c)
		if reads.IsTrueBooleanLiteral(c.row.ValueCond) {
			// we've reduced the expression to "true"
			c.row.ValueCond = nil
		}
	}

	// Normalise the special tag keys to the emitted format.
	mv := c.row.Tags.Get(models.MeasurementTagKeyBytes)
	c.row.Tags.Delete(models.MeasurementTagKeyBytes)
	c.row.Tags.Set(measurementKeyBytes, mv)
	c.row.Tags.Delete(models.FieldKeyTagKeyBytes)
	c.row.Tags.Set(fieldKeyBytes, fv)

	return &c.row
}
511076
func (e *TableScanExec) Next(ctx context.Context, req *chunk.RecordBatch) error {
	if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
		span1 := span.Tracer().StartSpan("tableScan.Next", opentracing.ChildOf(span.Context()))
		defer span1.Finish()
	}
	if e.runtimeStats != nil {
		start := time.Now()
		defer func() { e.runtimeStats.Record(time.Since(start), req.NumRows()) }()
	}
	req.GrowAndReset(e.maxChunkSize)
	if e.isVirtualTable {
		return e.nextChunk4InfoSchema(ctx, req.Chunk)
	}
	handle, found, err := e.nextHandle()
	if err != nil || !found {
		return err
	}

	mutableRow := chunk.MutRowFromTypes(e.retTypes())
	for req.NumRows() < req.Capacity() {
		row, err := e.getRow(handle)
		if err != nil {
			return err
		}
		e.seekHandle = handle + 1
		mutableRow.SetDatums(row...)
		req.AppendRow(mutableRow.ToRow())
	}
	return nil
}
1018860
func (iter *iterator) Next() bool {
	if iter.first {
		iter.first = false
		return iter.n != nil
	}

	if iter.n == nil {
		return false
	}

	iter.n = iter.n.forward[0]
	return iter.n != nil
}