use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class HashedWholeRowTripleResolverTest method testSerialize.
public void testSerialize() throws Exception {
// 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(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
RyaStatement deserialize = tripleResolver.deserialize(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, tripleRow);
assertEquals(stmt, deserialize);
// context
serialize = tripleResolver.serialize(stmtContext);
tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
deserialize = tripleResolver.deserialize(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, tripleRow);
assertEquals(stmtContext, deserialize);
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class HashedWholeRowTripleResolverTest method testSerializePO.
public void testSerializePO() throws Exception {
RdfCloudTripleStoreConstants.TABLE_LAYOUT po = RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO;
// 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 testObjectTypeInfo.
public void testObjectTypeInfo() throws Exception {
RyaURI subj = new RyaURI("urn:test#1234");
RyaURI pred = new RyaURI("urn:test#pred");
RyaType obj = new RyaType(XMLSchema.LONG, "10");
RyaStatement ryaStatement = new RyaStatement(subj, pred, obj);
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = RyaTripleContext.getInstance(new MockRdfConfiguration()).serializeTriple(ryaStatement);
TripleRow tripleRow = serialize.get(SPO);
String row = new String(tripleRow.getRow());
TriplePatternStrategy spoStrategy = new SpoWholeRowTriplePatternStrategy();
// obj
byte[][] bytes = RyaContext.getInstance().serializeType(obj);
String objStr = new String(bytes[0]);
byte[] objectTypeInfo = bytes[1];
TripleRowRegex tripleRowRegex = spoStrategy.buildRegex(null, null, objStr, null, objectTypeInfo);
Pattern p = Pattern.compile(tripleRowRegex.getRow());
Matcher matcher = p.matcher(row);
assertTrue(matcher.matches());
// build row with same object str data
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> dupTriple_str = RyaTripleContext.getInstance(new MockRdfConfiguration()).serializeTriple(new RyaStatement(subj, pred, new RyaType(XMLSchema.STRING, objStr)));
TripleRow tripleRow_dup_str = dupTriple_str.get(SPO);
row = new String(tripleRow_dup_str.getRow());
spoStrategy = new SpoWholeRowTriplePatternStrategy();
tripleRowRegex = spoStrategy.buildRegex(null, null, objStr, null, objectTypeInfo);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertFalse(matcher.matches());
// po table
TriplePatternStrategy poStrategy = new PoWholeRowTriplePatternStrategy();
tripleRowRegex = poStrategy.buildRegex(null, null, objStr, null, objectTypeInfo);
p = Pattern.compile(tripleRowRegex.getRow());
String po_row = new String(serialize.get(PO).getRow());
matcher = p.matcher(po_row);
assertTrue(matcher.matches());
tripleRowRegex = poStrategy.buildRegex(null, null, objStr, null, objectTypeInfo);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(new String(dupTriple_str.get(PO).getRow()));
assertFalse(matcher.matches());
// osp table
TriplePatternStrategy ospStrategy = new OspWholeRowTriplePatternStrategy();
tripleRowRegex = ospStrategy.buildRegex(null, null, objStr, null, objectTypeInfo);
p = Pattern.compile(tripleRowRegex.getRow());
String osp_row = new String(serialize.get(OSP).getRow());
matcher = p.matcher(osp_row);
assertTrue(matcher.matches());
tripleRowRegex = ospStrategy.buildRegex(null, null, objStr, null, objectTypeInfo);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(new String(dupTriple_str.get(OSP).getRow()));
assertFalse(matcher.matches());
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class HashedSpoWholeRowTriplePatternStrategyTest method testSpoRange.
public void testSpoRange() 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, rangeURI, null, null);
assertContains(entry.getValue(), tripleRow.getRow());
entry = strategy.defineRange(uri, uri, rangeURI2, null, null);
assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class RyaStatementBindingSetKeyValueIterator method next.
@Override
public Map.Entry<RyaStatement, BindingSet> next() throws RyaDAOException {
if (!hasNext() || isClosed()) {
throw new NoSuchElementException();
}
try {
while (true) {
if (bsIter != null && bsIter.hasNext()) {
maxResults--;
return new RdfCloudTripleStoreUtils.CustomEntry<RyaStatement, BindingSet>(statement, bsIter.next());
}
if (dataIterator.hasNext()) {
Map.Entry<Key, Value> next = dataIterator.next();
Key key = next.getKey();
statement = ryaContext.deserializeTriple(tableLayout, new TripleRow(key.getRowData().toArray(), key.getColumnFamilyData().toArray(), key.getColumnQualifierData().toArray(), key.getTimestamp(), key.getColumnVisibilityData().toArray(), next.getValue().get()));
if (next.getValue() != null) {
statement.setValue(next.getValue().get());
}
Collection<BindingSet> bindingSets = rangeMap.containsKey(key);
if (!bindingSets.isEmpty()) {
bsIter = bindingSets.iterator();
}
} else {
break;
}
}
return null;
} catch (TripleRowResolverException e) {
throw new RyaDAOException(e);
}
}
Aggregations