class Put extends VoltProcedure {
  private final SQLStmt selectStmt = new SQLStmt("SELECT value FROM Store WHERE keyspace = ? AND key = ?");
  private final SQLStmt insertStmt = new SQLStmt("INSERT INTO Store VALUES (?, ?, ?)");
  private final SQLStmt updateStmt = new SQLStmt("UPDATE Store SET value = ? WHERE keyspace = ? AND key = ?");

  public long run(byte[] keyspace, String key, byte[] data) {
    voltQueueSQL(selectStmt, keyspace, key);
    VoltTable res = voltExecuteSQL()[0];
    if (res.advanceRow()) {
      voltQueueSQL(updateStmt, merge(res.getVarbinary(0), data), keyspace, key);
    } else {
      voltQueueSQL(insertStmt, keyspace, key, data);
    }
    voltExecuteSQL(true);
    return 0L;
  }

  private byte[] merge(byte[] dest, byte[] src) {<FILL_FUNCTION_BODY>}
}

    HashSet<ByteWrapper> mergeSet = new HashSet<ByteWrapper>();
    ByteBuffer buf = ByteBuffer.wrap(src);
    int nSrc = buf.getInt();
    for (int i = 0; i < nSrc; i++) {
      int len = buf.getInt();
      int off = buf.position();
      mergeSet.add(new ByteWrapper(src, off, len));
      buf.position(off + len);
      len = buf.getInt();
      buf.position(buf.position() + len);
    }

    byte[] merged = new byte[src.length + dest.length];
    ByteBuffer out = ByteBuffer.wrap(merged);

    buf = ByteBuffer.wrap(dest);
    int nDest = buf.getInt();
    int nFields = nSrc + nDest;
    out.putInt(nFields);

    int blockStart = 4;
    int blockEnd = 4;
    for (int i = 0; i < nDest; i++) {
      int len = buf.getInt();
      int off = buf.position();
      boolean flushBlock = mergeSet.contains(new ByteWrapper(dest, off, len));
      buf.position(off + len);
      len = buf.getInt();
      buf.position(buf.position() + len);
      if (flushBlock) {
        if (blockStart < blockEnd) {
          out.put(dest, blockStart, blockEnd - blockStart);
        }
        nFields--;
        blockStart = buf.position();
      }
      blockEnd = buf.position();
    }
    if (blockStart < blockEnd) {
      out.put(dest, blockStart, blockEnd - blockStart);
    }
    out.put(src, 4, src.length - 4);

    int length = out.position();
    if (nFields != nSrc + nDest) {
      out.position(0);
      out.putInt(nFields);
    }

    byte[] res = new byte[length];
    System.arraycopy(merged, 0, res, 0, length);
    return res;
  
<no_super_class>