@Override
    public boolean next() {
      if (rows == null || !iterator.hasNext()) {
        this.rows = fetch();
        this.iterator = rows.iterator();
      }
      if (iterator.hasNext()) {
        current = iterator.next();
        return true;
      } else {
        current = null;
        return false;
      }
    }
Executing HiveQL from HPL/SQL directly, without JDBC or Thrift.
service/src/java/org/apache/hive/service/cli/operation/hplsql/HplSqlQueryExecutor.java