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();
        }
      }
    }
  }
 @Override
 public Function getMetadataEntityFromTuple(ITupleReference frameTuple) throws IOException {
   byte[] serRecord = frameTuple.getFieldData(FUNCTION_PAYLOAD_TUPLE_FIELD_INDEX);
   int recordStartOffset = frameTuple.getFieldStart(FUNCTION_PAYLOAD_TUPLE_FIELD_INDEX);
   int recordLength = frameTuple.getFieldLength(FUNCTION_PAYLOAD_TUPLE_FIELD_INDEX);
   ByteArrayInputStream stream =
       new ByteArrayInputStream(serRecord, recordStartOffset, recordLength);
   DataInput in = new DataInputStream(stream);
   ARecord functionRecord = (ARecord) recordSerDes.deserialize(in);
   return createFunctionFromARecord(functionRecord);
 }
  /** write the right result */
  private void writeRightResults(ITupleReference frameTuple) throws Exception {
    tb.reset();
    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 static void compareActualAndExpected(
     ITupleReference actual, CheckTuple expected, ISerializerDeserializer[] fieldSerdes)
     throws HyracksDataException {
   for (int i = 0; i < fieldSerdes.length; i++) {
     ByteArrayInputStream inStream =
         new ByteArrayInputStream(
             actual.getFieldData(i), actual.getFieldStart(i), actual.getFieldLength(i));
     DataInput dataIn = new DataInputStream(inStream);
     Object actualObj = fieldSerdes[i].deserialize(dataIn);
     if (!actualObj.equals(expected.getField(i))) {
       fail(
           "Actual and expected fields do not match on field "
               + i
               + ".\nExpected: "
               + expected.getField(i)
               + "\nActual  : "
               + actualObj);
     }
   }
 }