Search in sources :

Example 71 with VisibilityBindingSet

use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.

the class ConstructGraphTest method testConstructGraphBNode.

@Test
public void testConstructGraphBNode() throws MalformedQueryException {
    String query = "select ?x where { _:b <uri:talksTo> ?x. _:b <uri:worksAt> ?z }";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
    ConstructGraph graph = new ConstructGraph(patterns);
    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("x", vf.createURI("uri:Joe"));
    bs.addBinding("z", vf.createURI("uri:BurgerShack"));
    VisibilityBindingSet vBs = new VisibilityBindingSet(bs, "FOUO");
    Set<RyaStatement> statements = graph.createGraphFromBindingSet(vBs);
    Set<RyaStatement> statements2 = graph.createGraphFromBindingSet(vBs);
    RyaURI subject = null;
    for (RyaStatement statement : statements) {
        RyaURI subjURI = statement.getSubject();
        if (subject == null) {
            subject = subjURI;
        } else {
            assertEquals(subjURI, subject);
        }
    }
    RyaURI subject2 = null;
    for (RyaStatement statement : statements2) {
        RyaURI subjURI = statement.getSubject();
        if (subject2 == null) {
            subject2 = subjURI;
        } else {
            assertEquals(subjURI, subject2);
        }
    }
    assertTrue(!subject.equals(subject2));
    ConstructGraphTestUtils.ryaStatementsEqualIgnoresBlankNode(statements, statements2);
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) RyaURI(org.apache.rya.api.domain.RyaURI) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ParsedQuery(org.openrdf.query.parser.ParsedQuery) RyaStatement(org.apache.rya.api.domain.RyaStatement) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 72 with VisibilityBindingSet

use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.

the class ConstructGraphTest method testConstructGraph.

@Test
public void testConstructGraph() throws MalformedQueryException, UnsupportedEncodingException {
    String query = "select ?x where { ?x <uri:talksTo> <uri:Bob>. ?y <uri:worksAt> ?z }";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
    ConstructGraph graph = new ConstructGraph(patterns);
    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("x", vf.createURI("uri:Joe"));
    bs.addBinding("y", vf.createURI("uri:Bob"));
    bs.addBinding("z", vf.createURI("uri:BurgerShack"));
    VisibilityBindingSet vBs = new VisibilityBindingSet(bs, "FOUO");
    Set<RyaStatement> statements = graph.createGraphFromBindingSet(vBs);
    RyaStatement statement1 = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:talksTo"), new RyaURI("uri:Bob"));
    RyaStatement statement2 = new RyaStatement(new RyaURI("uri:Bob"), new RyaURI("uri:worksAt"), new RyaURI("uri:BurgerShack"));
    Set<RyaStatement> expected = Sets.newHashSet(Arrays.asList(statement1, statement2));
    expected.forEach(x -> x.setColumnVisibility("FOUO".getBytes()));
    ConstructGraphTestUtils.ryaStatementSetsEqualIgnoresTimestamp(expected, statements);
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) RyaURI(org.apache.rya.api.domain.RyaURI) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ParsedQuery(org.openrdf.query.parser.ParsedQuery) RyaStatement(org.apache.rya.api.domain.RyaStatement) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 73 with VisibilityBindingSet

use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.

the class ConstructProjectionTest method testConstructProjectionProjPred.

@Test
public void testConstructProjectionProjPred() throws MalformedQueryException {
    String query = "select ?p where { <uri:Joe> ?p <uri:Bob> }";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
    ConstructProjection projection = new ConstructProjection(patterns.get(0));
    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("p", vf.createURI("uri:worksWith"));
    VisibilityBindingSet vBs = new VisibilityBindingSet(bs);
    RyaStatement statement = projection.projectBindingSet(vBs, new HashMap<>());
    RyaStatement expected = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:worksWith"), new RyaURI("uri:Bob"));
    expected.setTimestamp(statement.getTimestamp());
    expected.setColumnVisibility(new byte[0]);
    assertEquals(expected, statement);
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) RyaURI(org.apache.rya.api.domain.RyaURI) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ParsedQuery(org.openrdf.query.parser.ParsedQuery) RyaStatement(org.apache.rya.api.domain.RyaStatement) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 74 with VisibilityBindingSet

use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.

the class MultiProjectionEvaluatorTest method singleBlankNode.

