@Override
  public List<ByteString> getNextRows(int fetchRowNum) throws IOException {
    List<ByteString> rows = new ArrayList<ByteString>();
    int startRow = currentRow;
    int endRow = startRow + fetchRowNum;

    if (physicalExec == null) {
      return rows;
    }

    while (currentRow < endRow) {
      Tuple currentTuple = physicalExec.next();

      if (currentTuple == null) {
        physicalExec.close();
        physicalExec = null;
        break;
      }

      currentRow++;
      rows.add(ByteString.copyFrom(encoder.toBytes(currentTuple)));

      if (currentRow >= maxRow) {
        physicalExec.close();
        physicalExec = null;
        break;
      }
    }

    return rows;
  }
 @Override
 public void close() throws Exception {
   tableDesc = null;
   outSchema = null;
   encoder = null;
   if (physicalExec != null) {
     try {
       physicalExec.close();
     } catch (Exception ignored) {
     }
   }
   physicalExec = null;
   currentRow = -1;
 }