use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.
the class HashedPoWholeRowTriplePatternStrategyTest method testPoRange.
public void testPoRange() throws Exception {
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, uri, null));
TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(null, uri, rangeURI, null, null);
assertContains(entry.getValue(), tripleRow.getRow());
entry = strategy.defineRange(null, uri, rangeURI2, null, null);
assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.
the class HashedPoWholeRowTriplePatternStrategyTest method testPosRange.
public void testPosRange() throws Exception {
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, uri, null));
TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(rangeURI, uri, uri, null, null);
assertContains(entry.getValue(), tripleRow.getRow());
entry = strategy.defineRange(rangeURI2, uri, uri, null, null);
assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.
the class HashedPoWholeRowTriplePatternStrategyTest method testPoRangeCustomType.
public void testPoRangeCustomType() throws Exception {
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, customType1, null));
TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(null, uri, customTypeRange1, null, null);
assertContains(entry.getValue(), tripleRow.getRow());
entry = strategy.defineRange(null, uri, customTypeRange2, null, null);
assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.
the class HashedPoWholeRowTriplePatternStrategy method defineRange.
@Override
public Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> defineRange(final RyaURI subject, final RyaURI predicate, final RyaType object, final RyaURI context, final RdfCloudTripleStoreConfiguration conf) throws IOException {
try {
// r(p)(ng)
if (!handles(subject, predicate, object, context)) {
return null;
}
final RyaContext ryaContext = RyaContext.getInstance();
final MessageDigest md = MessageDigest.getInstance("MD5");
final RdfCloudTripleStoreConstants.TABLE_LAYOUT table_layout = RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO;
byte[] start, stop;
if (object != null) {
if (object instanceof RyaRange) {
// p_r(o)
RyaRange rv = (RyaRange) object;
rv = ryaContext.transformRange(rv);
final byte[] objStartBytes = ryaContext.serializeType(rv.getStart())[0];
final byte[] objEndBytes = ryaContext.serializeType(rv.getStop())[0];
final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
final byte[] predHash = Hex.encodeHexString(md.digest(predBytes)).getBytes(StandardCharsets.UTF_8);
start = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES, objStartBytes);
stop = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES, objEndBytes, DELIM_BYTES, LAST_BYTES);
} else {
if (subject != null && subject instanceof RyaRange) {
// po_r(s)
RyaRange ru = (RyaRange) subject;
ru = ryaContext.transformRange(ru);
final byte[] subjStartBytes = ru.getStart().getData().getBytes(StandardCharsets.UTF_8);
final byte[] subjStopBytes = ru.getStop().getData().getBytes(StandardCharsets.UTF_8);
final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
final byte[] predHash = Hex.encodeHexString(md.digest(predBytes)).getBytes(StandardCharsets.UTF_8);
final byte[] objBytes = ryaContext.serializeType(object)[0];
start = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes, DELIM_BYTES, subjStartBytes);
stop = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes, DELIM_BYTES, subjStopBytes, TYPE_DELIM_BYTES, LAST_BYTES);
} else {
// po
// TODO: There must be a better way than creating multiple byte[]
final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
final byte[] predHash = Hex.encodeHexString(md.digest(predBytes)).getBytes(StandardCharsets.UTF_8);
final byte[] objBytes = ryaContext.serializeType(object)[0];
start = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes, DELIM_BYTES);
stop = Bytes.concat(start, LAST_BYTES);
}
}
} else {
// p
final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
final byte[] predHash = Hex.encodeHexString(md.digest(predBytes)).getBytes(StandardCharsets.UTF_8);
start = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES);
stop = Bytes.concat(start, LAST_BYTES);
}
return new RdfCloudTripleStoreUtils.CustomEntry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange>(table_layout, new ByteRange(start, stop));
} catch (final RyaTypeResolverException e) {
throw new IOException(e);
} catch (final NoSuchAlgorithmException e) {
throw new IOException(e);
}
}
use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.
the class NullRowTriplePatternStrategy method defineRange.
@Override
public Map.Entry<TABLE_LAYOUT, ByteRange> defineRange(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context, RdfCloudTripleStoreConfiguration conf) throws IOException {
// Scan from the beginning of the Accumulo Table
byte[] start = new byte[] {/* empty array */
};
// Scan to the end, up through things beginning with 0xff.
byte[] stop = LAST_BYTES;
return new RdfCloudTripleStoreUtils.CustomEntry<>(TABLE_LAYOUT.SPO, new ByteRange(start, stop));
}
Aggregations