Search in sources :

Example 76 with ExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.

the class MongoPcjIndexSetProvider method getIndices.

@Override
protected List<ExternalTupleSet> getIndices() throws PcjIndexSetException {
    try {
        final StatefulMongoDBRdfConfiguration mongoConf = (StatefulMongoDBRdfConfiguration) conf;
        final MongoClient client = mongoConf.getMongoClient();
        final MongoPcjDocuments pcjDocs = new MongoPcjDocuments(client, mongoConf.getRyaInstanceName());
        List<String> documents = null;
        documents = mongoConf.getPcjTables();
        // this maps associates pcj document name with pcj sparql query
        final Map<String, String> indexDocuments = Maps.newLinkedHashMap();
        try (final PrecomputedJoinStorage storage = new MongoPcjStorage(client, mongoConf.getRyaInstanceName())) {
            final boolean docsProvided = documents != null && !documents.isEmpty();
            if (docsProvided) {
                // if tables provided, associate table name with sparql
                for (final String doc : documents) {
                    indexDocuments.put(doc, storage.getPcjMetadata(doc).getSparql());
                }
            } else if (hasRyaDetails()) {
                // If this is a newer install of Rya, and it has PCJ Details, then
                // use those.
                final List<String> ids = storage.listPcjs();
                for (final String pcjId : ids) {
                    indexDocuments.put(pcjId, storage.getPcjMetadata(pcjId).getSparql());
                }
            } else {
                // Otherwise figure it out by getting document IDs.
                documents = pcjDocs.listPcjDocuments();
                for (final String pcjId : documents) {
                    if (pcjId.startsWith("INDEX")) {
                        indexDocuments.put(pcjId, pcjDocs.getPcjMetadata(pcjId).getSparql());
                    }
                }
            }
        }
        final List<ExternalTupleSet> index = Lists.newArrayList();
        if (indexDocuments.isEmpty()) {
            log.info("No Index found");
        } else {
            for (final String pcjID : indexDocuments.keySet()) {
                final String indexSparqlString = indexDocuments.get(pcjID);
                index.add(new MongoPcjQueryNode(indexSparqlString, pcjID, pcjDocs));
            }
        }
        return index;
    } catch (final PCJStorageException | MalformedQueryException e) {
        throw new PcjIndexSetException("Failed to get indicies for this PCJ index.", e);
    }
}
Also used : StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MongoPcjDocuments(org.apache.rya.indexing.pcj.storage.mongo.MongoPcjDocuments) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) MongoPcjStorage(org.apache.rya.indexing.pcj.storage.mongo.MongoPcjStorage) MongoClient(com.mongodb.MongoClient) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MalformedQueryException(org.openrdf.query.MalformedQueryException) List(java.util.List) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)

Example 77 with ExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.

the class AbstractPcjIndexSetProvider method getExternalSets.

/**
 * @param segment - QuerySegment used to get relevant queries form index cache for matching
 * @return List of PCJs for matching
 */
@Override
public List<ExternalTupleSet> getExternalSets(final QuerySegment<ExternalTupleSet> segment) {
    try {
        if (!init) {
            indexCache = PCJOptimizerUtilities.getValidPCJs(getIndices());
            init = true;
        }
        final TupleExpr query = segment.getQuery().getTupleExpr();
        final IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(query, indexCache);
        final List<ExternalTupleSet> pcjs = iep.getNormalizedIndices();
        final List<ExternalTupleSet> tuples = new ArrayList<>();
        for (final ExternalTupleSet tuple : pcjs) {
            final QuerySegment<ExternalTupleSet> pcj = converter.setToSegment(tuple);
            if (segment.containsQuerySegment(pcj)) {
                tuples.add(tuple);
            }
        }
        return tuples;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) IndexedExecutionPlanGenerator(org.apache.rya.indexing.IndexPlanValidator.IndexedExecutionPlanGenerator) TupleExpr(org.openrdf.query.algebra.TupleExpr) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)

Example 78 with ExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.

the class AccumuloPcjIT method testEvaluateTwoIndexValidate.

