Search in sources :

Example 26 with ExternalTupleSet

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

the class IndexedExecutionPlanGeneratorTest method testTwoIndexLargeQuery.

@Test
public void testTwoIndexLargeQuery() throws Exception {
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(q15, null);
    ParsedQuery pq2 = parser.parseQuery(q7, null);
    ParsedQuery pq3 = parser.parseQuery(q12, null);
    SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
    List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup2);
    list.add(extTup1);
    IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
    List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
    Assert.assertEquals(4, indexSet.size());
    Iterator<TupleExpr> processedTups = iep.getIndexedTuples();
    int size = 0;
    while (processedTups.hasNext()) {
        Assert.assertTrue(processedTups.hasNext());
        processedTups.next();
        size++;
    }
    Assert.assertTrue(!processedTups.hasNext());
    Assert.assertEquals(5, size);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) TupleExpr(org.openrdf.query.algebra.TupleExpr) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) Test(org.junit.Test)

Example 27 with ExternalTupleSet

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

the class ValidIndexCombinationGeneratorTest method medQueryEightOverlapIndex.

@Test
public void medQueryEightOverlapIndex() {
    String q1 = // 
    "" + // 
    "SELECT ?f ?m ?d " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "  ?f <uri:hangOutWith> ?m ." + // 
    "  ?m <uri:hangOutWith> ?d ." + // 
    "  ?f <uri:associatesWith> ?m ." + // 
    "  ?m <uri:associatesWith> ?d ." + // 
    "}";
    String q2 = // 
    "" + // 
    "SELECT ?t ?s ?u " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    String q3 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s <uri:hangOutWith> ?t ." + // 
    "  ?t <uri:hangOutWith> ?u ." + // 
    "}";
    String q4 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s <uri:associatesWith> ?t ." + // 
    "  ?t <uri:associatesWith> ?u ." + // 
    "}";
    String q5 = // 
    "" + // 
    "SELECT ?t ?s ?u " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "  ?s <uri:hangOutWith> ?t ." + // 
    "  ?t <uri:hangOutWith> ?u ." + // 
    "}";
    String q6 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s <uri:associatesWith> ?t ." + // 
    "  ?t <uri:associatesWith> ?u ." + // 
    "  ?s <uri:hangOutWith> ?t ." + // 
    "  ?t <uri:hangOutWith> ?u ." + // 
    "}";
    String q7 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s <uri:associatesWith> ?t ." + // 
    "  ?t <uri:associatesWith> ?u ." + // 
    "  ?t <uri:hangOutWith> ?u ." + // 
    "}";
    String q8 = // 
    "" + // 
    "SELECT ?t ?s ?u " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "  ?s <uri:associatesWith> ?t ." + // 
    "}";
    String q9 = // 
    "" + // 
    "SELECT ?t ?s ?u " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = null;
    ParsedQuery pq2 = null;
    ParsedQuery pq3 = null;
    ParsedQuery pq4 = null;
    ParsedQuery pq5 = null;
    ParsedQuery pq6 = null;
    ParsedQuery pq7 = null;
    ParsedQuery pq8 = null;
    ParsedQuery pq9 = null;
    SimpleExternalTupleSet extTup1 = null;
    SimpleExternalTupleSet extTup2 = null;
    SimpleExternalTupleSet extTup3 = null;
    SimpleExternalTupleSet extTup4 = null;
    SimpleExternalTupleSet extTup5 = null;
    SimpleExternalTupleSet extTup6 = null;
    SimpleExternalTupleSet extTup7 = null;
    SimpleExternalTupleSet extTup8 = null;
    try {
        pq1 = parser.parseQuery(q1, null);
        pq2 = parser.parseQuery(q2, null);
        pq3 = parser.parseQuery(q3, null);
        pq4 = parser.parseQuery(q4, null);
        pq5 = parser.parseQuery(q5, null);
        pq6 = parser.parseQuery(q6, null);
        pq7 = parser.parseQuery(q7, null);
        pq8 = parser.parseQuery(q8, null);
        pq9 = parser.parseQuery(q9, null);
        extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
        extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
        extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr());
        extTup4 = new SimpleExternalTupleSet((Projection) pq5.getTupleExpr());
        extTup5 = new SimpleExternalTupleSet((Projection) pq6.getTupleExpr());
        extTup6 = new SimpleExternalTupleSet((Projection) pq7.getTupleExpr());
        extTup7 = new SimpleExternalTupleSet((Projection) pq8.getTupleExpr());
        extTup8 = new SimpleExternalTupleSet((Projection) pq9.getTupleExpr());
    } catch (MalformedQueryException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    List<ExternalTupleSet> indexList = Lists.newArrayList();
    indexList.add(extTup1);
    indexList.add(extTup2);
    indexList.add(extTup3);
    indexList.add(extTup4);
    indexList.add(extTup5);
    indexList.add(extTup6);
    indexList.add(extTup7);
    indexList.add(extTup8);
    ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator(pq1.getTupleExpr());
    Iterator<List<ExternalTupleSet>> combos = vic.getValidIndexCombos(indexList);
    int size = 0;
    while (combos.hasNext()) {
        combos.hasNext();
        size++;
        combos.next();
        combos.hasNext();
    }
    Assert.assertTrue(!combos.hasNext());
    Assert.assertEquals(21, size);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Projection(org.openrdf.query.algebra.Projection) MalformedQueryException(org.openrdf.query.MalformedQueryException) List(java.util.List) ArrayList(java.util.ArrayList) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) Test(org.junit.Test)

Example 28 with ExternalTupleSet

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

the class AccumuloIndexSetProvider method getIndices.

