@Override
  public Map<String, Object> next() {
    try {
      Map<String, Object> record = new HashMap<String, Object>(hiveColumnNames.length);
      for (int i = 0; i < hiveColumnNames.length; i++) {
        String key = hiveColumnNames[i];
        Object value = null;
        if (!(hiveColumnTypesList.get(i) instanceof PrimitiveTypeInfo)) {
          throw new RuntimeException("date type of column " + hiveColumnNames[i] + ":" +
                  hiveColumnTypesList.get(i).getTypeName() + " is not supported");
        }
        try {
          switch (((PrimitiveTypeInfo) hiveColumnTypesList.get(i)).getPrimitiveCategory()) {
            case INT:
            case SHORT:
            case BYTE:
              value = rs.getInt(i + 1);
              break;
            case LONG:
              value = rs.getLong(i + 1);
              break;
            case FLOAT:
              value = rs.getFloat(i + 1);
              break;
            case DOUBLE:
              value = rs.getDouble(i + 1);
              break;
            case DECIMAL:
              value = rs.getBigDecimal(i + 1);
              break;
            case BOOLEAN:
              boolean b = rs.getBoolean(i + 1);
              if (b && rs.getMetaData().getColumnType(i + 1) == Types.CHAR) {
                // also accept Y/N in case of CHAR(1) - datanucleus stores booleans in CHAR(1) fields for derby 
                b = !"N".equals(rs.getString(i + 1));
              }
              value = b;
              break;
            case CHAR:
            case VARCHAR:
            case STRING:
              value = rs.getString(i + 1);
              break;
            case DATE:
              value = rs.getDate(i + 1);
              break;
            case TIMESTAMP:
              value = rs.getTimestamp(i + 1);
              break;
            default:
              LOGGER.error("date type of column " + hiveColumnNames[i] + ":" +
                      ((PrimitiveTypeInfo) hiveColumnTypesList.get(i)).getPrimitiveCategory() +
                      " is not supported");
              value = null;
              break;
          }
          if (value != null && !rs.wasNull()) {
            record.put(key, value);
          } else {
            record.put(key, null);
          }
        } catch (SQLDataException e) {
          record.put(key, null);
        }

      }

      return record;
    }
    catch (Exception e) {
      LOGGER.warn("next() threw exception", e);
      if (e instanceof SQLException){
        throw new RuntimeException(e);
      }
      return null;
    }
  }
An iterator that allows iterating through a SQL resultset. Includes methods to clear up resources.
jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/dao/JdbcRecordIterator.java