Search in sources :

Example 1 with AccumuloIndexSet

use of org.apache.rya.indexing.external.tupleSet.AccumuloIndexSet 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 2 with AccumuloIndexSet

use of org.apache.rya.indexing.external.tupleSet.AccumuloIndexSet 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 3 with AccumuloIndexSet

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

the class AccumuloPcjIT method testSupportedVarOrders1.

@Test
public void testSupportedVarOrders1() throws PcjException, RepositoryException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, MalformedQueryException, SailException, QueryEvaluationException {
    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 . " + // 
    "}";
    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 Set<String> ais1Set1 = Sets.newHashSet();
    ais1Set1.add("dog");
    Assert.assertTrue(ais1.supportsBindingSet(ais1Set1));
    ais1Set1.add("duck");
    Assert.assertTrue(ais1.supportsBindingSet(ais1Set1));
    ais1Set1.add("chicken");
    Assert.assertTrue(ais1.supportsBindingSet(ais1Set1));
    final Set<String> ais2Set1 = Sets.newHashSet();
    ais2Set1.add("f");
    Assert.assertTrue(ais2.supportsBindingSet(ais2Set1));
    ais2Set1.add("e");
    Assert.assertTrue(ais2.supportsBindingSet(ais2Set1));
    ais2Set1.add("o");
    Assert.assertTrue(ais2.supportsBindingSet(ais2Set1));
    ais2Set1.add("l");
    Assert.assertTrue(ais2.supportsBindingSet(ais2Set1));
    final Set<String> ais2Set2 = Sets.newHashSet();
    ais2Set2.add("f");
    Assert.assertTrue(ais2.supportsBindingSet(ais2Set2));
    ais2Set2.add("o");
    Assert.assertTrue(ais2.supportsBindingSet(ais2Set2));
    ais2Set2.add("c");
    Assert.assertTrue(!ais2.supportsBindingSet(ais2Set2));
    final Set<String> ais2Set3 = Sets.newHashSet();
    ais2Set3.add("c");
    Assert.assertTrue(ais2.supportsBindingSet(ais2Set3));
    ais2Set3.add("e");
    Assert.assertTrue(ais2.supportsBindingSet(ais2Set3));
    ais2Set3.add("l");
    Assert.assertTrue(ais2.supportsBindingSet(ais2Set3));
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) AccumuloIndexSet(org.apache.rya.indexing.external.tupleSet.AccumuloIndexSet) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 4 with AccumuloIndexSet

use of org.apache.rya.indexing.external.tupleSet.AccumuloIndexSet 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)

Aggregations

AccumuloIndexSet (org.apache.rya.indexing.external.tupleSet.AccumuloIndexSet)4 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)3 Test (org.junit.Test)3 URI (org.openrdf.model.URI)3 LiteralImpl (org.openrdf.model.impl.LiteralImpl)3 URIImpl (org.openrdf.model.impl.URIImpl)3 ArrayList (java.util.ArrayList)2 IndexPlanValidator (org.apache.rya.indexing.IndexPlanValidator.IndexPlanValidator)2 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)2 AccumuloIndexSetProvider (org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider)2 TupleExpr (org.openrdf.query.algebra.TupleExpr)2 ParsedQuery (org.openrdf.query.parser.ParsedQuery)2 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)2 List (java.util.List)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 Connector (org.apache.accumulo.core.client.Connector)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 RdfCloudTripleStoreConfiguration (org.apache.rya.api.RdfCloudTripleStoreConfiguration)1 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)1