use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class ProjectionEvaluatorTest method changesNothing.
/**
* This Projection enumerates all of the variables that were in the query, none of them are anonymous, and
* none of them insert constants.
*/
@Test
public void changesNothing() throws Exception {
// Read the projection object from a SPARQL query.
final Projection projection = getProjection("SELECT ?person ?employee ?business " + "WHERE { " + "?person <urn:talksTo> ?employee . " + "?employee <urn:worksAt> ?business . " + "}");
// Create a Binding Set that contains the result of the WHERE clause.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bs = new MapBindingSet();
bs.addBinding("person", vf.createURI("urn:Alice"));
bs.addBinding("employee", vf.createURI("urn:Bob"));
bs.addBinding("business", vf.createURI("urn:TacoJoint"));
final VisibilityBindingSet original = new VisibilityBindingSet(bs, "a|b");
// Execute the projection.
final VisibilityBindingSet result = ProjectionEvaluator.make(projection).project(original);
assertEquals(original, result);
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class ProjectionEvaluatorTest method addsConstantBinding.
/**
* This projection creates a Binding Set that represents a Statement and add a constant value to it.
*/
@Test
public void addsConstantBinding() throws Exception {
// Read the projection object from a SPARQL query.
final Projection projection = getProjection("CONSTRUCT { ?person <urn:hasGrandchild> ?grandchild } " + "WHERE {" + "?person <urn:hasChild> ?child ." + "?child <urn:hasChild> ?grandchild . " + "}");
// Create a Binding Set that contains the result of the WHERE clause.
final ValueFactory vf = new ValueFactoryImpl();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("person", vf.createURI("urn:Alice"));
bs.addBinding("child", vf.createURI("urn:Bob"));
bs.addBinding("grandchild", vf.createURI("urn:Charlie"));
final VisibilityBindingSet original = new VisibilityBindingSet(bs, "a|b");
// The expected binding set represents a statement.
bs = new MapBindingSet();
bs.addBinding("subject", vf.createURI("urn:Alice"));
bs.addBinding("predicate", vf.createURI("urn:hasGrandchild"));
bs.addBinding("object", vf.createURI("urn:Charlie"));
final VisibilityBindingSet expected = new VisibilityBindingSet(bs, "a|b");
// Execute the projection.
final VisibilityBindingSet result = ProjectionEvaluator.make(projection).project(original);
assertEquals(expected, result);
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class ProjectionEvaluatorTest method dropsBinding.
/**
* This projection drops a binding from the original Binding Set.
*/
@Test
public void dropsBinding() throws Exception {
// Read the projection object from a SPARQL query.
final Projection projection = getProjection("SELECT ?person " + "WHERE { " + "?person <urn:talksTo> ?employee . " + "?employee <urn:worksAt> ?business . " + "}");
// Create a Binding Set that contains the result of the WHERE clause.
final ValueFactory vf = new ValueFactoryImpl();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("person", vf.createURI("urn:Alice"));
bs.addBinding("employee", vf.createURI("urn:Bob"));
bs.addBinding("business", vf.createURI("urn:TacoJoint"));
final VisibilityBindingSet original = new VisibilityBindingSet(bs, "a|b");
// The expected binding set only has the "person" binding.
bs = new MapBindingSet();
bs.addBinding("person", vf.createURI("urn:Alice"));
final VisibilityBindingSet expected = new VisibilityBindingSet(bs, "a|b");
// Execute the projection.
final VisibilityBindingSet result = ProjectionEvaluator.make(projection).project(original);
assertEquals(expected, result);
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class ProjectionEvaluatorTest method renameBindings.
/**
* This Projection replaces some of the variables names with different names.
*/
@Test
public void renameBindings() throws Exception {
// Read the projection object from a SPARQL query.
final Projection projection = getProjection("SELECT (?person AS ?p) (?employee AS ?e) ?business " + "WHERE { " + "?person <urn:talksTo> ?employee . " + "?employee <urn:worksAt> ?business . " + "}");
// Create a Binding Set that contains the result of the WHERE clause.
final ValueFactory vf = new ValueFactoryImpl();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("person", vf.createURI("urn:Alice"));
bs.addBinding("employee", vf.createURI("urn:Bob"));
bs.addBinding("business", vf.createURI("urn:TacoJoint"));
final VisibilityBindingSet original = new VisibilityBindingSet(bs, "a|b");
// The expected binding set changes the "person" binding name to "p" and "employee" to "e".
bs = new MapBindingSet();
bs.addBinding("p", vf.createURI("urn:Alice"));
bs.addBinding("e", vf.createURI("urn:Bob"));
bs.addBinding("business", vf.createURI("urn:TacoJoint"));
final VisibilityBindingSet expected = new VisibilityBindingSet(bs, "a|b");
// Execute the projection.
final VisibilityBindingSet result = ProjectionEvaluator.make(projection).project(original);
assertEquals(expected, result);
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class ProjectionObserver method parseObservation.
@Override
public Observation parseObservation(final TransactionBase tx, final Bytes row) throws Exception {
requireNonNull(tx);
requireNonNull(row);
// Read the Filter metadata.
final String projectionNodeId = BindingSetRow.makeFromShardedRow(Bytes.of(PROJECTION_PREFIX), row).getNodeId();
final ProjectionMetadata projectionMetadata = queryDao.readProjectionMetadata(tx, projectionNodeId);
// Read the Visibility Binding Set from the value.
final Bytes valueBytes = tx.get(row, FluoQueryColumns.PROJECTION_BINDING_SET);
final VisibilityBindingSet projectionBindingSet = BS_SERDE.deserialize(valueBytes);
// Figure out which node needs to handle the new metadata.
final String parentNodeId = projectionMetadata.getParentNodeId();
return new Observation(projectionNodeId, projectionBindingSet, parentNodeId);
}
Aggregations