@Test
public void testEvaluateTwoIndexValidate() throws Exception {
    final URI superclass = new URIImpl("uri:superclass");
    final URI superclass2 = new URIImpl("uri:superclass2");
    conn.add(subclass, RDF.TYPE, superclass);
    conn.add(subclass2, RDF.TYPE, superclass2);
    conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
    conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
    conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
    conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
    final String indexSparqlString = // 
    "" + // 
    "SELECT ?dog ?pig ?duck  " + // 
    "{" + // 
    "  ?pig a ?dog . " + // 
    "  ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck " + // 
    "}";
    final String indexSparqlString2 = // 
    "" + // 
    "SELECT ?o ?f ?e ?c ?l  " + // 
    "{" + // 
    "  ?e <uri:talksTo> ?o . " + // 
    "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
    "  ?c a ?f . " + // 
    "}";
    final String queryString = // 
    "" + // 
    "SELECT ?e ?c ?l ?f ?o " + // 
    "{" + // 
    "  ?e a ?c . " + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
    "  ?e <uri:talksTo> ?o . " + // 
    "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
    "  ?c a ?f . " + // 
    "}";
    PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 1, indexSparqlString, new String[] { "dog", "pig", "duck" }, Optional.<PcjVarOrderFactory>absent());
    final AccumuloIndexSet ais1 = new AccumuloIndexSet(conf, tablename + 1);
    PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 2, indexSparqlString2, new String[] { "o", "f", "e", "c", "l" }, Optional.<PcjVarOrderFactory>absent());
    final AccumuloIndexSet ais2 = new AccumuloIndexSet(conf, tablename + 2);
    final List<ExternalTupleSet> index = new ArrayList<>();
    index.add(ais1);
    index.add(ais2);
    ParsedQuery pq = null;
    final SPARQLParser sp = new SPARQLParser();
    pq = sp.parseQuery(queryString, null);
    final List<TupleExpr> teList = Lists.newArrayList();
    final TupleExpr te = pq.getTupleExpr();
    final PCJOptimizer pcj = new PCJOptimizer(index, false, new AccumuloIndexSetProvider(conf));
    pcj.optimize(te, null, null);
    teList.add(te);
    final IndexPlanValidator ipv = new IndexPlanValidator(false);
    Assert.assertTrue(ipv.isValid(te));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) AccumuloIndexSet(org.apache.rya.indexing.external.tupleSet.AccumuloIndexSet) ParsedQuery(org.openrdf.query.parser.ParsedQuery) AccumuloIndexSetProvider(org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider) ArrayList(java.util.ArrayList) IndexPlanValidator(org.apache.rya.indexing.IndexPlanValidator.IndexPlanValidator) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) TupleExpr(org.openrdf.query.algebra.TupleExpr) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Test(org.junit.Test)

Example 79 with ExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.

the class PrecompJoinOptimizerTest method testSixIndex.

@Test
public void testSixIndex() throws Exception {
    final String q1 = // 
    "" + // 
    "SELECT ?f ?m ?d ?h ?i " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "  ?d <uri:hangOutWith> ?f ." + // 
    "  ?f <uri:hangOutWith> ?h ." + // 
    "  ?f <uri:associatesWith> ?i ." + // 
    "  ?i <uri:associatesWith> ?h ." + // 
    "}";
    final String q2 = // 
    "" + // 
    "SELECT ?t ?s ?u " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    final String q3 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s <uri:hangOutWith> ?t ." + // 
    "  ?t <uri:hangOutWith> ?u ." + // 
    "}";
    final String q4 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s <uri:associatesWith> ?t ." + // 
    "  ?t <uri:associatesWith> ?u ." + // 
    "}";
    final String q5 = // 
    "" + // 
    "SELECT ?m ?f ?d " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "}";
    final String q6 = // 
    "" + // 
    "SELECT ?d ?f ?h " + // 
    "{" + // 
    "  ?d <uri:hangOutWith> ?f ." + // 
    "  ?f <uri:hangOutWith> ?h ." + // 
    "}";
    final String q7 = // 
    "" + // 
    "SELECT ?f ?i ?h " + // 
    "{" + // 
    "  ?f <uri:associatesWith> ?i ." + // 
    "  ?i <uri:associatesWith> ?h ." + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(q1, null);
    final ParsedQuery pq2 = parser.parseQuery(q2, null);
    final ParsedQuery pq3 = parser.parseQuery(q3, null);
    final ParsedQuery pq4 = parser.parseQuery(q4, null);
    final ParsedQuery pq5 = parser.parseQuery(q5, null);
    final ParsedQuery pq6 = parser.parseQuery(q6, null);
    final ParsedQuery pq7 = parser.parseQuery(q7, null);
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
    final SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr());
    final SimpleExternalTupleSet extTup4 = new SimpleExternalTupleSet((Projection) pq5.getTupleExpr());
    final SimpleExternalTupleSet extTup5 = new SimpleExternalTupleSet((Projection) pq6.getTupleExpr());
    final SimpleExternalTupleSet extTup6 = new SimpleExternalTupleSet((Projection) pq7.getTupleExpr());
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup2);
    list.add(extTup1);
    list.add(extTup3);
    final List<QueryModelNode> optTupNodes = Lists.newArrayList();
    optTupNodes.add(extTup4);
    optTupNodes.add(extTup6);
    optTupNodes.add(extTup5);
    provider.setIndices(list);
    final PCJOptimizer pcj = new PCJOptimizer(list, true, provider);
    final TupleExpr te = pq1.getTupleExpr();
    pcj.optimize(te, null, null);
    System.out.println(te);
    final NodeCollector nc = new NodeCollector();
    te.visit(nc);
    Assert.assertEquals(nc.qNodes, Sets.newHashSet(optTupNodes));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) Test(org.junit.Test)

