Search in sources :

Example 71 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class MergeJoinTest method testMergeJoinMultiWayNone.

@Test
public void testMergeJoinMultiWayNone() throws Exception {
    // add data
    RyaURI pred = new RyaURI(litdupsNS, "pred1");
    RyaType zero = new RyaType("0");
    RyaType one = new RyaType("1");
    RyaType two = new RyaType("2");
    RyaType three = new RyaType("3");
    RyaType four = new RyaType("4");
    RyaURI subj1 = new RyaURI(litdupsNS, "subj1");
    RyaURI subj2 = new RyaURI(litdupsNS, "subj2");
    RyaURI subj3 = new RyaURI(litdupsNS, "subj3");
    RyaURI subj4 = new RyaURI(litdupsNS, "subj4");
    dao.add(new RyaStatement(subj1, pred, one));
    dao.add(new RyaStatement(subj1, pred, three));
    dao.add(new RyaStatement(subj1, pred, four));
    dao.add(new RyaStatement(subj2, pred, zero));
    dao.add(new RyaStatement(subj2, pred, one));
    dao.add(new RyaStatement(subj2, pred, four));
    dao.add(new RyaStatement(subj3, pred, two));
    dao.add(new RyaStatement(subj3, pred, four));
    dao.add(new RyaStatement(subj4, pred, one));
    dao.add(new RyaStatement(subj4, pred, two));
    dao.add(new RyaStatement(subj4, pred, three));
    // 1 join
    MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine());
    CloseableIteration<RyaURI, RyaDAOException> join = mergeJoin.join(null, new CustomEntry<RyaURI, RyaType>(pred, one), new CustomEntry<RyaURI, RyaType>(pred, two), new CustomEntry<RyaURI, RyaType>(pred, three), new CustomEntry<RyaURI, RyaType>(pred, four));
    assertFalse(join.hasNext());
    join.close();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MergeJoin(org.apache.rya.api.persist.query.join.MergeJoin) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

Example 72 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class MergeJoinTest method testMergeJoinMultiWay.

