use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class GeoFilterIT method showProcessorWorks.
@Test
public void showProcessorWorks() throws Exception {
// Enumerate some topics that will be re-used
final String ryaInstance = UUID.randomUUID().toString();
final UUID queryId = UUID.randomUUID();
final String statementsTopic = KafkaTopics.statementsTopic(ryaInstance);
final String resultsTopic = KafkaTopics.queryResultsTopic(ryaInstance, queryId);
// Get the RDF model objects that will be used to build the query.
final String sparql = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "PREFIX geof: <" + GEO + ">\n" + "SELECT * \n" + "WHERE { \n" + " <urn:event1> geo:asWKT ?point .\n" + " FILTER(geof:sfWithin(?point, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " + "}";
// Setup a topology.
final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
// Create the statements that will be input into the query.
final ValueFactory vf = new ValueFactoryImpl();
final List<VisibilityStatement> statements = getStatements();
// Make the expected results.
final Set<VisibilityBindingSet> expected = new HashSet<>();
final MapBindingSet bs = new MapBindingSet();
final WKTWriter w = new WKTWriter();
bs.addBinding("point", vf.createLiteral(w.write(ZERO), GeoConstants.XMLSCHEMA_OGC_WKT));
expected.add(new VisibilityBindingSet(bs, "a"));
// Run the test.
RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityBindingSetDeserializer.class);
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class FilterProcessorIT method showProcessorWorks.
@Test
public void showProcessorWorks() throws Exception {
// Enumerate some topics that will be re-used
final String ryaInstance = UUID.randomUUID().toString();
final UUID queryId = UUID.randomUUID();
final String statementsTopic = KafkaTopics.statementsTopic(ryaInstance);
final String resultsTopic = KafkaTopics.queryResultsTopic(ryaInstance, queryId);
// Get the RDF model objects that will be used to build the query.
final String sparql = "SELECT * " + "WHERE { " + "FILTER(?age < 10)" + "?person <urn:age> ?age " + "}";
// Setup a topology.
final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
// Create the statements that will be input into the query.
final ValueFactory vf = new ValueFactoryImpl();
final List<VisibilityStatement> statements = new ArrayList<>();
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:age"), vf.createLiteral(11)), "a"));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:age"), vf.createLiteral(9)), "a"));
// Make the expected results.
final Set<VisibilityBindingSet> expected = new HashSet<>();
final MapBindingSet bs = new MapBindingSet();
bs.addBinding("person", vf.createURI("urn:Alice"));
bs.addBinding("age", vf.createLiteral(9));
expected.add(new VisibilityBindingSet(bs, "a"));
// Run the test.
RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityBindingSetDeserializer.class);
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class TemporalFilterIT method showAfterWorks.
@Test
public void showAfterWorks() throws Exception {
// Enumerate some topics that will be re-used
final String ryaInstance = UUID.randomUUID().toString();
final UUID queryId = UUID.randomUUID();
final String statementsTopic = KafkaTopics.statementsTopic(ryaInstance);
final String resultsTopic = KafkaTopics.queryResultsTopic(ryaInstance, queryId);
// Get the RDF model objects that will be used to build the query.
final String sparql = "PREFIX time: <http://www.w3.org/2006/time/> \n" + "PREFIX tempf: <" + TemporalURIs.NAMESPACE + ">\n" + "SELECT * \n" + "WHERE { \n" + " <urn:time> time:atTime ?date .\n" + " FILTER(tempf:after(?date, \"" + TIME_10.toString() + "\")) " + "}";
// Setup a topology.
final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
// Create the statements that will be input into the query.
final ValueFactory vf = new ValueFactoryImpl();
final List<VisibilityStatement> statements = getStatements();
// Make the expected results.
final Set<VisibilityBindingSet> expected = new HashSet<>();
final MapBindingSet bs = new MapBindingSet();
bs.addBinding("date", vf.createLiteral(TIME_20.toString()));
expected.add(new VisibilityBindingSet(bs, "a"));
// Run the test.
RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityBindingSetDeserializer.class);
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class StatementPatternProcessorIT method singlePattern_manyStatements.
@Test
public void singlePattern_manyStatements() throws Exception {
// Enumerate some topics that will be re-used
final String ryaInstance = UUID.randomUUID().toString();
final UUID queryId = UUID.randomUUID();
final String statementsTopic = KafkaTopics.statementsTopic(ryaInstance);
final String resultsTopic = KafkaTopics.queryResultsTopic(ryaInstance, queryId);
// Setup a topology.
final String query = "SELECT * WHERE { ?person <urn:talksTo> ?otherPerson }";
final TopologyFactory factory = new TopologyFactory();
final TopologyBuilder builder = factory.build(query, statementsTopic, resultsTopic, new RandomUUIDFactory());
// Create some statements where some generates SP results and others do not.
final ValueFactory vf = new ValueFactoryImpl();
final List<VisibilityStatement> statements = new ArrayList<>();
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob")), "a"));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:worksAt"), vf.createURI("urn:TacoJoin")), "b"));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:talksTo"), vf.createURI("urn:Alice")), "a|b"));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:worksAt"), vf.createURI("urn:BurgerJoint")), "c"));
// Show the correct binding set results from the job.
final Set<VisibilityBindingSet> expected = new HashSet<>();
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("person", vf.createURI("urn:Alice"));
bs.addBinding("otherPerson", vf.createURI("urn:Bob"));
expected.add(new VisibilityBindingSet(bs, "a"));
bs = new QueryBindingSet();
bs.addBinding("person", vf.createURI("urn:Bob"));
bs.addBinding("otherPerson", vf.createURI("urn:Alice"));
expected.add(new VisibilityBindingSet(bs, "a|b"));
// Run the test.
RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityBindingSetDeserializer.class);
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class BindingSetOutputFormatterTest method binaryResult.
@Test
public void binaryResult() {
// Create the input binding set.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bindingSet = new MapBindingSet();
bindingSet.addBinding("person", vf.createURI("urn:Alice"));
bindingSet.addBinding("age", vf.createLiteral(34));
final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
// Mock the processor context that will be invoked.
final ProcessorContext context = mock(ProcessorContext.class);
// Run the test.
final BindingSetOutputFormatter formatter = new BindingSetOutputFormatter();
formatter.init(context);
formatter.process("key", ProcessorResult.make(new BinaryResult(Side.LEFT, visBs)));
// Verify the mock was invoked with the expected output.
verify(context, times(1)).forward(eq("key"), eq(visBs));
}
Aggregations