use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class AccumuloLoadStatementsFileIT method instanceDoesNotExist.
@Test(expected = InstanceDoesNotExistException.class)
public void instanceDoesNotExist() throws Exception {
final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(getUsername(), getPassword().toCharArray(), getInstanceName(), getZookeepers());
final RyaClient ryaClient = AccumuloRyaClientFactory.build(connectionDetails, getConnector());
ryaClient.getLoadStatementsFile().loadStatements(getRyaInstanceName(), Paths.get("src/test/resources/example.ttl"), RDFFormat.TURTLE);
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class AccumuloLoadStatementsFileIT method loadTurtleFile.
@Test
public void loadTurtleFile() throws Exception {
// Install an instance of Rya.
final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(false).setEnableEntityCentricIndex(false).setEnableFreeTextIndex(false).setEnableTemporalIndex(false).setEnablePcjIndex(false).setEnableGeoIndex(false).setFluoPcjAppName("fluo_app_name").build();
final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(getUsername(), getPassword().toCharArray(), getInstanceName(), getZookeepers());
final RyaClient ryaClient = AccumuloRyaClientFactory.build(connectionDetails, getConnector());
final Install install = ryaClient.getInstall();
install.install(getRyaInstanceName(), installConfig);
// Load the test statement file.
ryaClient.getLoadStatementsFile().loadStatements(getRyaInstanceName(), Paths.get("src/test/resources/example.ttl"), RDFFormat.TURTLE);
// Verify that the statements were loaded.
final ValueFactory vf = new ValueFactoryImpl();
final List<Statement> expected = new ArrayList<>();
expected.add(vf.createStatement(vf.createURI("http://example#alice"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#bob")));
expected.add(vf.createStatement(vf.createURI("http://example#bob"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#charlie")));
expected.add(vf.createStatement(vf.createURI("http://example#charlie"), vf.createURI("http://example#likes"), vf.createURI("http://example#icecream")));
final List<Statement> statements = new ArrayList<>();
final WholeRowTripleResolver tripleResolver = new WholeRowTripleResolver();
final Scanner scanner = getConnector().createScanner(getRyaInstanceName() + "spo", new Authorizations());
final Iterator<Entry<Key, Value>> it = scanner.iterator();
while (it.hasNext()) {
final Entry<Key, Value> next = it.next();
final Key key = next.getKey();
final byte[] row = key.getRow().getBytes();
final byte[] columnFamily = key.getColumnFamily().getBytes();
final byte[] columnQualifier = key.getColumnQualifier().getBytes();
final TripleRow tripleRow = new TripleRow(row, columnFamily, columnQualifier);
final RyaStatement ryaStatement = tripleResolver.deserialize(TABLE_LAYOUT.SPO, tripleRow);
final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
// Filter out the rya version statement if it is present.
if (!isRyaMetadataStatement(vf, statement)) {
statements.add(statement);
}
}
assertEquals(expected, statements);
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class MongoPCJIndexIT method sparqlQuery_Test_complex.
@Test
public void sparqlQuery_Test_complex() 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> ." + " }";
final String testQuery = "SELECT ?name WHERE {" + " ?name <urn:hasHairColor> <urn:brown> ." + " ?name <urn:likes> <urn:icecream> ." + " ?name <urn:hasEyeColor> <urn:blue> ." + " }";
// Install an instance of Rya and load statements.
conf.setBoolean(ConfigUtils.USE_PCJ, true);
conf.setBoolean(ConfigUtils.USE_OPTIMAL_PCJ, true);
conf.setBoolean(ConfigUtils.DISPLAY_QUERY_PLAN, true);
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);
System.out.println("Triples: " + getMongoClient().getDatabase(conf.getRyaInstanceName()).getCollection(conf.getTriplesCollectionName()).count());
System.out.println("PCJS: " + getMongoClient().getDatabase(conf.getRyaInstanceName()).getCollection("pcjs").count());
// run the query. since the triples collection is gone, if the results match, they came from the PCJ index.
final Sail sail = RyaSailFactory.getInstance(conf);
SailRepositoryConnection conn = new SailRepository(sail).getConnection();
conn.begin();
final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, testQuery);
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 = 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(3, results.size());
assertEquals(expectedResults, results);
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class MongoLoadStatementsIT 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.
ryaClient.getLoadStatements().loadStatements(getConnectionDetails().getHostname(), makeTestStatements());
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class MongoUninstallIT method uninstall.
@Test
public void uninstall() throws MongoException, RyaClientException {
// Install an instance of Rya.
final String instanceName = "testInstance_";
final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(true).setEnableEntityCentricIndex(true).setEnableFreeTextIndex(true).setEnableTemporalIndex(true).setEnablePcjIndex(true).setEnableGeoIndex(true).setFluoPcjAppName("fluo_app_name").build();
final RyaClient ryaClient = MongoRyaClientFactory.build(getConnectionDetails(), getMongoClient());
final Install install = ryaClient.getInstall();
install.install(instanceName, installConfig);
// Show that the instance exists.
final InstanceExists instanceExists = ryaClient.getInstanceExists();
assertTrue(instanceExists.exists(instanceName));
// Uninstall the instance
final Uninstall uninstall = ryaClient.getUninstall();
uninstall.uninstall(instanceName);
// Check that the instance no longer exists.
assertFalse(instanceExists.exists(instanceName));
}
Aggregations