use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class RyaSubGraphKafkaSerDeTest method serializationTestWithLiteral.
@Test
public void serializationTestWithLiteral() {
RyaSubGraph bundle = new RyaSubGraph(UUID.randomUUID().toString());
bundle.addStatement(new RyaStatement(new RyaURI("uri:123"), new RyaURI("uri:234"), new RyaType(XMLSchema.INTEGER, "345")));
bundle.addStatement(new RyaStatement(new RyaURI("uri:345"), new RyaURI("uri:567"), new RyaType(XMLSchema.INTEGER, "789")));
byte[] bundleBytes = serializer.toBytes(bundle);
RyaSubGraph deserializedBundle = serializer.fromBytes(bundleBytes);
assertEquals(bundle, deserializedBundle);
}
use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class FluoAndHistoricPcjsDemo method prettyFormat.
private static String prettyFormat(final RyaStatement statement) {
final RyaURI s = statement.getSubject();
final RyaURI p = statement.getPredicate();
final RyaType o = statement.getObject();
return "<" + s.getData() + "> <" + p.getData() + "> <" + o.getData() + ">";
}
use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class AccumuloRyaQueryEngine method query.
@Override
public CloseableIterable<RyaStatement> query(RyaQuery ryaQuery) throws RyaDAOException {
Preconditions.checkNotNull(ryaQuery);
RyaStatement stmt = ryaQuery.getQuery();
Preconditions.checkNotNull(stmt);
// query configuration
String[] auths = ryaQuery.getAuths();
Authorizations authorizations = auths != null ? new Authorizations(auths) : configuration.getAuthorizations();
Long ttl = ryaQuery.getTtl();
Long currentTime = ryaQuery.getCurrentTime();
Long maxResults = ryaQuery.getMaxResults();
Integer batchSize = ryaQuery.getBatchSize();
String regexSubject = ryaQuery.getRegexSubject();
String regexPredicate = ryaQuery.getRegexPredicate();
String regexObject = ryaQuery.getRegexObject();
TableLayoutStrategy tableLayoutStrategy = configuration.getTableLayoutStrategy();
try {
// find triple pattern range
TriplePatternStrategy strategy = ryaContext.retrieveStrategy(stmt);
TABLE_LAYOUT layout;
Range range;
RyaURI subject = stmt.getSubject();
RyaURI predicate = stmt.getPredicate();
RyaType object = stmt.getObject();
RyaURI context = stmt.getContext();
String qualifier = stmt.getQualifer();
TripleRowRegex tripleRowRegex = null;
if (strategy != null) {
// otherwise, full table scan is supported
Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(subject, predicate, object, context, null);
layout = entry.getKey();
ByteRange byteRange = entry.getValue();
range = new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd()));
} else {
range = new Range();
layout = TABLE_LAYOUT.SPO;
strategy = ryaContext.retrieveStrategy(layout);
}
byte[] objectTypeInfo = null;
if (object != null) {
// TODO: Not good to serialize this twice
if (object instanceof RyaRange) {
objectTypeInfo = RyaContext.getInstance().serializeType(((RyaRange) object).getStart())[1];
} else {
objectTypeInfo = RyaContext.getInstance().serializeType(object)[1];
}
}
tripleRowRegex = strategy.buildRegex(regexSubject, regexPredicate, regexObject, null, objectTypeInfo);
// use range to set scanner
// populate scanner based on authorizations, ttl
String table = layoutToTable(layout, tableLayoutStrategy);
Scanner scanner = connector.createScanner(table, authorizations);
scanner.setRange(range);
if (batchSize != null) {
scanner.setBatchSize(batchSize);
}
fillScanner(scanner, context, qualifier, ttl, currentTime, tripleRowRegex, ryaQuery.getConf());
FluentCloseableIterable<RyaStatement> results = FluentCloseableIterable.from(new ScannerBaseCloseableIterable(scanner)).transform(keyValueToRyaStatementFunctionMap.get(layout));
if (maxResults != null) {
results = results.limit(maxResults.intValue());
}
return results;
} catch (Exception e) {
throw new RyaDAOException(e);
}
}
use of org.apache.rya.api.domain.RyaType 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.domain.RyaType in project incubator-rya by apache.
the class AccumuloRyaDAOTest method testLiteralTypes.
@Test
public void testLiteralTypes() throws Exception {
RyaURI cpu = new RyaURI(litdupsNS + "cpu");
RyaURI loadPerc = new RyaURI(litdupsNS + "loadPerc");
RyaType longLit = new RyaType(XMLSchema.LONG, "3");
dao.add(new RyaStatement(cpu, loadPerc, longLit));
AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();
CloseableIteration<RyaStatement, RyaDAOException> query = queryEngine.query(new RyaStatement(cpu, null, null), conf);
assertTrue(query.hasNext());
RyaStatement next = query.next();
assertEquals(new Long(longLit.getData()), new Long(next.getObject().getData()));
query.close();
RyaType doubleLit = new RyaType(XMLSchema.DOUBLE, "2.0");
dao.add(new RyaStatement(cpu, loadPerc, doubleLit));
query = queryEngine.query(new RyaStatement(cpu, loadPerc, doubleLit), conf);
assertTrue(query.hasNext());
next = query.next();
assertEquals(Double.parseDouble(doubleLit.getData()), Double.parseDouble(next.getObject().getData()), 0.001);
query.close();
}
Aggregations