Search in sources :

Example 1 with ProjectionProcessor

use of org.apache.rya.streams.kafka.processors.projection.ProjectionProcessorSupplier.ProjectionProcessor in project incubator-rya by apache.

the class ProjectionProcessorTest method showProjectionFunctionIsCalled.

@Test
public void showProjectionFunctionIsCalled() throws Exception {
    // A query whose projection does not change anything.
    final Projection projection = RdfTestUtil.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();
    final MapBindingSet inputBs = new MapBindingSet();
    inputBs.addBinding("person", vf.createURI("urn:Alice"));
    inputBs.addBinding("employee", vf.createURI("urn:Bob"));
    inputBs.addBinding("business", vf.createURI("urn:TacoJoint"));
    final VisibilityBindingSet inputVisBs = new VisibilityBindingSet(inputBs, "a");
    // The expected binding set changes the "person" binding name to "p" and "employee" to "e".
    final MapBindingSet expectedBs = new MapBindingSet();
    expectedBs.addBinding("p", vf.createURI("urn:Alice"));
    expectedBs.addBinding("e", vf.createURI("urn:Bob"));
    expectedBs.addBinding("business", vf.createURI("urn:TacoJoint"));
    final VisibilityBindingSet expectedVisBs = new VisibilityBindingSet(expectedBs, "a");
    // Show it resulted in the correct output BindingSet.
    final ProcessorContext context = mock(ProcessorContext.class);
    final ProjectionProcessor processor = new ProjectionProcessor(ProjectionEvaluator.make(projection), result -> ProcessorResult.make(new UnaryResult(result)));
    processor.init(context);
    processor.process("key", ProcessorResult.make(new UnaryResult(inputVisBs)));
    // Verify the expected binding set was emitted.
    final ProcessorResult expected = ProcessorResult.make(new UnaryResult(expectedVisBs));
    verify(context, times(1)).forward(eq("key"), eq(expected));
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ProcessorResult(org.apache.rya.streams.kafka.processors.ProcessorResult) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Projection(org.openrdf.query.algebra.Projection) UnaryResult(org.apache.rya.streams.kafka.processors.ProcessorResult.UnaryResult) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) ProjectionProcessor(org.apache.rya.streams.kafka.processors.projection.ProjectionProcessorSupplier.ProjectionProcessor) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) Test(org.junit.Test)

Aggregations

ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)1 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)1 ProcessorResult (org.apache.rya.streams.kafka.processors.ProcessorResult)1 UnaryResult (org.apache.rya.streams.kafka.processors.ProcessorResult.UnaryResult)1 ProjectionProcessor (org.apache.rya.streams.kafka.processors.projection.ProjectionProcessorSupplier.ProjectionProcessor)1 Test (org.junit.Test)1 ValueFactory (org.openrdf.model.ValueFactory)1 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)1 Projection (org.openrdf.query.algebra.Projection)1 MapBindingSet (org.openrdf.query.impl.MapBindingSet)1