Search in sources :

Example 11 with RyaTypeResolverException

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

the class CustomDatatypeResolver method deserialize.

@Override
public RyaType deserialize(final byte[] bytes) throws RyaTypeResolverException {
    if (!deserializable(bytes)) {
        throw new RyaTypeResolverException("Bytes not deserializable");
    }
    final RyaType rt = newInstance();
    final int length = bytes.length;
    final int indexOfType = Bytes.indexOf(bytes, TYPE_DELIM_BYTE);
    if (indexOfType < 1) {
        throw new RyaTypeResolverException("Not a datatype literal");
    }
    final String label = deserializeData(new String(bytes, 0, indexOfType, StandardCharsets.UTF_8));
    rt.setDataType(new URIImpl(new String(bytes, indexOfType + 1, (length - indexOfType) - 3, StandardCharsets.UTF_8)));
    rt.setData(label);
    return rt;
}
Also used : RyaTypeResolverException(org.apache.rya.api.resolver.RyaTypeResolverException) URIImpl(org.openrdf.model.impl.URIImpl) RyaType(org.apache.rya.api.domain.RyaType)

Example 12 with RyaTypeResolverException

use of org.apache.rya.api.resolver.RyaTypeResolverException 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)

Example 13 with RyaTypeResolverException

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

the class SpoWholeRowTriplePatternStrategy method defineRange.

@Override
public Map.Entry<TABLE_LAYOUT, ByteRange> defineRange(final RyaURI subject, final RyaURI predicate, final RyaType object, final RyaURI context, final RdfCloudTripleStoreConfiguration conf) throws IOException {
    try {
        // s_r(p)(ng)
        if (!handles(subject, predicate, object, context)) {
            return null;
        }
        final RyaContext ryaContext = RyaContext.getInstance();
        final TABLE_LAYOUT table_layout = TABLE_LAYOUT.SPO;
        byte[] start;
        byte[] stop;
        if (predicate != null) {
            if (object != null) {
                if (object instanceof RyaRange) {
                    // sp_r(o)
                    // range = sp_r(o.s)->sp_r(o.e) (remove last byte to remove type info)
                    RyaRange rv = (RyaRange) object;
                    rv = ryaContext.transformRange(rv);
                    final byte[] objStartBytes = ryaContext.serializeType(rv.getStart())[0];
                    final byte[] objEndBytes = ryaContext.serializeType(rv.getStop())[0];
                    final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8);
                    final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
                    start = Bytes.concat(subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objStartBytes);
                    stop = Bytes.concat(subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objEndBytes, DELIM_BYTES, LAST_BYTES);
                } else {
                    // spo
                    // range = spo->spo (remove last byte to remove type info)
                    // TODO: There must be a better way than creating multiple byte[]
                    final byte[] objBytes = ryaContext.serializeType(object)[0];
                    start = Bytes.concat(subject.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, predicate.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, objBytes, TYPE_DELIM_BYTES);
                    stop = Bytes.concat(start, LAST_BYTES);
                }
            } else if (predicate instanceof RyaRange) {
                // s_r(p)
                // range = s_r(p.s)->s_r(p.e)
                RyaRange rv = (RyaRange) predicate;
                rv = ryaContext.transformRange(rv);
                final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8);
                final byte[] predStartBytes = rv.getStart().getData().getBytes(StandardCharsets.UTF_8);
                final byte[] predStopBytes = rv.getStop().getData().getBytes(StandardCharsets.UTF_8);
                start = Bytes.concat(subjBytes, DELIM_BYTES, predStartBytes);
                stop = Bytes.concat(subjBytes, DELIM_BYTES, predStopBytes, DELIM_BYTES, LAST_BYTES);
            } else {
                // sp
                // range = sp
                start = Bytes.concat(subject.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, predicate.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES);
                stop = Bytes.concat(start, LAST_BYTES);
            }
        } else if (subject instanceof RyaRange) {
            // r(s)
            // range = r(s.s) -> r(s.e)
            RyaRange ru = (RyaRange) subject;
            ru = ryaContext.transformRange(ru);
            start = ru.getStart().getData().getBytes(StandardCharsets.UTF_8);
            stop = Bytes.concat(ru.getStop().getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, LAST_BYTES);
        } else {
            // s
            // range = s
            start = Bytes.concat(subject.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES);
            stop = Bytes.concat(start, LAST_BYTES);
        }
        return new RdfCloudTripleStoreUtils.CustomEntry<TABLE_LAYOUT, ByteRange>(table_layout, new ByteRange(start, stop));
    } catch (final RyaTypeResolverException e) {
        throw new IOException(e);
    }
}
Also used : TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) RyaContext(org.apache.rya.api.resolver.RyaContext) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaRange(org.apache.rya.api.domain.RyaRange) RyaTypeResolverException(org.apache.rya.api.resolver.RyaTypeResolverException) IOException(java.io.IOException)