@Override
protected List<ExternalTupleSet> getIndices() throws PcjIndexSetException {
    requireNonNull(conf);
    try {
        final String tablePrefix = requireNonNull(conf.get(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX));
        final Connector conn = requireNonNull(ConfigUtils.getConnector(conf));
        List<String> tables = null;
        if (conf instanceof RdfCloudTripleStoreConfiguration) {
            tables = ((RdfCloudTripleStoreConfiguration) conf).getPcjTables();
        }
        // this maps associates pcj table name with pcj sparql query
        final Map<String, String> indexTables = Maps.newLinkedHashMap();
        try (final PrecomputedJoinStorage storage = new AccumuloPcjStorage(conn, tablePrefix)) {
            final PcjTableNameFactory pcjFactory = new PcjTableNameFactory();
            final boolean tablesProvided = tables != null && !tables.isEmpty();
            if (tablesProvided) {
                // if tables provided, associate table name with sparql
                for (final String table : tables) {
                    indexTables.put(table, storage.getPcjMetadata(pcjFactory.getPcjId(table)).getSparql());
                }
            } else if (hasRyaDetails(tablePrefix, conn)) {
                // 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 id : ids) {
                    indexTables.put(pcjFactory.makeTableName(tablePrefix, id), storage.getPcjMetadata(id).getSparql());
                }
            } else {
                // Otherwise figure it out by scanning tables.
                final PcjTables pcjTables = new PcjTables();
                for (final String table : conn.tableOperations().list()) {
                    if (table.startsWith(tablePrefix + "INDEX")) {
                        indexTables.put(table, pcjTables.getPcjMetadata(conn, table).getSparql());
                    }
                }
            }
        }
        // use table name sparql map (indexTables) to create {@link
        // AccumuloIndexSet}
        final List<ExternalTupleSet> index = Lists.newArrayList();
        if (indexTables.isEmpty()) {
            log.info("No Index found");
        } else {
            for (final String table : indexTables.keySet()) {
                final String indexSparqlString = indexTables.get(table);
                index.add(new AccumuloIndexSet(indexSparqlString, conf, table));
            }
        }
        return index;
    } catch (final PCJStorageException | AccumuloException | AccumuloSecurityException | MalformedQueryException | SailException | QueryEvaluationException | TableNotFoundException e) {
        throw new PcjIndexSetException("Failed to retrieve the indicies.", e);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) AccumuloIndexSet(org.apache.rya.indexing.external.tupleSet.AccumuloIndexSet) PcjTableNameFactory(org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory) SailException(org.openrdf.sail.SailException) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MalformedQueryException(org.openrdf.query.MalformedQueryException) List(java.util.List) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PcjTables(org.apache.rya.indexing.pcj.storage.accumulo.PcjTables) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException) RdfCloudTripleStoreConfiguration(org.apache.rya.api.RdfCloudTripleStoreConfiguration)

Example 29 with ExternalTupleSet

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

the class AccumuloPcjIT method testEvaluateThreeIndexValidate.

@Test
public void testEvaluateThreeIndexValidate() throws Exception {
    final URI superclass = new URIImpl("uri:superclass");
    final URI superclass2 = new URIImpl("uri:superclass2");
    final URI sub = new URIImpl("uri:entity");
    subclass = new URIImpl("uri:class");
    obj = new URIImpl("uri:obj");
    talksTo = new URIImpl("uri:talksTo");
    final URI howlsAt = new URIImpl("uri:howlsAt");
    final URI subType = new URIImpl("uri:subType");
    final URI superSuperclass = new URIImpl("uri:super_superclass");
    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(sub, howlsAt, superclass);
    conn.add(superclass, subType, superSuperclass);
    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 indexSparqlString3 = // 
    "" + // 
    "SELECT ?wolf ?sheep ?chicken  " + // 
    "{" + // 
    "  ?wolf <uri:howlsAt> ?sheep . " + // 
    "  ?sheep <uri:subType> ?chicken. " + // 
    "}";
    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 . " + // 
    "  ?e <uri:howlsAt> ?f. " + // 
    "  ?f <uri:subType> ?o. " + // 
    "}";
    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);
    PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 3, indexSparqlString3, new String[] { "wolf", "sheep", "chicken" }, Optional.<PcjVarOrderFactory>absent());
    final AccumuloIndexSet ais3 = new AccumuloIndexSet(conf, tablename + 3);
    final List<ExternalTupleSet> index = new ArrayList<>();
    index.add(ais1);
    index.add(ais3);
    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 30 with ExternalTupleSet

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

the class PrecompJoinOptimizerTest method testThreeIndex.

@Test
public void testThreeIndex() throws Exception {
    final String q7 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    final String q8 = // 
    "" + // 
    "SELECT ?e ?l ?c " + // 
    "{" + // 
    "  ?e a ?l ." + // 
    "  ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + // 
    "  ?c <uri:talksTo> ?e . " + // 
    "}";
    final String q9 = // 
    "" + // 
    "SELECT ?f ?m ?d " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "}";
    final String q15 = // 
    "" + // 
    "SELECT ?f ?m ?d ?e ?l ?c " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?e a ?l ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "  ?c <uri:talksTo> ?e . " + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(q15, null);
    final ParsedQuery pq2 = parser.parseQuery(q7, null);
    final ParsedQuery pq3 = parser.parseQuery(q8, null);
    final ParsedQuery pq4 = parser.parseQuery(q9, 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<QueryModelNode> optTupNodes = Lists.newArrayList();
    optTupNodes.add(extTup2);
    optTupNodes.add(extTup3);
    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.size(), optTupNodes.size());
    for (final QueryModelNode node : nc.qNodes) {
        Assert.assertTrue(optTupNodes.contains(node));
    }
}
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)

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