Search in sources :

Example 1 with TripleRowResolverException

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

the class RyaStatementWritable method readFields.

/**
 * Loads a RyaStatementWritable by reading data from an input stream.
 * Creates a new RyaStatement and assigns it to this RyaStatementWritable.
 * @param   dataInput   An stream containing serialized statement data.
 */
@Override
public void readFields(DataInput dataInput) throws IOException {
    byte[] row = read(dataInput);
    byte[] columnFamily = read(dataInput);
    byte[] columnQualifier = read(dataInput);
    byte[] columnVisibility = read(dataInput);
    byte[] value = read(dataInput);
    boolean b = dataInput.readBoolean();
    Long timestamp = null;
    if (b) {
        timestamp = dataInput.readLong();
    }
    try {
        ryaStatement = ryaContext.deserializeTriple(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, new TripleRow(row, columnFamily, columnQualifier));
        ryaStatement.setColumnVisibility(columnVisibility);
        ryaStatement.setValue(value);
        ryaStatement.setTimestamp(timestamp);
    } catch (TripleRowResolverException e) {
        throw new IOException(e);
    }
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) IOException(java.io.IOException)

Example 2 with TripleRowResolverException

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

the class WholeRowHashedTripleResolver method serialize.

@Override
public Map<TABLE_LAYOUT, TripleRow> serialize(final RyaStatement stmt) throws TripleRowResolverException {
    try {
        final RyaURI subject = stmt.getSubject();
        final RyaURI predicate = stmt.getPredicate();
        final RyaType object = stmt.getObject();
        final RyaURI context = stmt.getContext();
        final Long timestamp = stmt.getTimestamp();
        final byte[] columnVisibility = stmt.getColumnVisibility();
        final String qualifer = stmt.getQualifer();
        final byte[] qualBytes = qualifer == null ? EMPTY_BYTES : qualifer.getBytes(StandardCharsets.UTF_8);
        final byte[] value = stmt.getValue();
        assert subject != null && predicate != null && object != null;
        final byte[] cf = (context == null) ? EMPTY_BYTES : context.getData().getBytes(StandardCharsets.UTF_8);
        final Map<TABLE_LAYOUT, TripleRow> tripleRowMap = new HashMap<TABLE_LAYOUT, TripleRow>();
        final MessageDigest md = MessageDigest.getInstance("MD5");
        final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8);
        final byte[] subjHashBytes = md.digest(subjBytes);
        final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
        final byte[] predHashBytes = md.digest(predBytes);
        final byte[][] objBytes = RyaContext.getInstance().serializeType(object);
        tripleRowMap.put(TABLE_LAYOUT.SPO, new TripleRow(Bytes.concat(Hex.encodeHexString(subjHashBytes).getBytes(StandardCharsets.UTF_8), DELIM_BYTES, subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes[0], objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
        tripleRowMap.put(TABLE_LAYOUT.PO, new TripleRow(Bytes.concat(Hex.encodeHexString(predHashBytes).getBytes(StandardCharsets.UTF_8), DELIM_BYTES, predBytes, DELIM_BYTES, objBytes[0], DELIM_BYTES, subjBytes, objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
        tripleRowMap.put(TABLE_LAYOUT.OSP, new TripleRow(Bytes.concat(objBytes[0], DELIM_BYTES, subjBytes, DELIM_BYTES, predBytes, objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
        return tripleRowMap;
    } catch (final RyaTypeResolverException e) {
        throw new TripleRowResolverException(e);
    } catch (final NoSuchAlgorithmException e) {
        throw new TripleRowResolverException(e);
    }
}
Also used : HashMap(java.util.HashMap) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) RyaType(org.apache.rya.api.domain.RyaType) TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) RyaURI(org.apache.rya.api.domain.RyaURI) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) RyaTypeResolverException(org.apache.rya.api.resolver.RyaTypeResolverException) MessageDigest(java.security.MessageDigest)

Example 3 with TripleRowResolverException

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

the class BaseRuleMapper method map.

@Override
protected void map(final Key key, final Value value, final Context context) throws IOException, InterruptedException {
    final TripleRow row = new TripleRow(key.getRowData().toArray(), key.getColumnFamilyData().toArray(), key.getColumnQualifierData().toArray(), key.getTimestamp(), key.getColumnVisibilityData().toArray(), value == null ? null : value.get());
    try {
        // If there's no layout, copy the row directly
        if (parentLayout == null) {
            copyRow(key, value, context);
            context.getCounter(Counters.DIRECT_ROWS_COPIED).increment(1);
        } else // If there is a layout, deserialize the statement and insert it if it meets the condition
        {
            final RyaStatement rs = resolver.deserialize(parentLayout, row);
            if (condition == null || CopyRule.accept(RyaToRdfConversions.convertStatement(rs), condition, strategy)) {
                copyStatement(rs, context);
                context.getCounter(Counters.STATEMENTS_COPIED).increment(1);
            }
        }
    } catch (final TripleRowResolverException e) {
        throw new IOException("Error deserializing triple", e);
    } catch (final QueryEvaluationException e) {
        throw new IOException("Error evaluating the filter condition", e);
    }
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RyaStatement(org.apache.rya.api.domain.RyaStatement) IOException(java.io.IOException)

Example 4 with TripleRowResolverException

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

the class MergeToolMapper method run.

/**
 * Expert users can override this method for more complete control over
 * the execution of the Mapper.
 *
 * @param context
 * @throws IOException
 */
@Override
public void run(final Context context) throws IOException, InterruptedException {
    setup(context);
    this.context = context;
    try {
        RyaStatement parentRyaStatement = nextParentRyaStatement();
        RyaStatement childRyaStatement = nextChildRyaStatement();
        CompareKeysResult compareKeysResult = null;
        // Iteratively compare parent keys to child keys until finished
        while (compareKeysResult != CompareKeysResult.FINISHED) {
            compareKeysResult = compareKeys(parentRyaStatement, childRyaStatement);
            // Based on how the keys compare add or delete keys and advance the child or parent iterators forward
            switch(compareKeysResult) {
                case ADVANCE_CHILD:
                    childRyaStatement = nextChildRyaStatement();
                    break;
                case ADVANCE_PARENT:
                    parentRyaStatement = nextParentRyaStatement();
                    break;
                case ADVANCE_CHILD_AND_ADD:
                    final RyaStatement tempChildRyaStatement = childRyaStatement;
                    childRyaStatement = nextChildRyaStatement();
                    addKey(tempChildRyaStatement, context);
                    break;
                case ADVANCE_PARENT_AND_DELETE:
                    final RyaStatement tempParentRyaStatement = parentRyaStatement;
                    parentRyaStatement = nextParentRyaStatement();
                    deleteKey(tempParentRyaStatement, context);
                    break;
                case ADVANCE_BOTH:
                    final ColumnVisibility cv1 = new ColumnVisibility(parentRyaStatement.getColumnVisibility());
                    final ColumnVisibility cv2 = new ColumnVisibility(childRyaStatement.getColumnVisibility());
                    // Update new column visibility now if necessary
                    if (!cv1.equals(cv2) && !cv2.equals(AccumuloRdfConstants.EMPTY_CV)) {
                        final ColumnVisibility newCv = combineColumnVisibilities(cv1, cv2);
                        final RyaStatement newCvRyaStatement = updateRyaStatementColumnVisibility(parentRyaStatement, newCv);
                        deleteKey(parentRyaStatement, context);
                        addKey(newCvRyaStatement, context);
                    }
                    parentRyaStatement = nextParentRyaStatement();
                    childRyaStatement = nextChildRyaStatement();
                    break;
                case FINISHED:
                    log.info("Finished scanning parent and child tables");
                    break;
                default:
                    log.error("Unknown result: " + compareKeysResult);
                    break;
            }
        }
    } catch (MutationsRejectedException | TripleRowResolverException e) {
        log.error("Error encountered while merging", e);
    } finally {
        cleanup(context);
    }
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) RyaStatement(org.apache.rya.api.domain.RyaStatement) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 5 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 Iterator<Entry<Key, Value>> iterator, final RyaTripleContext ryaContext) {
    RyaStatement ryaStatement = null;
    if (iterator.hasNext()) {
        final Entry<Key, Value> entry = iterator.next();
        final Key key = entry.getKey();
        final Value value = entry.getValue();
        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)

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