use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class HashedWholeRowTripleResolverTest method testSerializeOSPCustomType.
public void testSerializeOSPCustomType() throws Exception {
RdfCloudTripleStoreConstants.TABLE_LAYOUT po = RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP;
// no context
RyaURI subj = new RyaURI("urn:test#1234");
RyaURI pred = new RyaURI("urn:test#pred");
RyaURI obj = new RyaURI("urn:test#obj");
RyaURI cntxt = new RyaURI("urn:test#cntxt");
final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l);
final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l);
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = tripleResolver.serialize(stmt);
TripleRow tripleRow = serialize.get(po);
RyaStatement deserialize = tripleResolver.deserialize(po, tripleRow);
assertEquals(stmt, deserialize);
// context
serialize = tripleResolver.serialize(stmtContext);
tripleRow = serialize.get(po);
deserialize = tripleResolver.deserialize(po, tripleRow);
assertEquals(stmtContext, deserialize);
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class AbstractTriplePatternStrategyTest method testRegex.
public void testRegex() throws Exception {
RyaURI subj = new RyaURI("urn:test#1234");
RyaURI pred = new RyaURI("urn:test#pred");
RyaURI obj = new RyaURI("urn:test#obj");
RyaStatement ryaStatement = new RyaStatement(subj, pred, obj);
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = new WholeRowTripleResolver().serialize(ryaStatement);
TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
String row = new String(tripleRow.getRow());
TriplePatternStrategy spoStrategy = new SpoWholeRowTriplePatternStrategy();
TriplePatternStrategy poStrategy = new PoWholeRowTriplePatternStrategy();
TriplePatternStrategy ospStrategy = new OspWholeRowTriplePatternStrategy();
// pred
TripleRowRegex tripleRowRegex = spoStrategy.buildRegex(null, pred.getData(), null, null, null);
Pattern p = Pattern.compile(tripleRowRegex.getRow());
Matcher matcher = p.matcher(row);
assertTrue(matcher.matches());
// subj
tripleRowRegex = spoStrategy.buildRegex(subj.getData(), null, null, null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertTrue(matcher.matches());
// obj
tripleRowRegex = spoStrategy.buildRegex(null, null, obj.getData(), null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertTrue(matcher.matches());
// po table
row = new String(serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO).getRow());
tripleRowRegex = poStrategy.buildRegex(null, pred.getData(), null, null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertTrue(matcher.matches());
tripleRowRegex = poStrategy.buildRegex(null, pred.getData(), obj.getData(), null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertTrue(matcher.matches());
tripleRowRegex = poStrategy.buildRegex(subj.getData(), pred.getData(), obj.getData(), null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertTrue(matcher.matches());
// various regex
tripleRowRegex = poStrategy.buildRegex(null, "urn:test#pr[e|d]{2}", null, null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertTrue(matcher.matches());
// does not match
tripleRowRegex = poStrategy.buildRegex(null, "hello", null, null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertFalse(matcher.matches());
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class HashedSpoWholeRowTriplePatternStrategyTest method testSpo.
public void testSpo() throws Exception {
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, uri, null));
TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, uri, uri, null, null);
assertContains(entry.getValue(), tripleRow.getRow());
entry = strategy.defineRange(uri, uri, uri2, null, null);
assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class HashedSpoWholeRowTriplePatternStrategyTest method testSpoRangeCustomType.
public void testSpoRangeCustomType() throws Exception {
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, customType1, null));
TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, uri, customTypeRange1, null, null);
assertContains(entry.getValue(), tripleRow.getRow());
entry = strategy.defineRange(uri, uri, customTypeRange2, null, null);
assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class WholeRowTripleResolver method serialize.
@Override
public Map<TABLE_LAYOUT, TripleRow> serialize(final RyaStatement stmt) throws TripleRowResolverException {
try {
final RyaURI subject = stmt.getSubject();
final RyaURI predicate = stmt.getPredicate();
final RyaType object = stmt.getObject();
final RyaURI context = stmt.getContext();
final Long timestamp = stmt.getTimestamp();
final byte[] columnVisibility = stmt.getColumnVisibility();
final String qualifer = stmt.getQualifer();
final byte[] qualBytes = qualifer == null ? EMPTY_BYTES : qualifer.getBytes(StandardCharsets.UTF_8);
final byte[] value = stmt.getValue();
assert subject != null && predicate != null && object != null;
final byte[] cf = (context == null) ? EMPTY_BYTES : context.getData().getBytes(StandardCharsets.UTF_8);
final Map<TABLE_LAYOUT, TripleRow> tripleRowMap = new HashMap<TABLE_LAYOUT, TripleRow>();
final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8);
final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
final byte[][] objBytes = RyaContext.getInstance().serializeType(object);
tripleRowMap.put(TABLE_LAYOUT.SPO, new TripleRow(Bytes.concat(subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes[0], objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
tripleRowMap.put(TABLE_LAYOUT.PO, new TripleRow(Bytes.concat(predBytes, DELIM_BYTES, objBytes[0], DELIM_BYTES, subjBytes, objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
tripleRowMap.put(TABLE_LAYOUT.OSP, new TripleRow(Bytes.concat(objBytes[0], DELIM_BYTES, subjBytes, DELIM_BYTES, predBytes, objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
return tripleRowMap;
} catch (final RyaTypeResolverException e) {
throw new TripleRowResolverException(e);
}
}
Aggregations