use of org.apache.rya.api.resolver.RyaTripleContext in project incubator-rya by apache.
the class AccumuloRyaStatementStore method fetchStatements.
@Override
public Iterator<RyaStatement> fetchStatements() throws FetchStatementException {
try {
final RyaTripleContext ryaTripleContext = RyaTripleContext.getInstance(accumuloRyaDao.getConf());
Scanner scanner = null;
try {
scanner = AccumuloRyaUtils.getScanner(tablePrefix + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, accumuloRyaDao.getConf());
for (final IteratorSetting iteratorSetting : iteratorSettings) {
scanner.addScanIterator(iteratorSetting);
}
} catch (final IOException e) {
throw new FetchStatementException("Unable to get scanner to fetch Rya Statements", e);
}
// Convert Entry iterator to RyaStatement iterator
final Iterator<Entry<Key, Value>> entryIter = scanner.iterator();
final Iterator<RyaStatement> ryaStatementIter = Iterators.transform(entryIter, new Function<Entry<Key, Value>, RyaStatement>() {
@Override
public RyaStatement apply(final Entry<Key, Value> entry) {
final Key key = entry.getKey();
final Value value = entry.getValue();
RyaStatement ryaStatement = null;
try {
ryaStatement = AccumuloRyaUtils.createRyaStatement(key, value, ryaTripleContext);
} catch (final TripleRowResolverException e) {
log.error("Unable to convert the key/value pair into a Rya Statement", e);
}
return ryaStatement;
}
});
return ryaStatementIter;
} catch (final Exception e) {
throw new FetchStatementException("Failed to fetch statements.", e);
}
}
use of org.apache.rya.api.resolver.RyaTripleContext in project incubator-rya by apache.
the class MRReasoningUtils method getStatement.
/**
* Convert an Accumulo row to a RyaStatement.
*/
static RyaStatement getStatement(Key row, Value data, Configuration conf) {
try {
RyaTripleContext ryaContext = RyaTripleContext.getInstance(new AccumuloRdfConfiguration(conf));
RyaStatement ryaStatement = ryaContext.deserializeTriple(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, new TripleRow(row.getRow().getBytes(), row.getColumnFamily().getBytes(), row.getColumnQualifier().getBytes(), row.getTimestamp(), row.getColumnVisibility().getBytes(), data.get()));
return ryaStatement;
} catch (TripleRowResolverException e) {
e.printStackTrace();
System.err.println("row: " + row);
return null;
} catch (IllegalArgumentException e) {
e.printStackTrace();
System.err.println("row: " + row);
throw e;
}
}
Aggregations