Example 80 with ExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.

the class PrecompJoinOptimizerTest method testThreeIndex2.

@Test
public void testThreeIndex2() throws Exception {
    final String q1 = // 
    "" + // 
    "SELECT ?f ?m ?d ?e ?l ?c " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?c a ?l ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "  ?e <uri:talksTo> ?c . " + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?l <http://www.w3.org/2000/01/rdf-schema#label> ?e ." + // 
    "  ?m <uri:talksTo> ?e . " + // 
    "}";
    final String q2 = // 
    "" + // 
    "SELECT ?u ?s ?t " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    final String q3 = // 
    "" + // 
    "SELECT ?e ?c ?l " + // 
    "{" + // 
    "  ?c a ?l ." + // 
    "  ?l <http://www.w3.org/2000/01/rdf-schema#label> ?e ." + // 
    "  ?e <uri:talksTo> ?c . " + // 
    "}";
    final String q4 = // 
    "" + // 
    "SELECT ?d ?f ?m " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(q1, null);
    final ParsedQuery pq2 = parser.parseQuery(q2, null);
    final ParsedQuery pq3 = parser.parseQuery(q3, null);
    final ParsedQuery pq4 = parser.parseQuery(q4, null);
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
    final SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr());
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    final List<StatementPattern> spList = StatementPatternCollector.process(pq1.getTupleExpr());
    final List<QueryModelNode> optTupNodes = Lists.newArrayList();
    optTupNodes.add(extTup3);
    optTupNodes.add(spList.get(6));
    optTupNodes.add(extTup2);
    provider.setIndices(list);
    final PCJOptimizer pcj = new PCJOptimizer(list, true, provider);
    final TupleExpr te = pq1.getTupleExpr();
    pcj.optimize(te, null, null);
    final NodeCollector nc = new NodeCollector();
    te.visit(nc);
    Assert.assertEquals(nc.qNodes, Sets.newHashSet(optTupNodes));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) StatementPattern(org.openrdf.query.algebra.StatementPattern) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Test(org.junit.Test)

Aggregations

ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)107 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)99 Test (org.junit.Test)97 ParsedQuery (org.openrdf.query.parser.ParsedQuery)97 TupleExpr (org.openrdf.query.algebra.TupleExpr)92 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)86 ArrayList (java.util.ArrayList)73 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)56 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)46 Projection (org.openrdf.query.algebra.Projection)27 StatementPattern (org.openrdf.query.algebra.StatementPattern)23 HashSet (java.util.HashSet)19 Join (org.openrdf.query.algebra.Join)14 LeftJoin (org.openrdf.query.algebra.LeftJoin)14 AccumuloIndexSetProvider (org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider)12 Configuration (org.apache.hadoop.conf.Configuration)10 QueryNodeConsolidator (org.apache.rya.indexing.external.matching.QueryNodeConsolidator)10 List (java.util.List)9 MalformedQueryException (org.openrdf.query.MalformedQueryException)7 Filter (org.openrdf.query.algebra.Filter)6