Search in sources :

Example 1 with RyaTripleContext

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);
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) RyaStatement(org.apache.rya.api.domain.RyaStatement) IOException(java.io.IOException) FetchStatementException(org.apache.rya.export.api.store.FetchStatementException) TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) AddStatementException(org.apache.rya.export.api.store.AddStatementException) ParentMetadataExistsException(org.apache.rya.export.api.metadata.ParentMetadataExistsException) UpdateStatementException(org.apache.rya.export.api.store.UpdateStatementException) FetchStatementException(org.apache.rya.export.api.store.FetchStatementException) IOException(java.io.IOException) RemoveStatementException(org.apache.rya.export.api.store.RemoveStatementException) ContainsStatementException(org.apache.rya.export.api.store.ContainsStatementException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MergerException(org.apache.rya.export.api.MergerException) TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) RyaTripleContext(org.apache.rya.api.resolver.RyaTripleContext) Entry(java.util.Map.Entry) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Example 2 with RyaTripleContext

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;
    }
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) RyaTripleContext(org.apache.rya.api.resolver.RyaTripleContext) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration)

Aggregations

RyaStatement (org.apache.rya.api.domain.RyaStatement)2 RyaTripleContext (org.apache.rya.api.resolver.RyaTripleContext)2 TripleRowResolverException (org.apache.rya.api.resolver.triple.TripleRowResolverException)2 IOException (java.io.IOException)1 Entry (java.util.Map.Entry)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 Scanner (org.apache.accumulo.core.client.Scanner)1 Key (org.apache.accumulo.core.data.Key)1 Value (org.apache.accumulo.core.data.Value)1 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)1 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)1 TripleRow (org.apache.rya.api.resolver.triple.TripleRow)1 MergerException (org.apache.rya.export.api.MergerException)1 ParentMetadataExistsException (org.apache.rya.export.api.metadata.ParentMetadataExistsException)1 AddStatementException (org.apache.rya.export.api.store.AddStatementException)1 ContainsStatementException (org.apache.rya.export.api.store.ContainsStatementException)1 FetchStatementException (org.apache.rya.export.api.store.FetchStatementException)1 RemoveStatementException (org.apache.rya.export.api.store.RemoveStatementException)1 UpdateStatementException (org.apache.rya.export.api.store.UpdateStatementException)1