Search in sources :

Example 21 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class AccumuloStatementMetadataNodeTest method simpleQueryWithBindingSetJoinOnProperty.

/**
 * Tests if the StatementMetadataNode joins BindingSet correctly for
 * variables appearing in metadata statements. In this case, the metadata
 * statements are (_:blankNode <http://createdOn 2017-01-04 ) and
 * (_:blankNode <http://createdBy> ?y). The variable ?y appears as the
 * object in the above metadata statement and its values are joined to the
 * constraint BindingSets in the example below.
 *
 * @throws MalformedQueryException
 * @throws QueryEvaluationException
 * @throws RyaDAOException
 */
@Test
public void simpleQueryWithBindingSetJoinOnProperty() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
    StatementMetadata metadata = new StatementMetadata();
    metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe"));
    metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
    RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
    dao.add(statement1);
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
    StatementMetadataNode<AccumuloRdfConfiguration> node = new StatementMetadataNode<>(spList, conf);
    QueryBindingSet bsConstraint = new QueryBindingSet();
    bsConstraint.addBinding("x", new LiteralImpl("CoffeeShop"));
    bsConstraint.addBinding("y", new LiteralImpl("Doug"));
    CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsConstraint);
    List<BindingSet> bsList = new ArrayList<>();
    while (iteration.hasNext()) {
        bsList.add(iteration.next());
    }
    Assert.assertEquals(0, bsList.size());
    dao.delete(statement1, conf);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) RyaURI(org.apache.rya.api.domain.RyaURI) StatementPattern(org.openrdf.query.algebra.StatementPattern) StatementMetadataNode(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode) LiteralImpl(org.openrdf.model.impl.LiteralImpl) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Test(org.junit.Test)

Example 22 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class AccumuloStatementMetadataNodeTest method simpleQueryWithBindingSet.

@Test
public void simpleQueryWithBindingSet() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
    StatementMetadata metadata = new StatementMetadata();
    metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe"));
    metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
    RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
    RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("HardwareStore"), new RyaURI("http://context"), "", metadata);
    dao.add(statement1);
    dao.add(statement2);
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
    StatementMetadataNode<AccumuloRdfConfiguration> node = new StatementMetadataNode<>(spList, conf);
    QueryBindingSet bsConstraint = new QueryBindingSet();
    bsConstraint.addBinding("x", new LiteralImpl("CoffeeShop"));
    bsConstraint.addBinding("z", new LiteralImpl("Virginia"));
    CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsConstraint);
    QueryBindingSet expected = new QueryBindingSet();
    expected.addBinding("x", new LiteralImpl("CoffeeShop"));
    expected.addBinding("y", new LiteralImpl("Joe"));
    expected.addBinding("z", new LiteralImpl("Virginia"));
    List<BindingSet> bsList = new ArrayList<>();
    while (iteration.hasNext()) {
        bsList.add(iteration.next());
    }
    Assert.assertEquals(1, bsList.size());
    Assert.assertEquals(expected, bsList.get(0));
    dao.delete(statement1, conf);
    dao.delete(statement2, conf);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) RyaURI(org.apache.rya.api.domain.RyaURI) StatementPattern(org.openrdf.query.algebra.StatementPattern) StatementMetadataNode(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode) LiteralImpl(org.openrdf.model.impl.LiteralImpl) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Test(org.junit.Test)

Example 23 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class AccumuloStatementMetadataNodeTest method simpleQueryWithConstantContext.

/**
 * Tests if StatementMetadataNode joins BindingSet values correctly for
 * variables appearing as the object in one of the StatementPattern
 * statements (in the case ?x appears as the Object in the statement
 * _:blankNode rdf:object ?x). StatementPattern statements have either
 * rdf:subject, rdf:predicate, or rdf:object as the predicate. Additionally,
 * this test also determines whether node uses specified context as a query
 * constraint.
 *
 * @throws MalformedQueryException
 * @throws QueryEvaluationException
 * @throws RyaDAOException
 */