@Test
public void testMergeJoinMultiWay() throws Exception {
    // add data
    RyaURI pred = new RyaURI(litdupsNS, "pred1");
    RyaType zero = new RyaType("0");
    RyaType one = new RyaType("1");
    RyaType two = new RyaType("2");
    RyaType three = new RyaType("3");
    RyaType four = new RyaType("4");
    RyaURI subj1 = new RyaURI(litdupsNS, "subj1");
    RyaURI subj2 = new RyaURI(litdupsNS, "subj2");
    RyaURI subj3 = new RyaURI(litdupsNS, "subj3");
    RyaURI subj4 = new RyaURI(litdupsNS, "subj4");
    dao.add(new RyaStatement(subj1, pred, one));
    dao.add(new RyaStatement(subj1, pred, two));
    dao.add(new RyaStatement(subj1, pred, three));
    dao.add(new RyaStatement(subj1, pred, four));
    dao.add(new RyaStatement(subj2, pred, zero));
    dao.add(new RyaStatement(subj2, pred, one));
    dao.add(new RyaStatement(subj2, pred, two));
    dao.add(new RyaStatement(subj2, pred, three));
    dao.add(new RyaStatement(subj2, pred, four));
    dao.add(new RyaStatement(subj3, pred, one));
    dao.add(new RyaStatement(subj3, pred, two));
    dao.add(new RyaStatement(subj3, pred, four));
    dao.add(new RyaStatement(subj4, pred, one));
    dao.add(new RyaStatement(subj4, pred, two));
    dao.add(new RyaStatement(subj4, pred, three));
    dao.add(new RyaStatement(subj4, pred, four));
    // 1 join
    MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine());
    CloseableIteration<RyaURI, RyaDAOException> join = mergeJoin.join(null, new CustomEntry<RyaURI, RyaType>(pred, one), new CustomEntry<RyaURI, RyaType>(pred, two), new CustomEntry<RyaURI, RyaType>(pred, three), new CustomEntry<RyaURI, RyaType>(pred, four));
    Set<RyaURI> uris = new HashSet<RyaURI>();
    while (join.hasNext()) {
        uris.add(join.next());
    }
    assertTrue(uris.contains(subj1));
    assertTrue(uris.contains(subj2));
    assertTrue(uris.contains(subj4));
    join.close();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MergeJoin(org.apache.rya.api.persist.query.join.MergeJoin) RyaType(org.apache.rya.api.domain.RyaType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 73 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class StatementPatternStorage method addInferredRanges.

protected void addInferredRanges(String tablePrefix, Job job) throws IOException {
    logger.info("Adding inferences to statement pattern[subject:" + subject_value + ", predicate:" + predicate_value + ", object:" + object_value + "]");
    // inference engine
    AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO();
    InferenceEngine inferenceEngine = new InferenceEngine();
    try {
        AccumuloRdfConfiguration rdfConf = new AccumuloRdfConfiguration(job.getConfiguration());
        rdfConf.setTablePrefix(tablePrefix);
        ryaDAO.setConf(rdfConf);
        try {
            if (!mock) {
                ryaDAO.setConnector(new ZooKeeperInstance(inst, zookeepers).getConnector(user, userP.getBytes(StandardCharsets.UTF_8)));
            } else {
                ryaDAO.setConnector(new MockInstance(inst).getConnector(user, userP.getBytes(StandardCharsets.UTF_8)));
            }
        } catch (Exception e) {
            throw new IOException(e);
        }
        ryaDAO.init();
        inferenceEngine.setConf(rdfConf);
        inferenceEngine.setRyaDAO(ryaDAO);
        inferenceEngine.setSchedule(false);
        inferenceEngine.init();
        // is it subclassof or subpropertyof
        if (RDF.TYPE.equals(predicate_value)) {
            // try subclassof
            Collection<URI> parents = inferenceEngine.findParents(inferenceEngine.getSubClassOfGraph(), (URI) object_value);
            if (parents != null && parents.size() > 0) {
                // add all relationships
                for (URI parent : parents) {
                    Map.Entry<TABLE_LAYOUT, Range> temp = createRange(subject_value, predicate_value, parent);
                    Range range = temp.getValue();
                    if (logger.isDebugEnabled()) {
                        logger.debug("Found subClassOf relationship [type:" + object_value + " is subClassOf:" + parent + "]");
                    }
                    addRange(range);
                }
            }
        } else if (predicate_value != null) {
            // subpropertyof check
            Set<URI> parents = inferenceEngine.findParents(inferenceEngine.getSubPropertyOfGraph(), (URI) predicate_value);
            for (URI parent : parents) {
                Map.Entry<TABLE_LAYOUT, Range> temp = createRange(subject_value, parent, object_value);
                Range range = temp.getValue();
                if (logger.isDebugEnabled()) {
                    logger.debug("Found subPropertyOf relationship [type:" + predicate_value + " is subPropertyOf:" + parent + "]");
                }
                addRange(range);
            }
        }
    } catch (Exception e) {
        logger.error("Exception in adding inferred ranges", e);
        throw new IOException(e);
    } finally {
        if (inferenceEngine != null) {
            try {
                inferenceEngine.destroy();
            } catch (InferenceEngineException e) {
                logger.error("Exception closing InferenceEngine", e);
            }
        }
        if (ryaDAO != null) {
            try {
                ryaDAO.destroy();
            } catch (RyaDAOException e) {
                logger.error("Exception closing ryadao", e);
            }
        }
    }
}
Also used : AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) Set(java.util.Set) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) ByteRange(org.apache.rya.api.query.strategy.ByteRange) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) MalformedQueryException(org.openrdf.query.MalformedQueryException) IOException(java.io.IOException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) InferenceEngine(org.apache.rya.rdftriplestore.inference.InferenceEngine) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) Map(java.util.Map)

Example 74 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class HashJoinTest method testMergeJoinMultiWayNone.

@Test
public void testMergeJoinMultiWayNone() throws Exception {
    // add data
    RyaURI pred = new RyaURI(litdupsNS, "pred1");
    RyaType zero = new RyaType("0");
    RyaType one = new RyaType("1");
    RyaType two = new RyaType("2");
    RyaType three = new RyaType("3");
    RyaType four = new RyaType("4");
    RyaURI subj1 = new RyaURI(litdupsNS, "subj1");
    RyaURI subj2 = new RyaURI(litdupsNS, "subj2");
    RyaURI subj3 = new RyaURI(litdupsNS, "subj3");
    RyaURI subj4 = new RyaURI(litdupsNS, "subj4");
    dao.add(new RyaStatement(subj1, pred, one));
    dao.add(new RyaStatement(subj1, pred, three));
    dao.add(new RyaStatement(subj1, pred, four));
    dao.add(new RyaStatement(subj2, pred, zero));
    dao.add(new RyaStatement(subj2, pred, one));
    dao.add(new RyaStatement(subj2, pred, four));
    dao.add(new RyaStatement(subj3, pred, two));
    dao.add(new RyaStatement(subj3, pred, four));
    dao.add(new RyaStatement(subj4, pred, one));
    dao.add(new RyaStatement(subj4, pred, two));
    dao.add(new RyaStatement(subj4, pred, three));
    // 1 join
    HashJoin hjoin = new HashJoin(dao.getQueryEngine());
    CloseableIteration<RyaURI, RyaDAOException> join = hjoin.join(null, new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, one), new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, two), new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, three), new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, four));
    assertFalse(join.hasNext());
    join.close();
}
Also used : RdfCloudTripleStoreUtils(org.apache.rya.api.RdfCloudTripleStoreUtils) RyaURI(org.apache.rya.api.domain.RyaURI) HashJoin(org.apache.rya.api.persist.query.join.HashJoin) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

