Search in sources :

Example 86 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class AccumuloRyaDAOTest method newRyaStatement.

private RyaStatement newRyaStatement() {
    RyaURI subject = new RyaURI(litdupsNS + randomString());
    RyaURI predicate = new RyaURI(litdupsNS + randomString());
    RyaType object = new RyaType(randomString());
    return new RyaStatement(subject, predicate, object);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType)

Example 87 with RyaType

use of org.apache.rya.api.domain.RyaType 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 88 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class AggregationPipelineQueryNode method getMatchExpression.

/**
 * Given a StatementPattern, generate an object representing the arguments
 * to a "$match" command that will find matching triples.
 * @param sp The StatementPattern to search for
 * @param path If given, specify the field that should be matched against
 *  the statement pattern, using an ordered list of field names for a nested
 *  field. E.g. to match records { "x": { "y": <statement pattern } }, pass
 *  "x" followed by "y".
 * @return The argument of a "$match" query
 */
private static BasicDBObject getMatchExpression(StatementPattern sp, String... path) {
    final Var subjVar = sp.getSubjectVar();
    final Var predVar = sp.getPredicateVar();
    final Var objVar = sp.getObjectVar();
    final Var contextVar = sp.getContextVar();
    RyaURI s = null;
    RyaURI p = null;
    RyaType o = null;
    RyaURI c = null;
    if (subjVar != null && subjVar.getValue() instanceof Resource) {
        s = RdfToRyaConversions.convertResource((Resource) subjVar.getValue());
    }
    if (predVar != null && predVar.getValue() instanceof URI) {
        p = RdfToRyaConversions.convertURI((URI) predVar.getValue());
    }
    if (objVar != null && objVar.getValue() != null) {
        o = RdfToRyaConversions.convertValue(objVar.getValue());
    }
    if (contextVar != null && contextVar.getValue() instanceof URI) {
        c = RdfToRyaConversions.convertURI((URI) contextVar.getValue());
    }
    RyaStatement rs = new RyaStatement(s, p, o, c);
    DBObject obj = strategy.getQuery(rs);
    // Add path prefix, if given
    if (path.length > 0) {
        StringBuilder sb = new StringBuilder();
        for (String str : path) {
            sb.append(str).append(".");
        }
        String prefix = sb.toString();
        Set<String> originalKeys = new HashSet<>(obj.keySet());
        originalKeys.forEach(key -> {
            Object value = obj.removeField(key);
            obj.put(prefix + key, value);
        });
    }
    return (BasicDBObject) obj;
}
Also used : Var(org.openrdf.query.algebra.Var) Resource(org.openrdf.model.Resource) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) RyaURI(org.apache.rya.api.domain.RyaURI) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) HashSet(java.util.HashSet)

Example 89 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class NullRowTriplePatternStrategyTest method testHandles.

/**
 * Test of handles method, of class NullRowTriplePatternStrategy.
 */
@Test
public void testHandles() {
    RyaURI subject = null;
    RyaURI predicate = null;
    RyaType object = null;
    RyaURI context = null;
    NullRowTriplePatternStrategy instance = new NullRowTriplePatternStrategy();
    assertTrue(instance.handles(subject, predicate, object, context));
    RyaURI uri = new RyaURI("urn:test#1234");
    assertFalse(instance.handles(uri, predicate, object, context));
    assertFalse(instance.handles(subject, uri, object, context));
    assertFalse(instance.handles(subject, predicate, uri, context));
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

Example 90 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class NullRowTriplePatternStrategyTest method testDefineRange.

/**
 * Test of defineRange method, of class NullRowTriplePatternStrategy.
 * @throws java.lang.Exception
 */
@Test
public void testDefineRange() throws Exception {
    RyaURI subject = null;
    RyaURI predicate = null;
    RyaType object = null;
    RyaURI context = null;
    RdfCloudTripleStoreConfiguration conf = new MockRdfConfiguration();
    NullRowTriplePatternStrategy instance = new NullRowTriplePatternStrategy();
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> expResult = new RdfCloudTripleStoreUtils.CustomEntry<>(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, new ByteRange(new byte[] {}, LAST_BYTES));
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> result = instance.defineRange(subject, predicate, object, context, conf);
    assertEquals(expResult.getKey(), result.getKey());
    assertTrue(Arrays.equals(expResult.getValue().getStart(), result.getValue().getStart()));
    assertTrue(Arrays.equals(expResult.getValue().getEnd(), result.getValue().getEnd()));
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaType(org.apache.rya.api.domain.RyaType) RdfCloudTripleStoreConfiguration(org.apache.rya.api.RdfCloudTripleStoreConfiguration) Map(java.util.Map) Test(org.junit.Test)

Aggregations

RyaType (org.apache.rya.api.domain.RyaType)178 RyaURI (org.apache.rya.api.domain.RyaURI)146 RyaStatement (org.apache.rya.api.domain.RyaStatement)115 Test (org.junit.Test)109 BindingSet (org.openrdf.query.BindingSet)42 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)42 ArrayList (java.util.ArrayList)35 StatementPattern (org.openrdf.query.algebra.StatementPattern)35 ParsedQuery (org.openrdf.query.parser.ParsedQuery)35 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)35 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)34 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)34 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)28 Property (org.apache.rya.indexing.entity.model.Property)23 URIImpl (org.openrdf.model.impl.URIImpl)23 HashSet (java.util.HashSet)22 Entity (org.apache.rya.indexing.entity.model.Entity)20 Value (org.openrdf.model.Value)19 LiteralImpl (org.openrdf.model.impl.LiteralImpl)19 BatchWriter (org.apache.accumulo.core.client.BatchWriter)18