@Test
public void simpleQueryWithConstantContext() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
    // query used to create StatementPatternMetadataNode
    String contextQuery = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where { graph <http://context_1> {_:blankNode rdf:type owl:Annotation; owl:annotatedSource <http://Joe>; " + "owl:annotatedProperty <http://worksAt>; owl:annotatedTarget ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }}";
    StatementMetadata metadata = new StatementMetadata();
    metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe"));
    metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
    RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context_1"), "", metadata);
    RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("HardwareStore"), new RyaURI("http://context_2"), "", metadata);
    dao.add(statement1);
    dao.add(statement2);
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(contextQuery, null);
    List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
    StatementMetadataNode<AccumuloRdfConfiguration> node = new StatementMetadataNode<>(spList, conf);
    List<BindingSet> bsCollection = new ArrayList<>();
    QueryBindingSet bsConstraint1 = new QueryBindingSet();
    bsConstraint1.addBinding("x", new LiteralImpl("CoffeeShop"));
    bsConstraint1.addBinding("z", new LiteralImpl("Virginia"));
    QueryBindingSet bsConstraint2 = new QueryBindingSet();
    bsConstraint2.addBinding("x", new LiteralImpl("HardwareStore"));
    bsConstraint2.addBinding("z", new LiteralImpl("Maryland"));
    QueryBindingSet bsConstraint3 = new QueryBindingSet();
    bsConstraint3.addBinding("x", new LiteralImpl("BurgerShack"));
    bsConstraint3.addBinding("z", new LiteralImpl("Delaware"));
    bsCollection.add(bsConstraint1);
    bsCollection.add(bsConstraint2);
    bsCollection.add(bsConstraint3);
    CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsCollection);
    QueryBindingSet expected1 = new QueryBindingSet();
    expected1.addBinding("x", new LiteralImpl("CoffeeShop"));
    expected1.addBinding("y", new LiteralImpl("Joe"));
    expected1.addBinding("z", new LiteralImpl("Virginia"));
    List<BindingSet> bsList = new ArrayList<>();
    while (iteration.hasNext()) {
        bsList.add(iteration.next());
    }
    Assert.assertEquals(1, bsList.size());
    Assert.assertEquals(expected1, bsList.get(0));
    dao.delete(statement1, conf);
    dao.delete(statement2, conf);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) RyaURI(org.apache.rya.api.domain.RyaURI) StatementPattern(org.openrdf.query.algebra.StatementPattern) StatementMetadataNode(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode) LiteralImpl(org.openrdf.model.impl.LiteralImpl) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Test(org.junit.Test)

Example 24 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class AccumuloStatementMetadataNodeTest method getConf.

private static AccumuloRdfConfiguration getConf() {
    final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, true);
    conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya_");
    conf.set(ConfigUtils.CLOUDBASE_USER, "root");
    conf.set(ConfigUtils.CLOUDBASE_PASSWORD, "");
    conf.set(ConfigUtils.CLOUDBASE_INSTANCE, "instance");
    conf.set(ConfigUtils.CLOUDBASE_AUTHS, "");
    return conf;
}
Also used : AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration)

Example 25 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class StatementMetadataExternalSetProviderTest method createSingleAccumuloMetadataNode.

@Test
public void createSingleAccumuloMetadataNode() throws MalformedQueryException {
    AccumuloRdfConfiguration conf = (AccumuloRdfConfiguration) getConf(false);
    Set<RyaURI> propertySet = new HashSet<>();
    propertySet.add(new RyaURI("http://createdBy"));
    conf.setStatementMetadataProperties(propertySet);
    StatementMetadataExternalSetProvider metaProvider = new StatementMetadataExternalSetProvider(conf);
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<QueryModelNode> patterns = new ArrayList<>();
    List<StatementMetadataNode<?>> expected = new ArrayList<>();
    Set<StatementPattern> sp = StatementMetadataTestUtils.getMetadataStatementPatterns(pq.getTupleExpr(), propertySet);
    patterns.addAll(StatementPatternCollector.process(pq.getTupleExpr()));
    JoinSegment<StatementMetadataNode<?>> segment = new JoinSegment<>(new HashSet<>(patterns), patterns, new HashMap<ValueExpr, Filter>());
    List<StatementMetadataNode<?>> extSets = metaProvider.getExternalSets(segment);
    expected.add(new StatementMetadataNode<>(sp, conf));
    Assert.assertEquals(expected, extSets);
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) JoinSegment(org.apache.rya.indexing.external.matching.JoinSegment) StatementMetadataExternalSetProvider(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataExternalSetProvider) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) RyaURI(org.apache.rya.api.domain.RyaURI) StatementMetadataNode(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode) StatementPattern(org.openrdf.query.algebra.StatementPattern) Filter(org.openrdf.query.algebra.Filter) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)108 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)26 AccumuloRyaDAO (org.apache.rya.accumulo.AccumuloRyaDAO)25 Test (org.junit.Test)24 RyaURI (org.apache.rya.api.domain.RyaURI)22 Connector (org.apache.accumulo.core.client.Connector)21 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)20 RyaStatement (org.apache.rya.api.domain.RyaStatement)20 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)15 Sail (org.openrdf.sail.Sail)15 RyaType (org.apache.rya.api.domain.RyaType)14 StatementPattern (org.openrdf.query.algebra.StatementPattern)14 AccumuloException (org.apache.accumulo.core.client.AccumuloException)13 Before (org.junit.Before)13 ArrayList (java.util.ArrayList)12 RdfCloudTripleStore (org.apache.rya.rdftriplestore.RdfCloudTripleStore)12 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)11 LiteralImpl (org.openrdf.model.impl.LiteralImpl)10 BindingSet (org.openrdf.query.BindingSet)10 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)10