Search in sources :

Example 21 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class Upgrade322ToolTest method testUpgrade.

public void testUpgrade() throws Exception {
    Upgrade322Tool.main(new String[] { "-Dac.mock=true", "-Dac.instance=" + instance, "-Dac.username=" + user, "-Dac.pwd=" + pwd, "-Drdf.tablePrefix=" + tablePrefix });
    final AccumuloRdfConfiguration configuration = new AccumuloRdfConfiguration();
    configuration.setTablePrefix(tablePrefix);
    final AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO();
    ryaDAO.setConnector(connector);
    ryaDAO.setConf(configuration);
    ryaDAO.init();
    final AccumuloRyaQueryEngine queryEngine = ryaDAO.getQueryEngine();
    TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#booleanLit"), new RyaType(XMLSchema.BOOLEAN, "true")), queryEngine);
    TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#longLit"), new RyaType(XMLSchema.LONG, "10")), queryEngine);
    TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#intLit"), new RyaType(XMLSchema.INTEGER, "10")), queryEngine);
    TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#byteLit"), new RyaType(XMLSchema.BYTE, "10")), queryEngine);
    TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#doubleLit"), new RyaType(XMLSchema.DOUBLE, "10.0")), queryEngine);
    TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#dateLit"), new RyaType(XMLSchema.DATETIME, "2011-07-12T06:00:00.000Z")), queryEngine);
    TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#stringLit"), new RyaType("stringLit")), queryEngine);
    TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#uriLit"), new RyaURI("http://here/2010/tracked-data-provenance/ns" + "#objectuuid1")), queryEngine);
    TestUtils.verify(new RyaStatement(new RyaURI("urn:org.apache.rya/2012/05#rts"), new RyaURI("urn:org.apache.rya/2012/05#version"), new RyaType("3.0.0")), queryEngine);
}
Also used : AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) RyaURI(org.apache.rya.api.domain.RyaURI) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration)

Example 22 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class RyaTypeWritable method equals.

/**
 * Tests for equality using the equals method of the enclosed RyaType.
 * @param   o   Object to compare with
 * @return  true if both objects are RyaTypeWritables containing equivalent
 *          RyaTypes.
 */
@Override
public boolean equals(Object o) {
    if (o == this) {
        return true;
    }
    if (o == null || !(o instanceof RyaTypeWritable)) {
        return false;
    }
    RyaType rtThis = ryatype;
    RyaType rtOther = ((RyaTypeWritable) o).ryatype;
    if (rtThis == null) {
        return rtOther == null;
    } else {
        return rtThis.equals(rtOther);
    }
}
Also used : RyaType(org.apache.rya.api.domain.RyaType)

Example 23 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class StarQuery method setValue.

private TextColumn setValue(final TextColumn tc, final Value v) throws RyaTypeResolverException {
    final String cq = tc.getColumnQualifier().toString();
    final String[] cqArray = cq.split("\u0000");
    if (cqArray[0].equals("subject")) {
        // RyaURI subjURI = (RyaURI) RdfToRyaConversions.convertValue(v);
        tc.setColumnQualifier(new Text("subject" + "\u0000" + v.stringValue()));
        tc.setIsPrefix(false);
    } else if (cqArray[0].equals("object")) {
        final RyaType objType = RdfToRyaConversions.convertValue(v);
        final byte[][] b1 = RyaContext.getInstance().serializeType(objType);
        final byte[] b2 = Bytes.concat("object".getBytes(StandardCharsets.UTF_8), "\u0000".getBytes(StandardCharsets.UTF_8), b1[0], b1[1]);
        tc.setColumnQualifier(new Text(b2));
        tc.setIsPrefix(false);
    } else {
        throw new IllegalStateException("Invalid direction!");
    }
    return tc;
}
Also used : Text(org.apache.hadoop.io.Text) RyaType(org.apache.rya.api.domain.RyaType)

Example 24 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class StarQuery method nodeToTextColumn.

