/* (non-Javadoc)
@see org.apache.hive.service.cli.Operation#getNextRowSet(org.apache.hive.service.cli.FetchOrientation, long)
493459
@Override
  public RowSet getNextRowSet(FetchOrientation orientation, long maxRows) throws HiveSQLException {
    assertState(OperationState.FINISHED);
    validateDefaultFetchOrientation(orientation);
    if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
      rowSet.setStartOffset(0);
    }
    return rowSet.extractSubset((int)maxRows);
  }
200422
@Override
    public T get(int n) {
        checkUnsupportedOperationForIterationOnlyMode("get(int n)");
        
        while ( allResults.size() <= n && nextResultsAvailable() ) {
            moveNextResults(false);
        }

        return allResults.get(n);
    }
112276
private void fetchNextChildHits() throws IOException {
        if (childHits != null) {
            childHits.close();
        }
        ScoreNode nextParent = parents.nextScoreNode();
        if (nextParent != null) {
            try {
                Node parent = (Node)session.getTransientNodesManager().getItemByIdentifier(nextParent.getNodeId(),true);
                childHits = new NodeTraversingQueryHits(parent, false, 1, indexConfig);
            } catch (RepositoryException e) {
                throw Util.createIOException(e);
            }
        } else {
            childHits = null;
        }
    }
366952
public int readNextToTarget(int iTargetPosition, int iRelPosition) throws DBException
    {
        int iRecordStatus = DBConstants.RECORD_NORMAL;
        boolean bMore = true;
        ResultSet resultSet = (ResultSet)this.getResultSet();
        while (m_iRow < iTargetPosition)
        {   // Spin until you get to the row or hit EOF
            try   {
                bMore = resultSet.next();
                if (!bMore)
                {
                    m_iEOFRow = m_iRow;   // Last physical row = this row - 1.
                    break;  // Hit EOF
                }
                m_iRow++; // Current row
            } catch (SQLException e)    {
                DBException dbEx = this.getDatabase().convertError(e);
                int iErrorCode = dbEx.getErrorCode();
                if ((iRelPosition == DBConstants.FIRST_RECORD) || ((iRelPosition == DBConstants.LAST_RECORD)))
                    if (iErrorCode == DBConstants.INVALID_RECORD)
                        return (DBConstants.RECORD_INVALID | DBConstants.RECORD_AT_BOF | DBConstants.RECORD_AT_EOF);    // Move first - no records
                throw dbEx;
            }
        }
        if ((m_iRow == -1) || (iTargetPosition == -1))
            iRecordStatus |= DBConstants.RECORD_INVALID | DBConstants.RECORD_AT_BOF;
        if (!bMore)
        {
            iRecordStatus |= DBConstants.RECORD_AT_EOF;
            int iEOFRow = m_iEOFRow;   // Save for a sec
            this.setResultSet(null, DBConstants.SQL_SELECT_TYPE);  // Can't use anymore
            m_iEOFRow = iEOFRow;       // I do know the EOF
        }
        return iRecordStatus;
    }
794832
@VisibleForTesting
  RangeSet<RowKeyWrapper> rowSetToRangeSet(RowSet btRowSet) {
    RangeSet<RowKeyWrapper> rangeSet = TreeRangeSet.create();
    for (RowRange btRowRange : btRowSet.getRowRangesList()) {
      rangeSet.add(rowRangeToRange(btRowRange));
    }
    for (ByteString key : btRowSet.getRowKeysList()) {
      rangeSet.add(Range.singleton(new RowKeyWrapper(key)));
    }
    return rangeSet;
  }
1359074
@Override
    public Tuple getNext()
            throws IOException {
        Tuple tuple = null;
        try {
            if (isBuildingExample) {
                isBuildingExample = false; // Terminate on the next iteration
                return tupleFactory.newTuple(createPigExample());
            }

            boolean notDone = reader.nextKeyValue();
            if (!notDone) {
                return null;
            }

            ParsedRecord value = reader.getCurrentValue();

            if (value != null) {
                List<Object> values = new ArrayList<>();
                if (onlyWantListOfFields) {
                    values.add(value.getString(ApacheHttpdLogfileRecordReader.FIELDS));
                } else {
                    for (String fieldName : requestedFields) {
                        if (fieldName.endsWith(".*")) {
                            values.add(value.getStringSet(fieldName));
                            continue;
                        } else {
                            EnumSet<Casts> casts = reader.getParser().getCasts(fieldName);

                            if (casts != null) {
                                if (casts.contains(Casts.LONG)) {
                                    values.add(value.getLong(fieldName));
                                    continue;
                                }

                                if (casts.contains(Casts.DOUBLE)) {
                                    values.add(value.getDouble(fieldName));
                                    continue;
                                }
                            }
                        }
                        values.add(value.getString(fieldName));
                    }
                }
                tuple = tupleFactory.newTuple(values);
            }
        } catch (InvalidDissectorException | MissingDissectorsException e) {
            throw new IOException("Fatal error in the parser", e);
        }
        return tuple;
    }
1334864
public int[] getRow(int rowIndex) {
        if (isCompacted) {
            throw new IllegalStateException(
                    "Illegal Invocation of the method after compact()");
        }
        if (rowIndex < 0 || rowIndex > rows) {
            throw new IllegalArgumentException("rowIndex out of bound!");
        }
        int[] rowToReturn = new int[columns - 2];
        System.arraycopy(v, rowIndex * columns + 2, rowToReturn, 0,
                         columns - 2);
        return rowToReturn;
    }
37736
@Override
	public Row nextRecord(Row row) throws IOException {
		try {
			if (!hasNext) {
				return null;
			}
			for (int pos = 0; pos < row.getArity(); pos++) {
				row.setField(pos, resultSet.getObject(pos + 1));
			}
			//update hasNext after we've read the record
			hasNext = resultSet.next();
			return row;
		} catch (SQLException se) {
			throw new IOException("Couldn't read data - " + se.getMessage(), se);
		} catch (NullPointerException npe) {
			throw new IOException("Couldn't access resultSet", npe);
		}
	}
941466
public static Throwable getNextThrowable(Throwable t) {

        Throwable nextThrowable = null;
        if (t != null) {

            // try getCause first.
            nextThrowable = t.getCause();

            if (nextThrowable == null) {
                // if getCause returns null, look for the JDBC and JCA specific chained exceptions
                // in case the resource adapter or database has not implemented getCause and initCause yet.
                if (t instanceof SQLException) {
                    nextThrowable = ((SQLException) t).getNextException();
                }

                else if (t instanceof ResourceException) {
                    nextThrowable = ((ResourceException) t).getCause(); 
                }
            }
        }
        return nextThrowable;
    }
26521
public Set<HBeanRow> getLazy(Set<HBeanRow> rows, FetchType... fetchType)
            throws HBeanNotFoundException {
        final List<Row> gets = new ArrayList<>(rows.size());
        for (HBeanRow row : rows) {
            final Get get = new Get(row.getRowKey());
            HBeanRow.setColumnFilter(get, fetchType);
            gets.add(get);
        }
        Set<HBeanRow> result = new HashSet<>();
        Set<BeanId> notFound = new HashSet<>();
        try {
            final Result[] r = new Result[gets.size()];
            table.batch(gets, r);
            table.flushCommits();
            for (int i = 0; i < r.length; i++) {
                KeyValue[] kvs = r[i].raw();
                if (kvs.length == 0) {
                    notFound.add(new HBeanRow(gets.get(i).getRow(), uids).getBeanId());
                } else {
                    HBeanRow row = new HBeanRow(kvs, uids);
                    result.add(row);
                }
            }
        } catch (IOException | InterruptedException e) {
            throw new RuntimeException(e);
        }
        if (notFound.size() > 0) {
            throw new HBeanNotFoundException(notFound, result);
        }
        return result;
    }
478155
protected long buildNextSequence(PersistenceBroker broker, ClassDescriptor cld, String sequenceName)
            throws LookupException, SQLException, PlatformException
    {
        CallableStatement cs = null;
        try
        {
            Connection con = broker.serviceConnectionManager().getConnection();
            cs = getPlatform().prepareNextValProcedureStatement(con, PROCEDURE_NAME, sequenceName);
            cs.executeUpdate();
            return cs.getLong(1);
        }
        finally
        {
            try
            {
                if (cs != null)
                    cs.close();
            }
            catch (SQLException ignore)
            {
                // ignore it
            }
        }
    }
808805
@Override
    public Row nextRow() {
        if (nextRow == null) {
            // Didn't call 'hasNext()' ...
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
        }
        assert nextRow != null;
        Row result = nextRow;
        nextRow = null;
        position++;
        return result;
    }
1193131
@Override
	public Record nextRecord(Record record) {
		try {
			resultSet.next();
			ResultSetMetaData rsmd = resultSet.getMetaData();
			int column_count = rsmd.getColumnCount();
			record.setNumFields(column_count);

			for (int pos = 0; pos < column_count; pos++) {
				int type = rsmd.getColumnType(pos + 1);
				retrieveTypeAndFillRecord(pos, type, record);
			}
			return record;
		} catch (SQLException e) {
			throw new IllegalArgumentException("Couldn't read data:\t" + e.getMessage());
		} catch (NotTransformableSQLFieldException e) {
			throw new IllegalArgumentException("Couldn't read data because of unknown column sql-type:\t"
				+ e.getMessage());
		} catch (NullPointerException e) {
			throw new IllegalArgumentException("Couldn't access resultSet:\t" + e.getMessage());
		}
	}
160547
def next_row(self):
        """"""
        row = self.currentIndex().row()
        rows = self.source_model.rowCount()
        if row + 1 == rows:
            row = -1
        self.selectRow(row + 1)
1256866
@Override
  public UnsafeRow getKeyRow(int rowId) {
    assert(rowId >= 0);
    assert(rowId < numRows);
    if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached
      long offset = keyOffsets[rowId];
      int klen = Platform.getInt(base, offset - 4);
      keyRow.pointTo(base, offset, klen);
      // set keyRowId so we can check if desired row is cached
      keyRowId = rowId;
    }
    return keyRow;
  }
475685
@Override
	public final FieldCase getNext(FieldCase ca) {
		if (ca == null) {
			List<FieldCase> stack = getCaseStack();
			ca = stack.remove(0);
			allHit = allHit | stack.isEmpty();
		} else {
			ca = createCase(ca);
		}
		return ca;
	}
1306831
protected Set<?> getPrevRenderedRows() {
		Set<?> keys = getComponentModel().prevRenderedRows;
		if (keys == null) {
			return Collections.emptySet();
		} else {
			return Collections.unmodifiableSet(keys);
		}
	}