@Test
public void singleBlankNode() throws Exception {
    // Read the multi projection object from a SPARQL query.
    final MultiProjection multiProjection = getMultiProjection("CONSTRUCT {" + "_:b a <urn:movementObservation> ; " + "<urn:location> ?location ; " + "<urn:direction> ?direction ; " + "}" + "WHERE {" + "?thing <urn:corner> ?location ." + "?thing <urn:compass> ?direction." + "}");
    // Create a Binding Set that contains the result of the WHERE clause.
    final ValueFactory vf = new ValueFactoryImpl();
    MapBindingSet bs = new MapBindingSet();
    bs.addBinding("location", vf.createLiteral("South St and 5th St"));
    bs.addBinding("direction", vf.createLiteral("NW"));
    final VisibilityBindingSet original = new VisibilityBindingSet(bs, "a|b");
    // Create the expected results.
    final Set<VisibilityBindingSet> expected = new HashSet<>();
    final String blankNodeId = UUID.randomUUID().toString();
    final BNode blankNode = vf.createBNode(blankNodeId);
    bs = new MapBindingSet();
    bs.addBinding("subject", blankNode);
    bs.addBinding("predicate", RDF.TYPE);
    bs.addBinding("object", vf.createURI("urn:movementObservation"));
    expected.add(new VisibilityBindingSet(bs, "a|b"));
    bs = new MapBindingSet();
    bs.addBinding("subject", blankNode);
    bs.addBinding("predicate", vf.createURI("urn:location"));
    bs.addBinding("object", vf.createLiteral("South St and 5th St"));
    expected.add(new VisibilityBindingSet(bs, "a|b"));
    bs = new MapBindingSet();
    bs.addBinding("subject", blankNode);
    bs.addBinding("predicate", vf.createURI("urn:direction"));
    bs.addBinding("object", vf.createLiteral("NW"));
    expected.add(new VisibilityBindingSet(bs, "a|b"));
    // Run the projection evaluator.
    final Set<VisibilityBindingSet> results = MultiProjectionEvaluator.make(multiProjection, () -> blankNodeId).project(original);
    // The expected binding sets.
    assertEquals(expected, results);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BNode(org.openrdf.model.BNode) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) MultiProjection(org.openrdf.query.algebra.MultiProjection) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 75 with VisibilityBindingSet

use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.

the class MultiProjectionEvaluatorTest method multipleBlanknodes.

@Test
public void multipleBlanknodes() throws Exception {
    // Read the multi projection object from a SPARQL query.
    final MultiProjection multiProjection = getMultiProjection("CONSTRUCT {" + "_:b a <urn:vehicle> . " + "_:b <urn:tiresCount> 4 ." + "_:c a <urn:pet> . " + "_:c <urn:isDead> false . " + "}" + "WHERE {" + "?vehicle <urn:owner> ?owner . " + "?vehicle <urn:plates> ?plates . " + "?pet <urn:owner> ?owner . " + "?pet <urn:isLiving> true . " + "}");
    // Create a Binding Set that contains the result of the WHERE clause.
    final ValueFactory vf = new ValueFactoryImpl();
    MapBindingSet bs = new MapBindingSet();
    bs.addBinding("vehicle", vf.createLiteral("Alice's car"));
    bs.addBinding("owner", vf.createURI("urn:Alice"));
    bs.addBinding("plates", vf.createLiteral("XXXXXXX"));
    bs.addBinding("pet", vf.createURI("urn:Kitty"));
    final VisibilityBindingSet original = new VisibilityBindingSet(bs, "a|b");
    // Run the projection evaluator.
    final Set<VisibilityBindingSet> results = MultiProjectionEvaluator.make(multiProjection, new RandomUUIDFactory()).project(original);
    // Figure out the blank nodes.
    Value vehicalBNode = null;
    Value petBNode = null;
    for (final VisibilityBindingSet result : results) {
        final Value object = result.getValue("object");
        if (object.equals(vf.createURI("urn:vehicle"))) {
            vehicalBNode = result.getValue("subject");
        } else if (object.equals(vf.createURI("urn:pet"))) {
            petBNode = result.getValue("subject");
        }
    }
    // The expected binding sets.
    final Set<VisibilityBindingSet> expected = new HashSet<>();
    bs = new MapBindingSet();
    bs.addBinding("subject", vehicalBNode);
    bs.addBinding("predicate", RDF.TYPE);
    bs.addBinding("object", vf.createURI("urn:vehicle"));
    expected.add(new VisibilityBindingSet(bs, "a|b"));
    bs = new MapBindingSet();
    bs.addBinding("subject", vehicalBNode);
    bs.addBinding("predicate", vf.createURI("urn:tiresCount"));
    bs.addBinding("object", vf.createLiteral("4", XMLSchema.INTEGER));
    expected.add(new VisibilityBindingSet(bs, "a|b"));
    bs = new MapBindingSet();
    bs.addBinding("subject", petBNode);
    bs.addBinding("predicate", RDF.TYPE);
    bs.addBinding("object", vf.createURI("urn:pet"));
    expected.add(new VisibilityBindingSet(bs, "a|b"));
    bs = new MapBindingSet();
    bs.addBinding("subject", petBNode);
    bs.addBinding("predicate", vf.createURI("urn:isDead"));
    bs.addBinding("object", vf.createLiteral(false));
    expected.add(new VisibilityBindingSet(bs, "a|b"));
    assertEquals(expected, results);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Value(org.openrdf.model.Value) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) MultiProjection(org.openrdf.query.algebra.MultiProjection) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)140 Test (org.junit.Test)105 MapBindingSet (org.openrdf.query.impl.MapBindingSet)93 ValueFactory (org.openrdf.model.ValueFactory)66 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)66 HashSet (java.util.HashSet)52 ArrayList (java.util.ArrayList)31 UUID (java.util.UUID)28 VisibilityStatement (org.apache.rya.api.model.VisibilityStatement)28 TopologyFactory (org.apache.rya.streams.kafka.topology.TopologyFactory)24 BindingSet (org.openrdf.query.BindingSet)24 TopologyBuilder (org.apache.kafka.streams.processor.TopologyBuilder)23 RandomUUIDFactory (org.apache.rya.api.function.projection.RandomUUIDFactory)23 URIImpl (org.openrdf.model.impl.URIImpl)19 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)19 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)18 Bytes (org.apache.fluo.api.data.Bytes)16 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)15 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)12 Statement (org.openrdf.model.Statement)12