use of org.apache.rya.api.persist.RyaDAOException 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.api.persist.RyaDAOException 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.api.persist.RyaDAOException 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.api.persist.RyaDAOException in project incubator-rya by apache.
the class AccumuloRyaDAOTest method testAddEmptyString.
@Test
public void testAddEmptyString() throws Exception {
RyaURI cpu = RdfToRyaConversions.convertURI(vf.createURI(litdupsNS, "cpu"));
RyaURI loadPerc = RdfToRyaConversions.convertURI(vf.createURI(litdupsNS, "loadPerc"));
RyaType empty = new RyaType("");
dao.add(new RyaStatement(cpu, loadPerc, empty));
CloseableIteration<RyaStatement, RyaDAOException> iter = dao.getQueryEngine().query(new RyaStatement(cpu, loadPerc, null), conf);
while (iter.hasNext()) {
assertEquals("", iter.next().getObject().getData());
}
iter.close();
}
use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class RyaStatementBindingSetKeyValueIterator method next.
@Override
public Map.Entry<RyaStatement, BindingSet> next() throws RyaDAOException {
if (!hasNext() || isClosed()) {
throw new NoSuchElementException();
}
try {
while (true) {
if (bsIter != null && bsIter.hasNext()) {
maxResults--;
return new RdfCloudTripleStoreUtils.CustomEntry<RyaStatement, BindingSet>(statement, bsIter.next());
}
if (dataIterator.hasNext()) {
Map.Entry<Key, Value> next = dataIterator.next();
Key key = next.getKey();
statement = ryaContext.deserializeTriple(tableLayout, new TripleRow(key.getRowData().toArray(), key.getColumnFamilyData().toArray(), key.getColumnQualifierData().toArray(), key.getTimestamp(), key.getColumnVisibilityData().toArray(), next.getValue().get()));
if (next.getValue() != null) {
statement.setValue(next.getValue().get());
}
Collection<BindingSet> bindingSets = rangeMap.containsKey(key);
if (!bindingSets.isEmpty()) {
bsIter = bindingSets.iterator();
}
} else {
break;
}
}
return null;
} catch (TripleRowResolverException e) {
throw new RyaDAOException(e);
}
}
Aggregations