Search in sources :

Example 1 with QueryBindingSet

use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.

the class AccumuloIndexSetColumnVisibilityTest method accumuloIndexSetTestAttemptJoinAccrossTypes.

@Test
public void accumuloIndexSetTestAttemptJoinAccrossTypes() throws Exception {
    // Setup the object that will be tested.
    final String pcjTableName = new PcjTableNameFactory().makeTableName(ryaInstanceName, pcjId);
    final AccumuloIndexSet ais = new AccumuloIndexSet(conf, pcjTableName);
    // Setup the binding sets that will be evaluated.
    final QueryBindingSet bs1 = new QueryBindingSet();
    bs1.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
    final QueryBindingSet bs2 = new QueryBindingSet();
    bs2.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
    final Set<BindingSet> bSets = Sets.<BindingSet>newHashSet(bs1, bs2);
    final CloseableIteration<BindingSet, QueryEvaluationException> results = ais.evaluate(bSets);
    final Set<BindingSet> fetchedResults = new HashSet<>();
    while (results.hasNext()) {
        final BindingSet next = results.next();
        fetchedResults.add(next);
    }
    final Set<BindingSet> expected = Sets.<BindingSet>newHashSet(pcjBs1, pcjBs2);
    assertEquals(expected, fetchedResults);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) PcjTableNameFactory(org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with QueryBindingSet

use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.

the class AccumuloIndexSetColumnVisibilityTest method variableInstantiationTest.

@Test
public void variableInstantiationTest() throws Exception {
    // Setup the object that will be tested.
    final String pcjTableName = new PcjTableNameFactory().makeTableName(ryaInstanceName, pcjId);
    final AccumuloIndexSet ais = new AccumuloIndexSet(conf, pcjTableName);
    // Setup the binding sets that will be evaluated.
    final QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("name", new URIImpl("http://Alice"));
    final QueryBindingSet bs2 = new QueryBindingSet();
    bs2.addBinding("name", new URIImpl("http://Bob"));
    final Set<BindingSet> bSets = Sets.<BindingSet>newHashSet(bs, bs2);
    final CloseableIteration<BindingSet, QueryEvaluationException> results = ais.evaluate(bSets);
    final Set<BindingSet> fetchedResults = new HashSet<>();
    while (results.hasNext()) {
        final BindingSet next = results.next();
        fetchedResults.add(next);
    }
    final Set<BindingSet> expected = Sets.<BindingSet>newHashSet(pcjBs1, pcjBs2);
    assertEquals(expected, fetchedResults);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) URIImpl(org.openrdf.model.impl.URIImpl) PcjTableNameFactory(org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with QueryBindingSet

use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.

the class MongoDbSmartUriIT method testStorage.

@Test
public void testStorage() throws SmartUriException, MalformedQueryException, RuntimeException, QueryEvaluationException {
    smartUriConverter.storeEntity(BOB_ENTITY);
    final String sparql = "SELECT * WHERE { " + "<" + BOB.getData() + "> <" + RDF.TYPE + "> <" + PERSON_TYPE.getId().getData() + "> . " + "<" + BOB.getData() + "> <" + HAS_SSN.getData() + "> ?ssn . " + "<" + BOB.getData() + "> <" + HAS_AGE.getData() + "> ?age . " + "<" + BOB.getData() + "> <" + HAS_WEIGHT.getData() + "> ?weight . " + "<" + BOB.getData() + "> <" + HAS_ADDRESS.getData() + "> ?address . " + "}";
    final StatementPatternCollector spCollector = new StatementPatternCollector();
    new SPARQLParser().parseQuery(sparql, null).getTupleExpr().visit(spCollector);
    final List<StatementPattern> patterns = spCollector.getStatementPatterns();
    final EntityQueryNode entityQueryNode = new EntityQueryNode(PERSON_TYPE, patterns, smartUriConverter.getEntityStorage());
    final QueryBindingSet queryBindingSet = new QueryBindingSet();
    final Property ssnProperty = BOB_ENTITY.lookupTypeProperty(PERSON_TYPE, HAS_SSN).get();
    queryBindingSet.addBinding(HAS_SSN.getData(), RyaToRdfConversions.convertValue(ssnProperty.getValue()));
    final CloseableIteration<BindingSet, QueryEvaluationException> iter = entityQueryNode.evaluate(queryBindingSet);
    int count = 0;
    // These should match what was used in the SPARQL query.
    final List<String> queryParamNames = Lists.newArrayList("ssn", "age", "weight", "address");
    while (iter.hasNext()) {
        final BindingSet bs = iter.next();
        assertTrue(bs.getBindingNames().containsAll(queryParamNames));
        count++;
    }
    assertEquals(count, 1);
}
Also used : StatementPatternCollector(org.openrdf.query.algebra.helpers.StatementPatternCollector) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) EntityQueryNode(org.apache.rya.indexing.entity.query.EntityQueryNode) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 4 with QueryBindingSet

use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.

the class AccumuloDocIndexerTest method testContextCommonVarBs1.

@Test
public void testContextCommonVarBs1() throws Exception {
    BatchWriter bw = null;
    RyaTableMutationsFactory rtm = new RyaTableMutationsFactory(RyaTripleContext.getInstance(conf));
    bw = accCon.createBatchWriter(tableName, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);
    for (int i = 0; i < 30; i++) {
        RyaStatement rs1 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf1"), new RyaURI("uri:cq1"), new RyaURI("uri:joe"));
        RyaStatement rs2 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf2"), new RyaType(XMLSchema.STRING, "cq2"), new RyaURI("uri:joe"));
        RyaStatement rs3 = null;
        RyaStatement rs4 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf1"), new RyaURI("uri:cq1"), new RyaURI("uri:hank"));
        RyaStatement rs5 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf2"), new RyaType(XMLSchema.STRING, "cq2"), new RyaURI("uri:hank"));
        RyaStatement rs6 = null;
        if (i == 5 || i == 10 || i == 15 || i == 20 || i == 25) {
            rs3 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf3"), new RyaType(XMLSchema.INTEGER, Integer.toString(i)), new RyaURI("uri:joe"));
            rs6 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf3"), new RyaType(XMLSchema.INTEGER, Integer.toString(i)), new RyaURI("uri:hank"));
        }
        Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize1 = rtm.serialize(rs1);
        Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize2 = rtm.serialize(rs2);
        Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize3 = null;
        Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize4 = rtm.serialize(rs4);
        Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize5 = rtm.serialize(rs5);
        Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize6 = null;
        if (rs3 != null) {
            serialize3 = rtm.serialize(rs3);
        }
        if (rs6 != null) {
            serialize6 = rtm.serialize(rs6);
        }
        Collection<Mutation> m1 = EntityCentricIndex.createMutations(rs1);
        for (Mutation m : m1) {
            bw.addMutation(m);
        }
        Collection<Mutation> m2 = EntityCentricIndex.createMutations(rs2);
        for (Mutation m : m2) {
            bw.addMutation(m);
        }
        if (serialize3 != null) {
            Collection<Mutation> m3 = EntityCentricIndex.createMutations(rs3);
            for (Mutation m : m3) {
                bw.addMutation(m);
            }
        }
        Collection<Mutation> m4 = EntityCentricIndex.createMutations(rs4);
        for (Mutation m : m4) {
            bw.addMutation(m);
        }
        Collection<Mutation> m5 = EntityCentricIndex.createMutations(rs5);
        for (Mutation m : m5) {
            bw.addMutation(m);
        }
        if (serialize6 != null) {
            Collection<Mutation> m6 = EntityCentricIndex.createMutations(rs6);
            for (Mutation m : m6) {
                bw.addMutation(m);
            }
        }
    }
    String q1 = // 
    "" + // 
    "SELECT ?X ?Y1 ?Y2 ?Y3 " + // 
    "{" + // 
    "?X <uri:cf1> ?Y1 ." + // 
    "?X <uri:cf2> ?Y2 ." + // 
    "?X <uri:cf3> ?Y3 ." + "}";
    String q2 = // 
    "" + // 
    "SELECT ?X ?Y1 ?Y2 ?Y3 " + // 
    "{" + // 
    " GRAPH <uri:hank> { " + // 
    "?X <uri:cf1> ?Y1 ." + // 
    "?X <uri:cf2> ?Y2 ." + // 
    "?X <uri:cf3> ?Y3 ." + // 
    " } " + "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(q1, null);
    TupleExpr te1 = pq1.getTupleExpr();
    List<StatementPattern> spList1 = StatementPatternCollector.process(te1);
    Assert.assertTrue(StarQuery.isValidStarQuery(spList1));
    StarQuery sq1 = new StarQuery(spList1);
    AccumuloDocIdIndexer adi = new AccumuloDocIdIndexer(conf);
    Value v1 = RyaToRdfConversions.convertValue(new RyaType(XMLSchema.INTEGER, Integer.toString(5)));
    Value v2 = RyaToRdfConversions.convertValue(new RyaType(XMLSchema.INTEGER, Integer.toString(25)));
    List<BindingSet> bsList = Lists.newArrayList();
    QueryBindingSet b1 = (new QueryBindingSet());
    b1.addBinding("X", vf.createURI("uri:5"));
    QueryBindingSet b2 = (new QueryBindingSet());
    b2.addBinding("X", vf.createURI("uri:15"));
    QueryBindingSet b3 = (new QueryBindingSet());
    b3.addBinding("X", vf.createURI("uri:25"));
    bsList.add(b1);
    bsList.add(b2);
    bsList.add(b3);
    CloseableIteration<BindingSet, QueryEvaluationException> sol1 = adi.queryDocIndex(sq1, bsList);
    System.out.println("**********************TEST 12***********************");
    int results = 0;
    while (sol1.hasNext()) {
        System.out.println(sol1.next());
        results++;
    }
    Assert.assertEquals(6, results);
    ParsedQuery pq2 = parser.parseQuery(q2, null);
    TupleExpr te2 = pq2.getTupleExpr();
    List<StatementPattern> spList2 = StatementPatternCollector.process(te2);
    Assert.assertTrue(StarQuery.isValidStarQuery(spList2));
    StarQuery sq2 = new StarQuery(spList2);
    CloseableIteration<BindingSet, QueryEvaluationException> sol2 = adi.queryDocIndex(sq2, bsList);
    System.out.println("**********************TEST 12***********************");
    results = 0;
    while (sol2.hasNext()) {
        System.out.println(sol2.next());
        results++;
    }
    Assert.assertEquals(3, results);
    adi.close();
}
Also used : ParsedQuery(org.openrdf.query.parser.ParsedQuery) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) TupleExpr(org.openrdf.query.algebra.TupleExpr) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) RyaURI(org.apache.rya.api.domain.RyaURI) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RyaTableMutationsFactory(org.apache.rya.accumulo.RyaTableMutationsFactory) Value(org.openrdf.model.Value) Collection(java.util.Collection) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Example 5 with QueryBindingSet