Example 14 with RyaTypeResolverException

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

the class DateTimeRyaTypeResolver method serializeData.

@Override
protected String serializeData(String data) throws RyaTypeResolverException {
    try {
        DateTime dateTime = DateTime.parse(data, XMLDATETIME_PARSER);
        Date value = dateTime.toDate();
        return DATE_STRING_TYPE_ENCODER.encode(value);
    } catch (TypeEncodingException e) {
        throw new RyaTypeResolverException("Exception occurred serializing data[" + data + "]", e);
    }
}
Also used : TypeEncodingException(org.calrissian.mango.types.exception.TypeEncodingException) RyaTypeResolverException(org.apache.rya.api.resolver.RyaTypeResolverException) DateTime(org.joda.time.DateTime) Date(java.util.Date)

Example 15 with RyaTypeResolverException

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

the class StarQuery method getConstrainedStarQuery.

public static StarQuery getConstrainedStarQuery(final StarQuery query, final BindingSet bs) {
    if (bs.size() == 0) {
        return query;
    }
    final Set<String> bindingNames = bs.getBindingNames();
    final Set<String> unCommonVarNames = query.getUnCommonVars();
    final Set<String> intersectVar = Sets.intersection(bindingNames, unCommonVarNames);
    if (!query.commonVarConstant()) {
        final Value v = bs.getValue(query.getCommonVarName());
        if (v != null) {
            query.commonVar.setValue(v);
        }
    }
    for (final String s : intersectVar) {
        try {
            query.nodeColumnCond[query.varPos.get(s)] = query.setValue(query.nodeColumnCond[query.varPos.get(s)], bs.getValue(s));
        } catch (final RyaTypeResolverException e) {
            e.printStackTrace();
        }
    }
    return query;
}
Also used : Value(org.openrdf.model.Value) RyaTypeResolverException(org.apache.rya.api.resolver.RyaTypeResolverException)

Aggregations

RyaTypeResolverException (org.apache.rya.api.resolver.RyaTypeResolverException)16 IOException (java.io.IOException)5 TABLE_LAYOUT (org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT)5 RyaRange (org.apache.rya.api.domain.RyaRange)5 RyaType (org.apache.rya.api.domain.RyaType)5 RyaURI (org.apache.rya.api.domain.RyaURI)5 ByteRange (org.apache.rya.api.query.strategy.ByteRange)5 RyaContext (org.apache.rya.api.resolver.RyaContext)5 TripleRowResolverException (org.apache.rya.api.resolver.triple.TripleRowResolverException)4 MessageDigest (java.security.MessageDigest)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 HashMap (java.util.HashMap)2 RdfCloudTripleStoreConstants (org.apache.rya.api.RdfCloudTripleStoreConstants)2 RyaStatement (org.apache.rya.api.domain.RyaStatement)2 TripleRow (org.apache.rya.api.resolver.triple.TripleRow)2 Value (org.openrdf.model.Value)2 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)2 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 Value (org.apache.accumulo.core.data.Value)1