Search in sources :

Example 1 with FilterProcessor

use of org.apache.rya.streams.kafka.processors.filter.FilterProcessorSupplier.FilterProcessor in project incubator-rya by apache.

the class FilterProcessorTest method showFilterFunctionIsCalled.

@Test
public void showFilterFunctionIsCalled() throws Exception {
    // Read the filter object from a SPARQL query.
    final Filter filter = RdfTestUtil.getFilter("SELECT * " + "WHERE { " + "FILTER(?age < 10)" + "?person <urn:age> ?age " + "}");
    // Create a Binding Set that will be passed into the Filter function based on the where clause.
    final ValueFactory vf = new ValueFactoryImpl();
    final MapBindingSet bs = new MapBindingSet();
    bs.addBinding("person", vf.createURI("urn:Alice"));
    bs.addBinding("age", vf.createLiteral(9));
    final VisibilityBindingSet inputVisBs = new VisibilityBindingSet(bs, "a");
    // Mock the processor context that will be invoked.
    final ProcessorContext context = mock(ProcessorContext.class);
    // Run the test.
    final FilterProcessor processor = new FilterProcessor(FilterEvaluator.make(filter), result -> ProcessorResult.make(new UnaryResult(result)));
    processor.init(context);
    processor.process("key", ProcessorResult.make(new UnaryResult(inputVisBs)));
    // Verify the binding set was passed through.
    verify(context, times(1)).forward(eq("key"), eq(ProcessorResult.make(new UnaryResult(inputVisBs))));
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) Filter(org.openrdf.query.algebra.Filter) FilterProcessor(org.apache.rya.streams.kafka.processors.filter.FilterProcessorSupplier.FilterProcessor) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) UnaryResult(org.apache.rya.streams.kafka.processors.ProcessorResult.UnaryResult) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) 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 UnaryResult (org.apache.rya.streams.kafka.processors.ProcessorResult.UnaryResult)1 FilterProcessor (org.apache.rya.streams.kafka.processors.filter.FilterProcessorSupplier.FilterProcessor)1 Test (org.junit.Test)1 ValueFactory (org.openrdf.model.ValueFactory)1 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)1 Filter (org.openrdf.query.algebra.Filter)1 MapBindingSet (org.openrdf.query.impl.MapBindingSet)1