@Override
 public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
   innerAccessor.reset(buffer);
   for (int i = 0; i < innerAccessor.getTupleCount(); ++i) {
     validate(innerAccessor, i);
   }
 }
  private void writeSearchResults(IFrameTupleAccessor leftAccessor, int tIndex) throws Exception {
    while (cursor.hasNext()) {
      tb.reset();
      cursor.next();

      ITupleReference frameTuple = cursor.getTuple();
      for (int i = 0; i < inputRecDesc.getFields().length; i++) {
        int tupleStart = leftAccessor.getTupleStartOffset(tIndex);
        int fieldStart = leftAccessor.getFieldStartOffset(tIndex, i);
        int offset = leftAccessor.getFieldSlotsLength() + tupleStart + fieldStart;
        int len = leftAccessor.getFieldEndOffset(tIndex, i) - fieldStart;
        dos.write(leftAccessor.getBuffer().array(), offset, len);
        tb.addFieldEndOffset();
      }
      for (int i = 0; i < frameTuple.getFieldCount(); i++) {
        dos.write(
            frameTuple.getFieldData(i), frameTuple.getFieldStart(i), frameTuple.getFieldLength(i));
        tb.addFieldEndOffset();
      }

      if (!appender.append(tb.getFieldEndOffsets(), tb.getByteArray(), 0, tb.getSize())) {
        FrameUtils.flushFrame(writeBuffer, writer);
        appender.reset(writeBuffer, true);
        if (!appender.append(tb.getFieldEndOffsets(), tb.getByteArray(), 0, tb.getSize())) {
          throw new IllegalStateException();
        }
      }
    }
  }
 private void validate(IFrameTupleAccessor innerAccessor, int i) {
   assertTrue(tid < accessor.getTupleCount());
   assertEquals(accessor.getTupleLength(tid), innerAccessor.getTupleLength(i));
   assertArrayEquals(
       Arrays.copyOfRange(
           accessor.getBuffer().array(),
           accessor.getTupleStartOffset(tid),
           accessor.getTupleEndOffset(tid)),
       Arrays.copyOfRange(
           innerAccessor.getBuffer().array(),
           innerAccessor.getTupleStartOffset(i),
           innerAccessor.getTupleEndOffset(i)));
   tid++;
 }
  /** write the left result */
  private void writeLeftResults(IFrameTupleAccessor leftAccessor, int tIndex) throws Exception {
    tb.reset();
    for (int i = 0; i < inputRecDesc.getFields().length; i++) {
      int tupleStart = leftAccessor.getTupleStartOffset(tIndex);
      int fieldStart = leftAccessor.getFieldStartOffset(tIndex, i);
      int offset = leftAccessor.getFieldSlotsLength() + tupleStart + fieldStart;
      int len = leftAccessor.getFieldEndOffset(tIndex, i) - fieldStart;
      dos.write(leftAccessor.getBuffer().array(), offset, len);
      tb.addFieldEndOffset();
    }

    if (!appender.append(tb.getFieldEndOffsets(), tb.getByteArray(), 0, tb.getSize())) {
      FrameUtils.flushFrame(writeBuffer, writer);
      appender.reset(writeBuffer, true);
      if (!appender.append(tb.getFieldEndOffsets(), tb.getByteArray(), 0, tb.getSize())) {
        throw new IllegalStateException();
      }
    }
  }
 private IFrameTupleAccessor prepareData(DATA_TYPE type) throws HyracksDataException {
   IFrameTupleAccessor accessor = new FrameTupleAccessor(recordDescriptor);
   IFrameTupleAppender appender =
       new FrameTupleAppender(new VSizeFrame(new FrameManager(INPUT_BUFFER_SIZE)), true);
   int i = 0;
   do {
     switch (type) {
       case NORMAL_RECORD:
         makeATuple(tupleBuilder, i++);
         break;
       case ONE_FIELD_LONG:
         makeASizeUpTuple(tupleBuilder, i++);
         break;
       case ONE_RECORD_LONG:
         makeABigObjectTuple(tupleBuilder, i++);
         break;
     }
   } while (appender.append(
       tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray(), 0, tupleBuilder.getSize()));
   accessor.reset(appender.getBuffer());
   return accessor;
 }
 private void testProcess(IFrameTupleAccessor accessor) throws HyracksDataException {
   IFrameWriter writer = prepareValidator(accessor);
   writer.open();
   for (int tid = 0; tid < accessor.getTupleCount(); tid++) {
     for (int fid = 0; fid < fields.length; fid++) {
       if (!appender.appendField(accessor, tid, fid)) {
         appender.flush(writer, true);
         if (!appender.appendField(accessor, tid, fid)) {}
       }
     }
   }
   appender.flush(writer, true);
   writer.close();
 }
 @Override
 public void close() throws HyracksDataException {
   assertEquals(accessor.getTupleCount(), tid);
 }