use of org.apache.rya.accumulo.query.AccumuloRyaQueryEngine in project incubator-rya by apache.
the class AccumuloRyaDAOTest method testQueryCollectionRegex.
@Test
public void testQueryCollectionRegex() throws Exception {
RyaURI cpu = new RyaURI(litdupsNS + "cpu");
RyaURI loadPerc = new RyaURI(litdupsNS + "loadPerc");
RyaURI uri1 = new RyaURI(litdupsNS + "uri1");
RyaURI uri2 = new RyaURI(litdupsNS + "uri2");
RyaURI uri3 = new RyaURI(litdupsNS + "uri3");
RyaURI uri4 = new RyaURI(litdupsNS + "uri4");
RyaURI uri5 = new RyaURI(litdupsNS + "uri5");
RyaURI uri6 = new RyaURI(litdupsNS + "uri6");
dao.add(new RyaStatement(cpu, loadPerc, uri1));
dao.add(new RyaStatement(cpu, loadPerc, uri2));
dao.add(new RyaStatement(cpu, loadPerc, uri3));
dao.add(new RyaStatement(cpu, loadPerc, uri4));
dao.add(new RyaStatement(cpu, loadPerc, uri5));
dao.add(new RyaStatement(cpu, loadPerc, uri6));
AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();
Collection<RyaStatement> coll = new ArrayList();
coll.add(new RyaStatement(null, loadPerc, uri1));
coll.add(new RyaStatement(null, loadPerc, uri2));
conf.setRegexPredicate(loadPerc.getData());
CloseableIteration<RyaStatement, RyaDAOException> iter = queryEngine.batchQuery(coll, conf);
int count = 0;
while (iter.hasNext()) {
count++;
iter.next();
}
iter.close();
assertEquals(2, count);
conf.setRegexPredicate("notLoadPerc");
iter = queryEngine.batchQuery(coll, conf);
count = 0;
while (iter.hasNext()) {
count++;
iter.next();
}
iter.close();
assertEquals(0, count);
}
use of org.apache.rya.accumulo.query.AccumuloRyaQueryEngine in project incubator-rya by apache.
the class AccumuloRyaDAOTest method testQuery.
// TOOD: Add test for set of queries
@Test
public void testQuery() throws Exception {
RyaURI cpu = new RyaURI(litdupsNS + "cpu");
RyaURI loadPerc = new RyaURI(litdupsNS + "loadPerc");
RyaURI uri1 = new RyaURI(litdupsNS + "uri1");
RyaURI uri2 = new RyaURI(litdupsNS + "uri2");
RyaURI uri3 = new RyaURI(litdupsNS + "uri3");
RyaURI uri4 = new RyaURI(litdupsNS + "uri4");
RyaURI uri5 = new RyaURI(litdupsNS + "uri5");
RyaURI uri6 = new RyaURI(litdupsNS + "uri6");
dao.add(new RyaStatement(cpu, loadPerc, uri1));
dao.add(new RyaStatement(cpu, loadPerc, uri2));
dao.add(new RyaStatement(cpu, loadPerc, uri3));
dao.add(new RyaStatement(cpu, loadPerc, uri4));
dao.add(new RyaStatement(cpu, loadPerc, uri5));
dao.add(new RyaStatement(cpu, loadPerc, uri6));
AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();
Collection<RyaStatement> coll = new ArrayList();
coll.add(new RyaStatement(null, loadPerc, uri1));
coll.add(new RyaStatement(null, loadPerc, uri2));
CloseableIteration<RyaStatement, RyaDAOException> iter = queryEngine.batchQuery(coll, conf);
int count = 0;
while (iter.hasNext()) {
count++;
iter.next();
}
iter.close();
assertEquals(2, count);
// now use batchscanner
AccumuloRdfConfiguration queryConf = new AccumuloRdfConfiguration(conf);
queryConf.setMaxRangesForScanner(2);
coll = new ArrayList();
coll.add(new RyaStatement(null, loadPerc, uri1));
coll.add(new RyaStatement(null, loadPerc, uri2));
coll.add(new RyaStatement(null, loadPerc, uri3));
coll.add(new RyaStatement(null, loadPerc, uri4));
iter = queryEngine.batchQuery(coll, queryConf);
// old code had a weird behaviour that could not perform hasNext consecutively
assertTrue(iter.hasNext());
assertTrue(iter.hasNext());
assertTrue(iter.hasNext());
count = 0;
while (iter.hasNext()) {
count++;
assertTrue(iter.hasNext());
iter.next();
}
iter.close();
assertEquals(4, count);
}
use of org.apache.rya.accumulo.query.AccumuloRyaQueryEngine in project incubator-rya by apache.
the class AccumuloRyaDAOTest method testQueryCollectionRegexWBatchScanner.
@Test
public void testQueryCollectionRegexWBatchScanner() throws Exception {
RyaURI cpu = new RyaURI(litdupsNS + "cpu");
RyaURI loadPerc = new RyaURI(litdupsNS + "loadPerc");
RyaURI uri1 = new RyaURI(litdupsNS + "uri1");
RyaURI uri2 = new RyaURI(litdupsNS + "uri2");
RyaURI uri3 = new RyaURI(litdupsNS + "uri3");
RyaURI uri4 = new RyaURI(litdupsNS + "uri4");
RyaURI uri5 = new RyaURI(litdupsNS + "uri5");
RyaURI uri6 = new RyaURI(litdupsNS + "uri6");
dao.add(new RyaStatement(cpu, loadPerc, uri1));
dao.add(new RyaStatement(cpu, loadPerc, uri2));
dao.add(new RyaStatement(cpu, loadPerc, uri3));
dao.add(new RyaStatement(cpu, loadPerc, uri4));
dao.add(new RyaStatement(cpu, loadPerc, uri5));
dao.add(new RyaStatement(cpu, loadPerc, uri6));
AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();
AccumuloRdfConfiguration queryConf = new AccumuloRdfConfiguration(conf);
queryConf.setMaxRangesForScanner(1);
Collection<RyaStatement> coll = new ArrayList();
coll.add(new RyaStatement(null, loadPerc, uri1));
coll.add(new RyaStatement(null, loadPerc, uri2));
conf.setRegexPredicate(loadPerc.getData());
CloseableIteration<RyaStatement, RyaDAOException> iter = queryEngine.batchQuery(coll, queryConf);
int count = 0;
while (iter.hasNext()) {
count++;
iter.next();
}
iter.close();
assertEquals(2, count);
queryConf.setRegexPredicate("notLoadPerc");
iter = queryEngine.batchQuery(coll, queryConf);
count = 0;
while (iter.hasNext()) {
count++;
iter.next();
}
iter.close();
assertEquals(0, count);
}
use of org.apache.rya.accumulo.query.AccumuloRyaQueryEngine in project incubator-rya by apache.
the class AccumuloRyaDAOTest method testMaxResults.
@Test
public void testMaxResults() throws Exception {
RyaURI cpu = new RyaURI(litdupsNS + "cpu");
RyaURI loadPerc = new RyaURI(litdupsNS + "loadPerc");
dao.add(new RyaStatement(cpu, loadPerc, new RyaURI(litdupsNS + "uri1")));
dao.add(new RyaStatement(cpu, loadPerc, new RyaURI(litdupsNS + "uri2")));
dao.add(new RyaStatement(cpu, loadPerc, new RyaURI(litdupsNS + "uri3")));
dao.add(new RyaStatement(cpu, loadPerc, new RyaURI(litdupsNS + "uri4")));
dao.add(new RyaStatement(cpu, loadPerc, new RyaURI(litdupsNS + "uri5")));
AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();
AccumuloRdfConfiguration queryConf = new AccumuloRdfConfiguration(conf);
long limit = 3l;
queryConf.setLimit(limit);
CloseableIteration<RyaStatement, RyaDAOException> iter = queryEngine.query(new RyaStatement(cpu, loadPerc, null), queryConf);
int count = 0;
while (iter.hasNext()) {
iter.next().getObject();
count++;
}
iter.close();
assertEquals(limit, count);
}
use of org.apache.rya.accumulo.query.AccumuloRyaQueryEngine in project incubator-rya by apache.
the class RyaQueryEngineFactory method getQueryEngine.
@SuppressWarnings("unchecked")
public static <C extends RdfCloudTripleStoreConfiguration> RyaQueryEngine<C> getQueryEngine(RdfCloudTripleStoreConfiguration conf) {
if (conf instanceof AccumuloRdfConfiguration) {
AccumuloRdfConfiguration aConf = (AccumuloRdfConfiguration) conf;
Instance instance;
String instanceName = aConf.get("sc.cloudbase.instancename");
String user = aConf.get("sc.cloudbase.username");
String password = aConf.get("sc.cloudbase.password");
if (aConf.getBoolean(".useMockInstance", false)) {
instance = new MockInstance(instanceName);
} else {
String zookeepers = aConf.get("sc.cloudbase.zookeepers");
instance = new ZooKeeperInstance(instanceName, zookeepers);
}
Connector conn;
try {
conn = instance.getConnector(user, new PasswordToken(password));
} catch (AccumuloException | AccumuloSecurityException e) {
throw new RuntimeException(e);
}
return (RyaQueryEngine<C>) new AccumuloRyaQueryEngine(conn, aConf);
} else if (conf instanceof StatefulMongoDBRdfConfiguration && ConfigUtils.getUseMongo(conf)) {
StatefulMongoDBRdfConfiguration mongoConf = (StatefulMongoDBRdfConfiguration) conf;
MongoDBQueryEngine mongoQueryEngine = new MongoDBQueryEngine();
mongoQueryEngine.setConf(mongoConf);
return (RyaQueryEngine<C>) mongoQueryEngine;
} else {
throw new IllegalArgumentException("Invalid configuration type.");
}
}
Aggregations