Search in sources :

Example 16 with TripleRowResolverException

use of org.apache.rya.api.resolver.triple.TripleRowResolverException in project incubator-rya by apache.

the class InsertTriples method insert.

/**
 * Insert a batch of RyaStatements into Fluo.
 *
 * @param fluo - A connection to the Fluo table that will be updated. (not null)
 * @param triples - The triples to insert. (not null)
 */
public void insert(final FluoClient fluo, final Collection<RyaStatement> triples) {
    checkNotNull(fluo);
    checkNotNull(triples);
    try (Transaction tx = fluo.newTransaction()) {
        for (final RyaStatement triple : triples) {
            Optional<byte[]> visibility = Optional.fromNullable(triple.getColumnVisibility());
            try {
                tx.set(spoFormat(triple), FluoQueryColumns.TRIPLES, Bytes.of(visibility.or(new byte[0])));
            } catch (final TripleRowResolverException e) {
                log.error("Could not convert a Triple into the SPO format: " + triple);
            }
        }
        tx.commit();
    }
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) Transaction(org.apache.fluo.api.client.Transaction) RyaStatement(org.apache.rya.api.domain.RyaStatement)

Example 17 with TripleRowResolverException

use of org.apache.rya.api.resolver.triple.TripleRowResolverException in project incubator-rya by apache.

the class MergeToolMapper method nextRyaStatement.

private static RyaStatement nextRyaStatement(final Context context, final RyaTripleContext ryaContext) throws IOException, InterruptedException {
    RyaStatement ryaStatement = null;
    if (context.nextKeyValue()) {
        final Key key = context.getCurrentKey();
        final Value value = context.getCurrentValue();
        try {
            ryaStatement = createRyaStatement(key, value, ryaContext);
        } catch (final TripleRowResolverException e) {
            log.error("TripleRowResolverException encountered while creating statement", e);
        }
    }
    return ryaStatement;
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) Value(org.apache.accumulo.core.data.Value) RyaStatement(org.apache.rya.api.domain.RyaStatement) Key(org.apache.accumulo.core.data.Key)

Example 18 with TripleRowResolverException

use of org.apache.rya.api.resolver.triple.TripleRowResolverException in project incubator-rya by apache.

the class RyaTableKeyValues method invoke.

@SuppressWarnings({ "unchecked", "rawtypes" })
public RyaTableKeyValues invoke() throws IOException {
    /**
     * TODO: If there are contexts, do we still replicate the information into the default graph as well
     * as the named graphs?
     */
    try {
        Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, org.apache.rya.api.resolver.triple.TripleRow> rowMap = instance.serializeTriple(stmt);
        TripleRow tripleRow = rowMap.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
        byte[] columnVisibility = tripleRow.getColumnVisibility();
        Text cv = columnVisibility == null ? EMPTY_CV_TEXT : new Text(columnVisibility);
        Long timestamp = tripleRow.getTimestamp();
        timestamp = timestamp == null ? 0l : timestamp;
        byte[] value = tripleRow.getValue();
        Value v = value == null ? EMPTY_VALUE : new Value(value);
        spo.add(new SimpleEntry(new Key(new Text(tripleRow.getRow()), new Text(tripleRow.getColumnFamily()), new Text(tripleRow.getColumnQualifier()), cv, timestamp), v));
        tripleRow = rowMap.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
        po.add(new SimpleEntry(new Key(new Text(tripleRow.getRow()), new Text(tripleRow.getColumnFamily()), new Text(tripleRow.getColumnQualifier()), cv, timestamp), v));
        tripleRow = rowMap.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP);
        osp.add(new SimpleEntry(new Key(new Text(tripleRow.getRow()), new Text(tripleRow.getColumnFamily()), new Text(tripleRow.getColumnQualifier()), cv, timestamp), v));
    } catch (TripleRowResolverException e) {
        throw new IOException(e);
    }
    return this;
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Example 19 with TripleRowResolverException

use of org.apache.rya.api.resolver.triple.TripleRowResolverException in project incubator-rya by apache.

the class RyaTableMutationsFactory method serializeDelete.

public Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serializeDelete(RyaStatement stmt) throws IOException {
    Collection<Mutation> spo_muts = new ArrayList<Mutation>();
    Collection<Mutation> po_muts = new ArrayList<Mutation>();
    Collection<Mutation> osp_muts = new ArrayList<Mutation>();
    /**
     * TODO: If there are contexts, do we still replicate the information into the default graph as well
     * as the named graphs?
     */
    try {
        Map<TABLE_LAYOUT, TripleRow> rowMap = ryaContext.serializeTriple(stmt);
        TripleRow tripleRow = rowMap.get(TABLE_LAYOUT.SPO);
        spo_muts.add(deleteMutation(tripleRow));
        tripleRow = rowMap.get(TABLE_LAYOUT.PO);
        po_muts.add(deleteMutation(tripleRow));
        tripleRow = rowMap.get(TABLE_LAYOUT.OSP);
        osp_muts.add(deleteMutation(tripleRow));
    } catch (TripleRowResolverException fe) {
        throw new IOException(fe);
    }
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> mutations = new HashMap<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>>();
    mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, spo_muts);
    mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO, po_muts);
    mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP, osp_muts);
    return mutations;
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Mutation(org.apache.accumulo.core.data.Mutation) IOException(java.io.IOException) RdfCloudTripleStoreConstants(org.apache.rya.api.RdfCloudTripleStoreConstants)

Example 20 with TripleRowResolverException

use of org.apache.rya.api.resolver.triple.TripleRowResolverException in project incubator-rya by apache.

the class RyaTableMutationsFactory method serialize.

// TODO: Does this still need to be collections
public Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize(RyaStatement stmt) throws IOException {
    Collection<Mutation> spo_muts = new ArrayList<Mutation>();
    Collection<Mutation> po_muts = new ArrayList<Mutation>();
    Collection<Mutation> osp_muts = new ArrayList<Mutation>();
    /**
     * TODO: If there are contexts, do we still replicate the information into the default graph as well
     * as the named graphs?
     */
    try {
        Map<TABLE_LAYOUT, TripleRow> rowMap = ryaContext.serializeTriple(stmt);
        TripleRow tripleRow = rowMap.get(TABLE_LAYOUT.SPO);
        spo_muts.add(createMutation(tripleRow));
        tripleRow = rowMap.get(TABLE_LAYOUT.PO);
        po_muts.add(createMutation(tripleRow));
        tripleRow = rowMap.get(TABLE_LAYOUT.OSP);
        osp_muts.add(createMutation(tripleRow));
    } catch (TripleRowResolverException fe) {
        throw new IOException(fe);
    }
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> mutations = new HashMap<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>>();
    mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, spo_muts);
    mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO, po_muts);
    mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP, osp_muts);
    return mutations;
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Mutation(org.apache.accumulo.core.data.Mutation) IOException(java.io.IOException) RdfCloudTripleStoreConstants(org.apache.rya.api.RdfCloudTripleStoreConstants)

Aggregations

TripleRowResolverException (org.apache.rya.api.resolver.triple.TripleRowResolverException)22 RyaStatement (org.apache.rya.api.domain.RyaStatement)14 TripleRow (org.apache.rya.api.resolver.triple.TripleRow)13 IOException (java.io.IOException)8 Key (org.apache.accumulo.core.data.Key)7 Value (org.apache.accumulo.core.data.Value)7 HashMap (java.util.HashMap)4 TABLE_LAYOUT (org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT)4 RyaURI (org.apache.rya.api.domain.RyaURI)4 RyaTypeResolverException (org.apache.rya.api.resolver.RyaTypeResolverException)4 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Mutation (org.apache.accumulo.core.data.Mutation)2 Transaction (org.apache.fluo.api.client.Transaction)2 RdfCloudTripleStoreConstants (org.apache.rya.api.RdfCloudTripleStoreConstants)2 RyaType (org.apache.rya.api.domain.RyaType)2 RyaTripleContext (org.apache.rya.api.resolver.RyaTripleContext)2 MessageDigest (java.security.MessageDigest)1