Search in sources :

Example 31 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class MongoLoadStatementsFileIT method instanceDoesNotExist.

@Test(expected = InstanceDoesNotExistException.class)
public void instanceDoesNotExist() throws Exception {
    org.apache.log4j.BasicConfigurator.configure();
    final RyaClient ryaClient = MongoRyaClientFactory.build(getConnectionDetails(), getMongoClient());
    ryaClient.getLoadStatementsFile().loadStatements(getConnectionDetails().getHostname(), Paths.get("src/test/resources/example.ttl"), RDFFormat.TURTLE);
}
Also used : RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 32 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class MongoSetRyaStreamsConfigurationIT method instanceDoesNotExist.

@Test(expected = InstanceDoesNotExistException.class)
public void instanceDoesNotExist() throws Exception {
    final RyaClient ryaClient = MongoRyaClientFactory.build(getConnectionDetails(), getMongoClient());
    // Skip the install step to create error causing situation.
    final String ryaInstance = conf.getRyaInstanceName();
    final RyaStreamsDetails details = new RyaStreamsDetails("localhost", 6);
    ryaClient.getSetRyaStreamsConfiguration().setRyaStreamsConfiguration(ryaInstance, details);
}
Also used : RyaStreamsDetails(org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 33 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class MongoPCJIndexIT method sparqlQuery_Test.

@Test
public void sparqlQuery_Test() throws Exception {
    // Setup a Rya Client.
    final MongoConnectionDetails connectionDetails = getConnectionDetails();
    final RyaClient ryaClient = MongoRyaClientFactory.build(connectionDetails, getMongoClient());
    final String pcjQuery = "SELECT ?name WHERE {" + " ?name <urn:likes> <urn:icecream> ." + " ?name <urn:hasEyeColor> <urn:blue> ." + " }";
    // Install an instance of Rya and load statements.
    ryaClient.getInstall().install(conf.getRyaInstanceName(), InstallConfiguration.builder().setEnablePcjIndex(true).build());
    ryaClient.getLoadStatements().loadStatements(conf.getRyaInstanceName(), getStatements());
    final String pcjId = ryaClient.getCreatePCJ().createPCJ(conf.getRyaInstanceName(), pcjQuery);
    ryaClient.getBatchUpdatePCJ().batchUpdate(conf.getRyaInstanceName(), pcjId);
    // purge contents of rya triples collection
    getMongoClient().getDatabase(conf.getRyaInstanceName()).getCollection(conf.getTriplesCollectionName()).drop();
    // run the query.  since the triples collection is gone, if the results match, they came from the PCJ index.
    conf.setBoolean(ConfigUtils.USE_PCJ, true);
    conf.setBoolean(ConfigUtils.USE_OPTIMAL_PCJ, true);
    conf.setBoolean(ConfigUtils.DISPLAY_QUERY_PLAN, true);
    final Sail sail = RyaSailFactory.getInstance(conf);
    SailRepositoryConnection conn = new SailRepository(sail).getConnection();
    conn.begin();
    final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, pcjQuery);
    tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERYPLAN_FLAG, RdfCloudTripleStoreConstants.VALUE_FACTORY.createLiteral(true));
    final TupleQueryResult rez = tupleQuery.evaluate();
    final Set<BindingSet> results = new HashSet<>();
    while (rez.hasNext()) {
        final BindingSet bs = rez.next();
        results.add(bs);
    }
    // Verify the correct results were loaded into the PCJ table.
    final Set<BindingSet> expectedResults = new HashSet<>();
    MapBindingSet bs = new MapBindingSet();
    bs.addBinding("name", VF.createURI("urn:Alice"));
    expectedResults.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("name", VF.createURI("urn:Bob"));
    expectedResults.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("name", VF.createURI("urn:Charlie"));
    expectedResults.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("name", VF.createURI("urn:David"));
    expectedResults.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("name", VF.createURI("urn:Eve"));
    expectedResults.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("name", VF.createURI("urn:Frank"));
    expectedResults.add(bs);
    assertEquals(6, results.size());
    assertEquals(expectedResults, results);
}
Also used : MongoConnectionDetails(org.apache.rya.api.client.mongo.MongoConnectionDetails) MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) SailRepository(org.openrdf.repository.sail.SailRepository) Sail(org.openrdf.sail.Sail) TupleQuery(org.openrdf.query.TupleQuery) RyaClient(org.apache.rya.api.client.RyaClient) MapBindingSet(org.openrdf.query.impl.MapBindingSet) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) TupleQueryResult(org.openrdf.query.TupleQueryResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class GeoFunctionsIT method runTest.

public void runTest(final String sparql, final Collection<Statement> statements, final Collection<BindingSet> expectedResults) throws Exception {
    requireNonNull(sparql);
    requireNonNull(statements);
    requireNonNull(expectedResults);
    // Register the PCJ with Rya.
    final Instance accInstance = super.getAccumuloConnector().getInstance();
    final Connector accumuloConn = super.getAccumuloConnector();
    final RyaClient ryaClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(getUsername(), getPassword().toCharArray(), accInstance.getInstanceName(), accInstance.getZooKeepers()), accumuloConn);
    ryaClient.getCreatePCJ().createPCJ(getRyaInstanceName(), sparql);
    // Write the data to Rya.
    final SailRepositoryConnection ryaConn = super.getRyaSailRepository().getConnection();
    ryaConn.begin();
    ryaConn.add(statements);
    ryaConn.commit();
    ryaConn.close();
    // Wait for the Fluo application to finish computing the end result.
    super.getMiniFluo().waitForObservers();
    // Fetch the value that is stored within the PCJ table.
    try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumuloConn, getRyaInstanceName())) {
        final String pcjId = pcjStorage.listPcjs().get(0);
        final Set<BindingSet> results = Sets.newHashSet(pcjStorage.listResults(pcjId));
        // Ensure the result of the query matches the expected result.
        assertEquals(expectedResults, results);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) Instance(org.apache.accumulo.core.client.Instance) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) RyaClient(org.apache.rya.api.client.RyaClient) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection)

