use of org.apache.fluo.api.data.Bytes.BytesBuilder in project incubator-rya by apache.
the class BindingHashShardingFunction method removeHash.
/**
* @return Returns input with prefix and hash stripped from beginning.
*/
public static Bytes removeHash(Bytes prefixBytes, Bytes row) {
checkNotNull(prefixBytes);
checkNotNull(row);
checkArgument(row.length() >= prefixBytes.length() + 6, "Row is shorter than expected " + row);
checkArgument(row.subSequence(0, prefixBytes.length()).equals(prefixBytes), "Row does not have expected prefix " + row);
checkArgument(hasHash(prefixBytes, row), "Row does not have expected hash " + row);
BytesBuilder builder = Bytes.builder();
builder.append(prefixBytes);
builder.append("_");
builder.append(row.subSequence(prefixBytes.length() + 6, row.length()));
return builder.toBytes();
}
use of org.apache.fluo.api.data.Bytes.BytesBuilder in project incubator-rya by apache.
the class TriplePrefixUtils method addTriplePrefixAndConvertToBytes.
/**
* Prepends the triple prefix to the provided bytes and returns the new value as a {@link Bytes}.
* @param tripleBytes - serialized {@link RyaStatement}
* @return - serialized RyaStatement with prepended triple prefix, converted to Bytes
*/
public static Bytes addTriplePrefixAndConvertToBytes(byte[] tripleBytes) {
checkNotNull(tripleBytes);
BytesBuilder builder = Bytes.builder();
return builder.append(TRIPLE_PREFIX_BYTES).append(tripleBytes).toBytes();
}
use of org.apache.fluo.api.data.Bytes.BytesBuilder in project incubator-rya by apache.
the class BindingHashShardingFunction method getShardedScanPrefix.
/**
* Generates a sharded rowId from the indicated nodeId and bindingString. For example, the row key generated from
* nodeId = SP_123, varOrder = a;b, bs = [a = uri:Bob, b = uri:Doug] would be
* SP:HASH(uri:Bob):123//uri:Bob;uri:Doug, where HASH(uri:Bob) indicates the shard id hash generated from the
* Binding value "uri:Bob".
*
* @param nodeId - NodeId with tyep and UUID
* @param bindingString - String representation of BindingSet values, as formed by {@link BindingSetStringConverter}
* @return - serialized, sharded Bytes prefix
*/
public static Bytes getShardedScanPrefix(String nodeId, String bindingString) {
checkNotNull(nodeId);
checkNotNull(bindingString);
String[] rowPrefixAndId = nodeId.split("_");
Preconditions.checkArgument(rowPrefixAndId.length == 2);
String prefix = rowPrefixAndId[0];
String id = rowPrefixAndId[1];
BytesBuilder builder = Bytes.builder();
builder.append(prefix + ":");
builder.append(genHash(Bytes.of(id + NODEID_BS_DELIM + bindingString)));
builder.append(":");
builder.append(id);
builder.append(NODEID_BS_DELIM);
builder.append(bindingString);
return builder.toBytes();
}
use of org.apache.fluo.api.data.Bytes.BytesBuilder in project incubator-rya by apache.
the class BindingHashShardingFunction method addShard.
/**
* Generates a sharded rowId. The rowId is of the form: node_prefix:shardId:nodeId//Binding_values. For
* example, the row key generated from nodeId = SP_123, varOrder = a;b, bs = [a = uri:Bob, b = uri:Doug] would be
* SP:HASH(uri:Bob):123//uri:Bob;uri:Doug, where HASH(uri:Bob) indicates the shard id hash generated from the
* Binding value "uri:Bob".
*
* @param nodeId - Node Id with type and UUID
* @param varOrder - VarOrder used to order BindingSet values
* @param bs - BindingSet with partially formed query values
* @return - serialized Bytes rowId for storing BindingSet results in Fluo
*/
public static Bytes addShard(String nodeId, VariableOrder varOrder, VisibilityBindingSet bs) {
checkNotNull(nodeId);
checkNotNull(varOrder);
checkNotNull(bs);
String[] rowPrefixAndId = nodeId.split("_");
Preconditions.checkArgument(rowPrefixAndId.length == 2);
String prefix = rowPrefixAndId[0];
String id = rowPrefixAndId[1];
String firstBindingString = "";
Bytes rowSuffix = Bytes.of(id);
if (varOrder.getVariableOrders().size() > 0) {
VariableOrder first = new VariableOrder(varOrder.getVariableOrders().get(0));
firstBindingString = BS_CONVERTER.convert(bs, first);
rowSuffix = RowKeyUtil.makeRowKey(id, varOrder, bs);
}
BytesBuilder builder = Bytes.builder();
builder.append(Bytes.of(prefix + ":"));
builder.append(genHash(Bytes.of(id + NODEID_BS_DELIM + firstBindingString)));
builder.append(":");
builder.append(rowSuffix);
return builder.toBytes();
}
Aggregations