@Test public void testToKeyValuesDelete() throws Exception { IRI res = SimpleValueFactory.getInstance().createIRI("http: KeyValue kvs[] = HalyardTableUtils.toKeyValues(res, res, res, res, true, 0); assertEquals(6, kvs.length); for (KeyValue kv : kvs) { assertEquals(KeyValue.Type.DeleteColumn, KeyValue.Type.codeToType(kv.getTypeByte())); } }
public static KeyValue[] toKeyValues(Resource subj, IRI pred, Value obj, Resource context, boolean delete, long timestamp) { byte[] sb = writeBytes(subj); byte[] pb = writeBytes(pred); byte[] ob = writeBytes(obj); byte[] cb = context == null ? new byte[0] : writeBytes(context); byte[] sKey = hashKey(sb); byte[] pKey = hashKey(pb); byte[] oKey = hashKey(ob); byte[] cq = ByteBuffer.allocate(sb.length + pb.length + ob.length + cb.length + 12).putInt(sb.length).putInt(pb.length).putInt(ob.length).put(sb).put(pb).put(ob).put(cb).array(); KeyValue kv[] = new KeyValue[context == null ? PREFIXES : 2 * PREFIXES]; KeyValue.Type type = delete ? KeyValue.Type.DeleteColumn : KeyValue.Type.Put; timestamp = timestamp << 1; if (!delete) { timestamp |= 1; } kv[0] = new KeyValue(concat(SPO_PREFIX, false, sKey, pKey, oKey), CF_NAME, cq, timestamp, type, EMPTY); kv[1] = new KeyValue(concat(POS_PREFIX, false, pKey, oKey, sKey), CF_NAME, cq, timestamp, type, EMPTY); kv[2] = new KeyValue(concat(OSP_PREFIX, false, oKey, sKey, pKey), CF_NAME, cq, timestamp, type, EMPTY); if (context != null) { byte[] cKey = hashKey(cb); kv[3] = new KeyValue(concat(CSPO_PREFIX, false, cKey, sKey, pKey, oKey), CF_NAME, cq, timestamp, type, EMPTY); kv[4] = new KeyValue(concat(CPOS_PREFIX, false, cKey, pKey, oKey, sKey), CF_NAME, cq, timestamp, type, EMPTY); kv[5] = new KeyValue(concat(COSP_PREFIX, false, cKey, oKey, sKey, pKey), CF_NAME, cq, timestamp, type, EMPTY); } return kv; }
HalyardTableUtils { public static KeyValue[] toKeyValues(Resource subj, IRI pred, Value obj, Resource context, boolean delete, long timestamp) { byte[] sb = writeBytes(subj); byte[] pb = writeBytes(pred); byte[] ob = writeBytes(obj); byte[] cb = context == null ? new byte[0] : writeBytes(context); byte[] sKey = hashKey(sb); byte[] pKey = hashKey(pb); byte[] oKey = hashKey(ob); byte[] cq = ByteBuffer.allocate(sb.length + pb.length + ob.length + cb.length + 12).putInt(sb.length).putInt(pb.length).putInt(ob.length).put(sb).put(pb).put(ob).put(cb).array(); KeyValue kv[] = new KeyValue[context == null ? PREFIXES : 2 * PREFIXES]; KeyValue.Type type = delete ? KeyValue.Type.DeleteColumn : KeyValue.Type.Put; timestamp = timestamp << 1; if (!delete) { timestamp |= 1; } kv[0] = new KeyValue(concat(SPO_PREFIX, false, sKey, pKey, oKey), CF_NAME, cq, timestamp, type, EMPTY); kv[1] = new KeyValue(concat(POS_PREFIX, false, pKey, oKey, sKey), CF_NAME, cq, timestamp, type, EMPTY); kv[2] = new KeyValue(concat(OSP_PREFIX, false, oKey, sKey, pKey), CF_NAME, cq, timestamp, type, EMPTY); if (context != null) { byte[] cKey = hashKey(cb); kv[3] = new KeyValue(concat(CSPO_PREFIX, false, cKey, sKey, pKey, oKey), CF_NAME, cq, timestamp, type, EMPTY); kv[4] = new KeyValue(concat(CPOS_PREFIX, false, cKey, pKey, oKey, sKey), CF_NAME, cq, timestamp, type, EMPTY); kv[5] = new KeyValue(concat(COSP_PREFIX, false, cKey, oKey, sKey, pKey), CF_NAME, cq, timestamp, type, EMPTY); } return kv; } }
HalyardTableUtils { public static KeyValue[] toKeyValues(Resource subj, IRI pred, Value obj, Resource context, boolean delete, long timestamp) { byte[] sb = writeBytes(subj); byte[] pb = writeBytes(pred); byte[] ob = writeBytes(obj); byte[] cb = context == null ? new byte[0] : writeBytes(context); byte[] sKey = hashKey(sb); byte[] pKey = hashKey(pb); byte[] oKey = hashKey(ob); byte[] cq = ByteBuffer.allocate(sb.length + pb.length + ob.length + cb.length + 12).putInt(sb.length).putInt(pb.length).putInt(ob.length).put(sb).put(pb).put(ob).put(cb).array(); KeyValue kv[] = new KeyValue[context == null ? PREFIXES : 2 * PREFIXES]; KeyValue.Type type = delete ? KeyValue.Type.DeleteColumn : KeyValue.Type.Put; timestamp = timestamp << 1; if (!delete) { timestamp |= 1; } kv[0] = new KeyValue(concat(SPO_PREFIX, false, sKey, pKey, oKey), CF_NAME, cq, timestamp, type, EMPTY); kv[1] = new KeyValue(concat(POS_PREFIX, false, pKey, oKey, sKey), CF_NAME, cq, timestamp, type, EMPTY); kv[2] = new KeyValue(concat(OSP_PREFIX, false, oKey, sKey, pKey), CF_NAME, cq, timestamp, type, EMPTY); if (context != null) { byte[] cKey = hashKey(cb); kv[3] = new KeyValue(concat(CSPO_PREFIX, false, cKey, sKey, pKey, oKey), CF_NAME, cq, timestamp, type, EMPTY); kv[4] = new KeyValue(concat(CPOS_PREFIX, false, cKey, pKey, oKey, sKey), CF_NAME, cq, timestamp, type, EMPTY); kv[5] = new KeyValue(concat(COSP_PREFIX, false, cKey, oKey, sKey, pKey), CF_NAME, cq, timestamp, type, EMPTY); } return kv; }  }
HalyardTableUtils { public static KeyValue[] toKeyValues(Resource subj, IRI pred, Value obj, Resource context, boolean delete, long timestamp) { byte[] sb = writeBytes(subj); byte[] pb = writeBytes(pred); byte[] ob = writeBytes(obj); byte[] cb = context == null ? new byte[0] : writeBytes(context); byte[] sKey = hashKey(sb); byte[] pKey = hashKey(pb); byte[] oKey = hashKey(ob); byte[] cq = ByteBuffer.allocate(sb.length + pb.length + ob.length + cb.length + 12).putInt(sb.length).putInt(pb.length).putInt(ob.length).put(sb).put(pb).put(ob).put(cb).array(); KeyValue kv[] = new KeyValue[context == null ? PREFIXES : 2 * PREFIXES]; KeyValue.Type type = delete ? KeyValue.Type.DeleteColumn : KeyValue.Type.Put; timestamp = timestamp << 1; if (!delete) { timestamp |= 1; } kv[0] = new KeyValue(concat(SPO_PREFIX, false, sKey, pKey, oKey), CF_NAME, cq, timestamp, type, EMPTY); kv[1] = new KeyValue(concat(POS_PREFIX, false, pKey, oKey, sKey), CF_NAME, cq, timestamp, type, EMPTY); kv[2] = new KeyValue(concat(OSP_PREFIX, false, oKey, sKey, pKey), CF_NAME, cq, timestamp, type, EMPTY); if (context != null) { byte[] cKey = hashKey(cb); kv[3] = new KeyValue(concat(CSPO_PREFIX, false, cKey, sKey, pKey, oKey), CF_NAME, cq, timestamp, type, EMPTY); kv[4] = new KeyValue(concat(CPOS_PREFIX, false, cKey, pKey, oKey, sKey), CF_NAME, cq, timestamp, type, EMPTY); kv[5] = new KeyValue(concat(COSP_PREFIX, false, cKey, oKey, sKey, pKey), CF_NAME, cq, timestamp, type, EMPTY); } return kv; }  static HTable getTable(Configuration config, String tableName, boolean create, int splitBits); static HTable getTable(Configuration config, String tableName, boolean create, byte[][] splits); static HTable truncateTable(HTable table); static KeyValue[] toKeyValues(Resource subj, IRI pred, Value obj, Resource context, boolean delete, long timestamp); static Scan scan(Resource subj, IRI pred, Value obj, Resource ctx); static Scan scan(byte[] subjHash, byte[] predHash, byte[] objHash, byte[] ctxHash); static List<Statement> parseStatements(Result res, ValueFactory vf); static Statement parseStatement(Cell c, ValueFactory vf); static Scan scan(byte[] startRow, byte[] stopRow); static byte[] concat(byte prefix, boolean trailingZero, byte[]...fragments); static byte[] hashKey(byte[] key); static byte[] hashKey(Value v); static String encode(byte b[]); static byte[] writeBytes(Value v); static Value readValue(byte[] b, ValueFactory vf); static Resource readResource(byte[] b, ValueFactory vf); static IRI readIRI(byte[] b, ValueFactory vf); }
HalyardTableUtils { public static KeyValue[] toKeyValues(Resource subj, IRI pred, Value obj, Resource context, boolean delete, long timestamp) { byte[] sb = writeBytes(subj); byte[] pb = writeBytes(pred); byte[] ob = writeBytes(obj); byte[] cb = context == null ? new byte[0] : writeBytes(context); byte[] sKey = hashKey(sb); byte[] pKey = hashKey(pb); byte[] oKey = hashKey(ob); byte[] cq = ByteBuffer.allocate(sb.length + pb.length + ob.length + cb.length + 12).putInt(sb.length).putInt(pb.length).putInt(ob.length).put(sb).put(pb).put(ob).put(cb).array(); KeyValue kv[] = new KeyValue[context == null ? PREFIXES : 2 * PREFIXES]; KeyValue.Type type = delete ? KeyValue.Type.DeleteColumn : KeyValue.Type.Put; timestamp = timestamp << 1; if (!delete) { timestamp |= 1; } kv[0] = new KeyValue(concat(SPO_PREFIX, false, sKey, pKey, oKey), CF_NAME, cq, timestamp, type, EMPTY); kv[1] = new KeyValue(concat(POS_PREFIX, false, pKey, oKey, sKey), CF_NAME, cq, timestamp, type, EMPTY); kv[2] = new KeyValue(concat(OSP_PREFIX, false, oKey, sKey, pKey), CF_NAME, cq, timestamp, type, EMPTY); if (context != null) { byte[] cKey = hashKey(cb); kv[3] = new KeyValue(concat(CSPO_PREFIX, false, cKey, sKey, pKey, oKey), CF_NAME, cq, timestamp, type, EMPTY); kv[4] = new KeyValue(concat(CPOS_PREFIX, false, cKey, pKey, oKey, sKey), CF_NAME, cq, timestamp, type, EMPTY); kv[5] = new KeyValue(concat(COSP_PREFIX, false, cKey, oKey, sKey, pKey), CF_NAME, cq, timestamp, type, EMPTY); } return kv; }  static HTable getTable(Configuration config, String tableName, boolean create, int splitBits); static HTable getTable(Configuration config, String tableName, boolean create, byte[][] splits); static HTable truncateTable(HTable table); static KeyValue[] toKeyValues(Resource subj, IRI pred, Value obj, Resource context, boolean delete, long timestamp); static Scan scan(Resource subj, IRI pred, Value obj, Resource ctx); static Scan scan(byte[] subjHash, byte[] predHash, byte[] objHash, byte[] ctxHash); static List<Statement> parseStatements(Result res, ValueFactory vf); static Statement parseStatement(Cell c, ValueFactory vf); static Scan scan(byte[] startRow, byte[] stopRow); static byte[] concat(byte prefix, boolean trailingZero, byte[]...fragments); static byte[] hashKey(byte[] key); static byte[] hashKey(Value v); static String encode(byte b[]); static byte[] writeBytes(Value v); static Value readValue(byte[] b, ValueFactory vf); static Resource readResource(byte[] b, ValueFactory vf); static IRI readIRI(byte[] b, ValueFactory vf); static final byte SPO_PREFIX; static final byte POS_PREFIX; static final byte OSP_PREFIX; static final byte CSPO_PREFIX; static final byte CPOS_PREFIX; static final byte COSP_PREFIX; static final byte KEY_SIZE; static final byte[] STOP_KEY; }