Example 35 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class CreateDeleteIT method loadData.

private String loadData(final String sparql, final Collection<Statement> statements) throws Exception {
    requireNonNull(sparql);
    requireNonNull(statements);
    // Register the PCJ with Rya.
    final RyaClient ryaClient = AccumuloRyaClientFactory.build(createConnectionDetails(), getAccumuloConnector());
    final String pcjId = ryaClient.getCreatePCJ().createPCJ(getRyaInstanceName(), sparql, Sets.newHashSet());
    // Write the data to Rya.
    final SailRepositoryConnection ryaConn = getRyaSailRepository().getConnection();
    ryaConn.begin();
    ryaConn.add(statements);
    ryaConn.commit();
    ryaConn.close();
    // Wait for the Fluo application to finish computing the end result.
    getMiniFluo().waitForObservers();
    // The PCJ Id is the topic name the results will be written to.
    return pcjId;
}
Also used : RyaClient(org.apache.rya.api.client.RyaClient) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection)

Aggregations

RyaClient (org.apache.rya.api.client.RyaClient)105 Test (org.junit.Test)76 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)41 SparqlPrompt (org.apache.rya.shell.util.SparqlPrompt)29 InstallConfiguration (org.apache.rya.api.client.Install.InstallConfiguration)26 CliCommand (org.springframework.shell.core.annotation.CliCommand)20 RyaClientException (org.apache.rya.api.client.RyaClientException)18 Install (org.apache.rya.api.client.Install)17 ShellState (org.apache.rya.shell.SharedShellState.ShellState)16 InstallPrompt (org.apache.rya.shell.util.InstallPrompt)16 UninstallPrompt (org.apache.rya.shell.util.UninstallPrompt)16 RyaDetails (org.apache.rya.api.instance.RyaDetails)14 ConsolePrinter (org.apache.rya.shell.util.ConsolePrinter)13 IOException (java.io.IOException)11 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)9 Sail (org.openrdf.sail.Sail)9 ValueFactory (org.openrdf.model.ValueFactory)8 HashSet (java.util.HashSet)7 Connector (org.apache.accumulo.core.client.Connector)7 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)7