// assumes nodes forms valid star query with only one common variable
// assumes nodes and commonVar has been set
private TextColumn nodeToTextColumn(final StatementPattern node, final int i) throws RyaTypeResolverException {
    final RyaContext rc = RyaContext.getInstance();
    final Var subjVar = node.getSubjectVar();
    final Var predVar = node.getPredicateVar();
    final Var objVar = node.getObjectVar();
    final RyaURI predURI = (RyaURI) RdfToRyaConversions.convertValue(node.getPredicateVar().getValue());
    // assumes StatementPattern contains at least on variable
    if (subjVar.isConstant()) {
        if (commonVarConstant()) {
            varPos.put(objVar.getName(), i);
            return new TextColumn(new Text(predURI.getData()), new Text("object"));
        } else {
            return new TextColumn(new Text(predURI.getData()), new Text("subject" + "\u0000" + subjVar.getValue().stringValue()));
        }
    } else if (objVar.isConstant()) {
        if (commonVarConstant()) {
            varPos.put(subjVar.getName(), i);
            return new TextColumn(new Text(predURI.getData()), new Text("subject"));
        } else {
            isCommonVarURI = true;
            final RyaType objType = RdfToRyaConversions.convertValue(objVar.getValue());
            final byte[][] b1 = rc.serializeType(objType);
            final byte[] b2 = Bytes.concat("object".getBytes(StandardCharsets.UTF_8), "\u0000".getBytes(StandardCharsets.UTF_8), b1[0], b1[1]);
            return new TextColumn(new Text(predURI.getData()), new Text(b2));
        }
    } else {
        if (subjVar.getName().equals(commonVarName)) {
            isCommonVarURI = true;
            varPos.put(objVar.getName(), i);
            final TextColumn tc = new TextColumn(new Text(predURI.getData()), new Text("object"));
            tc.setIsPrefix(true);
            return tc;
        } else {
            varPos.put(subjVar.getName(), i);
            final TextColumn tc = new TextColumn(new Text(predURI.getData()), new Text("subject"));
            tc.setIsPrefix(true);
            return tc;
        }
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaContext(org.apache.rya.api.resolver.RyaContext) Var(org.openrdf.query.algebra.Var) Text(org.apache.hadoop.io.Text) RyaType(org.apache.rya.api.domain.RyaType) TextColumn(org.apache.rya.accumulo.documentIndex.TextColumn)

Example 25 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class EntityQueryNode method findBindings.

private List<BindingSet> findBindings(final BindingSet bindingSet) throws QueryEvaluationException {
    final MapBindingSet resultSet = new MapBindingSet();
    try {
        final ConvertingCursor<TypedEntity> entitiesCursor;
        final String subj;
        // If the subject needs to be filled in, check if the subject variable is in the binding set.
        if (subjectIsConstant) {
            // if it is, fetch that value and then fetch the entity for the subject.
            subj = subjectConstant.get();
            entitiesCursor = entities.search(Optional.of(new RyaURI(subj)), type, properties);
        } else {
            entitiesCursor = entities.search(Optional.empty(), type, properties);
        }
        while (entitiesCursor.hasNext()) {
            final TypedEntity typedEntity = entitiesCursor.next();
            final ImmutableCollection<Property> properties = typedEntity.getProperties();
            // ensure properties match and only add properties that are in the statement patterns to the binding set
            for (final RyaURI key : objectVariables.keySet()) {
                final Optional<RyaType> prop = typedEntity.getPropertyValue(new RyaURI(key.getData()));
                if (prop.isPresent()) {
                    final RyaType type = prop.get();
                    final String bindingName = objectVariables.get(key).getName();
                    resultSet.addBinding(bindingName, ValueFactoryImpl.getInstance().createLiteral(type.getData()));
                }
            }
        }
    } catch (final EntityStorageException e) {
        throw new QueryEvaluationException("Failed to evaluate the binding set", e);
    }
    bindingSet.forEach(new Consumer<Binding>() {

        @Override
        public void accept(final Binding binding) {
            resultSet.addBinding(binding);
        }
    });
    final List<BindingSet> list = new ArrayList<>();
    list.add(resultSet);
    return list;
}
Also used : Binding(org.openrdf.query.Binding) MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) ArrayList(java.util.ArrayList) RyaType(org.apache.rya.api.domain.RyaType) RyaURI(org.apache.rya.api.domain.RyaURI) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Property(org.apache.rya.indexing.entity.model.Property) EntityStorageException(org.apache.rya.indexing.entity.storage.EntityStorage.EntityStorageException)

Aggregations

RyaType (org.apache.rya.api.domain.RyaType)178 RyaURI (org.apache.rya.api.domain.RyaURI)146 RyaStatement (org.apache.rya.api.domain.RyaStatement)115 Test (org.junit.Test)109 BindingSet (org.openrdf.query.BindingSet)42 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)42 ArrayList (java.util.ArrayList)35 StatementPattern (org.openrdf.query.algebra.StatementPattern)35 ParsedQuery (org.openrdf.query.parser.ParsedQuery)35 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)35 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)34 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)34 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)28 Property (org.apache.rya.indexing.entity.model.Property)23 URIImpl (org.openrdf.model.impl.URIImpl)23 HashSet (java.util.HashSet)22 Entity (org.apache.rya.indexing.entity.model.Entity)20 Value (org.openrdf.model.Value)19 LiteralImpl (org.openrdf.model.impl.LiteralImpl)19 BatchWriter (org.apache.accumulo.core.client.BatchWriter)18