Search in sources :

Example 51 with RyaDAOException

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);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) Test(org.junit.Test)

Example 52 with RyaDAOException

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);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) Test(org.junit.Test)

Example 53 with RyaDAOException

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);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) Test(org.junit.Test)

Example 54 with RyaDAOException

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();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) 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 55 with RyaDAOException

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);
    }
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) BindingSet(org.openrdf.query.BindingSet) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) Value(org.apache.accumulo.core.data.Value) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException) Key(org.apache.accumulo.core.data.Key)

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