Search in sources :

Example 11 with TripleRowResolverException

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

the class WholeRowTripleResolver method deserialize.

@Override
public RyaStatement deserialize(final TABLE_LAYOUT table_layout, final TripleRow tripleRow) throws TripleRowResolverException {
    try {
        assert tripleRow != null && table_layout != null;
        final byte[] row = tripleRow.getRow();
        final int firstIndex = Bytes.indexOf(row, DELIM_BYTE);
        final int secondIndex = Bytes.lastIndexOf(row, DELIM_BYTE);
        final int typeIndex = Bytes.indexOf(row, TYPE_DELIM_BYTE);
        final byte[] first = Arrays.copyOf(row, firstIndex);
        final byte[] second = Arrays.copyOfRange(row, firstIndex + 1, secondIndex);
        final byte[] third = Arrays.copyOfRange(row, secondIndex + 1, typeIndex);
        final byte[] type = Arrays.copyOfRange(row, typeIndex, row.length);
        final byte[] columnFamily = tripleRow.getColumnFamily();
        final boolean contextExists = columnFamily != null && columnFamily.length > 0;
        final RyaURI context = (contextExists) ? (new RyaURI(new String(columnFamily, StandardCharsets.UTF_8))) : null;
        final byte[] columnQualifier = tripleRow.getColumnQualifier();
        final String qualifier = columnQualifier != null && columnQualifier.length > 0 ? new String(columnQualifier, StandardCharsets.UTF_8) : null;
        final Long timestamp = tripleRow.getTimestamp();
        final byte[] columnVisibility = tripleRow.getColumnVisibility();
        final byte[] value = tripleRow.getValue();
        switch(table_layout) {
            case SPO:
                {
                    final byte[] obj = Bytes.concat(third, type);
                    return new RyaStatement(new RyaURI(new String(first, StandardCharsets.UTF_8)), new RyaURI(new String(second, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp);
                }
            case PO:
                {
                    final byte[] obj = Bytes.concat(second, type);
                    return new RyaStatement(new RyaURI(new String(third, StandardCharsets.UTF_8)), new RyaURI(new String(first, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp);
                }
            case OSP:
                {
                    final byte[] obj = Bytes.concat(first, type);
                    return new RyaStatement(new RyaURI(new String(second, StandardCharsets.UTF_8)), new RyaURI(new String(third, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp);
                }
        }
    } catch (final RyaTypeResolverException e) {
        throw new TripleRowResolverException(e);
    }
    throw new TripleRowResolverException("TripleRow[" + tripleRow + "] with Table layout[" + table_layout + "] is not deserializable");
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaTypeResolverException(org.apache.rya.api.resolver.RyaTypeResolverException)

Example 12 with TripleRowResolverException

use of org.apache.rya.api.resolver.triple.TripleRowResolverException 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 13 with TripleRowResolverException

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

the class RyaStatementWritable method write.

/**
 * Serializes this RyaStatementWritable.
 * @param   dataOutput  An output stream for serialized statement data.
 * @throws  IOException if the RyaStatement is null or otherwise can't be
 *          serialized.
 */
@Override
public void write(DataOutput dataOutput) throws IOException {
    if (ryaStatement == null) {
        throw new IOException("Rya Statement is null");
    }
    try {
        Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> map = ryaContext.serializeTriple(ryaStatement);
        TripleRow tripleRow = map.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
        byte[] row = tripleRow.getRow();
        byte[] columnFamily = tripleRow.getColumnFamily();
        byte[] columnQualifier = tripleRow.getColumnQualifier();
        write(dataOutput, row);
        write(dataOutput, columnFamily);
        write(dataOutput, columnQualifier);
        write(dataOutput, ryaStatement.getColumnVisibility());
        write(dataOutput, ryaStatement.getValue());
        Long timestamp = ryaStatement.getTimestamp();
        boolean b = timestamp != null;
        dataOutput.writeBoolean(b);
        if (b) {
            dataOutput.writeLong(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 14 with TripleRowResolverException

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

the class WholeRowTripleResolver 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 byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8);
        final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
        final byte[][] objBytes = RyaContext.getInstance().serializeType(object);
        tripleRowMap.put(TABLE_LAYOUT.SPO, new TripleRow(Bytes.concat(subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes[0], objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
        tripleRowMap.put(TABLE_LAYOUT.PO, new TripleRow(Bytes.concat(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);
    }
}
Also used : 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) HashMap(java.util.HashMap) RyaTypeResolverException(org.apache.rya.api.resolver.RyaTypeResolverException) RyaType(org.apache.rya.api.domain.RyaType)

Example 15 with TripleRowResolverException

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

the class WholeRowHashedTripleResolver method deserialize.

@Override
public RyaStatement deserialize(final TABLE_LAYOUT table_layout, final TripleRow tripleRow) throws TripleRowResolverException {
    try {
        assert tripleRow != null && table_layout != null;
        byte[] row = tripleRow.getRow();
        // if it is a hashed row, ony keep the row after the hash
        if ((table_layout == TABLE_LAYOUT.SPO) || (table_layout == TABLE_LAYOUT.PO)) {
            final int hashStart = Bytes.indexOf(row, DELIM_BYTE);
            row = Arrays.copyOfRange(row, hashStart + 1, row.length);
        }
        final int firstIndex = Bytes.indexOf(row, DELIM_BYTE);
        final byte[] first = Arrays.copyOf(row, firstIndex);
        final int secondIndex = Bytes.lastIndexOf(row, DELIM_BYTE);
        final int typeIndex = Bytes.indexOf(row, TYPE_DELIM_BYTE);
        final byte[] second = Arrays.copyOfRange(row, firstIndex + 1, secondIndex);
        final byte[] third = Arrays.copyOfRange(row, secondIndex + 1, typeIndex);
        final byte[] type = Arrays.copyOfRange(row, typeIndex, row.length);
        final byte[] columnFamily = tripleRow.getColumnFamily();
        final boolean contextExists = columnFamily != null && columnFamily.length > 0;
        final RyaURI context = (contextExists) ? (new RyaURI(new String(columnFamily, StandardCharsets.UTF_8))) : null;
        final byte[] columnQualifier = tripleRow.getColumnQualifier();
        final String qualifier = columnQualifier != null && columnQualifier.length > 0 ? new String(columnQualifier, StandardCharsets.UTF_8) : null;
        final Long timestamp = tripleRow.getTimestamp();
        final byte[] columnVisibility = tripleRow.getColumnVisibility();
        final byte[] value = tripleRow.getValue();
        switch(table_layout) {
            case SPO:
                {
                    final byte[] obj = Bytes.concat(third, type);
                    return new RyaStatement(new RyaURI(new String(first, StandardCharsets.UTF_8)), new RyaURI(new String(second, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp);
                }
            case PO:
                {
                    final byte[] obj = Bytes.concat(second, type);
                    return new RyaStatement(new RyaURI(new String(third, StandardCharsets.UTF_8)), new RyaURI(new String(first, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp);
                }
            case OSP:
                {
                    final byte[] obj = Bytes.concat(first, type);
                    return new RyaStatement(new RyaURI(new String(second, StandardCharsets.UTF_8)), new RyaURI(new String(third, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp);
                }
        }
    } catch (final RyaTypeResolverException e) {
        throw new TripleRowResolverException(e);
    }
    throw new TripleRowResolverException("TripleRow[" + tripleRow + "] with Table layout[" + table_layout + "] is not deserializable");
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaTypeResolverException(org.apache.rya.api.resolver.RyaTypeResolverException)

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