Example 75 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class NewQueryCommand method execute.

@Override
public void execute(final Connector accumulo, final String ryaTablePrefix, final RyaSailRepository rya, final FluoClient fluo, final String[] args) throws ArgumentsException, ExecutionException, UnsupportedQueryException {
    checkNotNull(accumulo);
    checkNotNull(fluo);
    checkNotNull(args);
    log.trace("Executing the New Query Command...");
    // Parse the command line arguments.
    final Parameters params = new Parameters();
    try {
        new JCommander(params, args);
    } catch (final ParameterException e) {
        throw new ArgumentsException("Could not create a new query because of invalid command line parameters.", e);
    }
    // Load the request from the file into memory.
    log.trace("Loading the query found in file '" + params.queryRequestFile + "' into the client app.");
    ParsedQueryRequest request = null;
    try {
        final Path requestFile = Paths.get(params.queryRequestFile);
        final String requestText = IOUtils.toString(Files.newInputStream(requestFile));
        request = ParsedQueryRequest.parse(requestText);
    } catch (final IOException e) {
        throw new ExecutionException("Could not load the query request into memory.", e);
    }
    // Load the query into the Fluo app.
    log.trace("SPARQL Query: " + request.getQuery());
    log.trace("Var Orders: " + request.getVarOrders());
    log.trace("Loading these values into the Fluo app.");
    final CreateFluoPcj createPcj = new CreateFluoPcj();
    try {
        // Create the PCJ in Rya.
        final String sparql = request.getQuery();
        final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumulo, ryaTablePrefix);
        final String pcjId = pcjStorage.createPcj(sparql);
        // Tell the Fluo PCJ Updater app to maintain the PCJ.
        createPcj.withRyaIntegration(pcjId, pcjStorage, fluo, accumulo, ryaTablePrefix);
    } catch (MalformedQueryException | PcjException | RyaDAOException e) {
        throw new ExecutionException("Could not create and load historic matches into the the Fluo app for the query.", e);
    }
    log.trace("Finished executing the New Query Command.");
}
Also used : Path(java.nio.file.Path) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) PcjException(org.apache.rya.indexing.pcj.storage.PcjException) CreateFluoPcj(org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj) IOException(java.io.IOException) ParsedQueryRequest(org.apache.rya.indexing.pcj.fluo.client.util.ParsedQueryRequest) JCommander(com.beust.jcommander.JCommander) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MalformedQueryException(org.openrdf.query.MalformedQueryException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) ParameterException(com.beust.jcommander.ParameterException)

Aggregations

RyaDAOException (org.apache.rya.api.persist.RyaDAOException)100 RyaStatement (org.apache.rya.api.domain.RyaStatement)61 RyaURI (org.apache.rya.api.domain.RyaURI)45 Test (org.junit.Test)39 RyaType (org.apache.rya.api.domain.RyaType)28 IOException (java.io.IOException)26 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)23 AccumuloException (org.apache.accumulo.core.client.AccumuloException)22 SailException (org.openrdf.sail.SailException)15 HashSet (java.util.HashSet)12 AccumuloRyaQueryEngine (org.apache.rya.accumulo.query.AccumuloRyaQueryEngine)12 RdfCloudTripleStoreUtils (org.apache.rya.api.RdfCloudTripleStoreUtils)12 Map (java.util.Map)11 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)11 RyaClientException (org.apache.rya.api.client.RyaClientException)11 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)10 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)10 ArrayList (java.util.ArrayList)9 Scanner (org.apache.accumulo.core.client.Scanner)8 Text (org.apache.hadoop.io.Text)8