use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.

the class AccumuloDocIndexerTest method testNoContextCommonVarBs2.

@Test
public void testNoContextCommonVarBs2() throws Exception {
    BatchWriter bw = null;
    RyaTableMutationsFactory rtm = new RyaTableMutationsFactory(RyaTripleContext.getInstance(conf));
    bw = accCon.createBatchWriter(tableName, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);
    for (int i = 0; i < 30; i++) {
        RyaStatement rs1 = new RyaStatement(new RyaURI("uri:cq1"), new RyaURI("uri:cf1"), new RyaURI("uri:" + i));
        RyaStatement rs2 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf2"), new RyaType(XMLSchema.STRING, "cq2"));
        RyaStatement rs3 = null;
        if (i == 5 || i == 10 || i == 15 || i == 20 || i == 25) {
            rs3 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf3"), new RyaType(XMLSchema.INTEGER, Integer.toString(i)));
        }
        Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize1 = rtm.serialize(rs1);
        Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize2 = rtm.serialize(rs2);
        Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize3 = null;
        if (rs3 != null) {
            serialize3 = rtm.serialize(rs3);
        }
        Collection<Mutation> m1 = EntityCentricIndex.createMutations(rs1);
        for (Mutation m : m1) {
            bw.addMutation(m);
        }
        Collection<Mutation> m2 = EntityCentricIndex.createMutations(rs2);
        for (Mutation m : m2) {
            bw.addMutation(m);
        }
        if (serialize3 != null) {
            Collection<Mutation> m3 = EntityCentricIndex.createMutations(rs3);
            for (Mutation m : m3) {
                bw.addMutation(m);
            }
        }
    }
    String q1 = // 
    "" + // 
    "SELECT ?X ?Y1 ?Y2 ?Y3 " + // 
    "{" + // 
    "?Y1 <uri:cf1> ?X ." + // 
    "?X <uri:cf2> ?Y2 ." + // 
    "?X <uri:cf3> ?Y3 ." + "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(q1, null);
    TupleExpr te1 = pq1.getTupleExpr();
    List<StatementPattern> spList1 = StatementPatternCollector.process(te1);
    Assert.assertTrue(StarQuery.isValidStarQuery(spList1));
    StarQuery sq1 = new StarQuery(spList1);
    AccumuloDocIdIndexer adi = new AccumuloDocIdIndexer(conf);
    List<BindingSet> bsList = Lists.newArrayList();
    QueryBindingSet b1 = (new QueryBindingSet());
    b1.addBinding("X", vf.createURI("uri:5"));
    QueryBindingSet b2 = (new QueryBindingSet());
    b2.addBinding("X", vf.createURI("uri:15"));
    QueryBindingSet b3 = (new QueryBindingSet());
    b3.addBinding("X", vf.createURI("uri:25"));
    bsList.add(b1);
    bsList.add(b2);
    bsList.add(b3);
    CloseableIteration<BindingSet, QueryEvaluationException> sol1 = adi.queryDocIndex(sq1, bsList);
    System.out.println("**********************TEST 5***********************");
    int results = 0;
    while (sol1.hasNext()) {
        System.out.println(sol1.next());
        results++;
    }
    Assert.assertEquals(3, results);
    adi.close();
}
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) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) TupleExpr(org.openrdf.query.algebra.TupleExpr) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) RyaURI(org.apache.rya.api.domain.RyaURI) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RyaTableMutationsFactory(org.apache.rya.accumulo.RyaTableMutationsFactory) Collection(java.util.Collection) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Aggregations

QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)107 Test (org.junit.Test)84 BindingSet (org.openrdf.query.BindingSet)79 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)52 RyaURI (org.apache.rya.api.domain.RyaURI)46 RyaStatement (org.apache.rya.api.domain.RyaStatement)45 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)42 StatementPattern (org.openrdf.query.algebra.StatementPattern)41 ParsedQuery (org.openrdf.query.parser.ParsedQuery)41 RyaType (org.apache.rya.api.domain.RyaType)39 LiteralImpl (org.openrdf.model.impl.LiteralImpl)32 ArrayList (java.util.ArrayList)30 HashSet (java.util.HashSet)28 URIImpl (org.openrdf.model.impl.URIImpl)27 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)26 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)20 StatementMetadataNode (org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode)15 Statement (org.openrdf.model.Statement)15 TupleExpr (org.openrdf.query.algebra.TupleExpr)14 Collection (java.util.Collection)13