Search in sources :

Example 6 with RandomUUIDFactory

use of org.apache.rya.api.function.projection.RandomUUIDFactory in project incubator-rya by apache.

the class TopologyFactoryTest method projectionJoinJoinStatementPattern.

@Test
public void projectionJoinJoinStatementPattern() throws Exception {
    final String query = "SELECT * WHERE { " + "?person <urn:talksTo> ?otherPerson . " + "?otherPerson <urn:talksTo> ?dog . " + "?dog <urn:chews> ?toy . " + "}";
    FACTORY.build(query, "source", "sink", new RandomUUIDFactory());
    final List<ProcessorEntry> entries = FACTORY.getProcessorEntry();
    assertTrue(entries.get(0).getNode() instanceof Projection);
    assertTrue(entries.get(1).getNode() instanceof Join);
    assertTrue(entries.get(2).getNode() instanceof Join);
    StatementPattern expected = new StatementPattern(new Var("person"), TALKS_TO, new Var("otherPerson"));
    assertEquals(expected, entries.get(3).getNode());
    expected = new StatementPattern(new Var("otherPerson"), TALKS_TO, new Var("dog"));
    assertEquals(expected, entries.get(4).getNode());
    expected = new StatementPattern(new Var("dog"), CHEWS, new Var("toy"));
    assertEquals(expected, entries.get(5).getNode());
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) RandomUUIDFactory(org.apache.rya.api.function.projection.RandomUUIDFactory) Projection(org.openrdf.query.algebra.Projection) Join(org.openrdf.query.algebra.Join) ProcessorEntry(org.apache.rya.streams.kafka.topology.TopologyFactory.ProcessorEntry) Test(org.junit.Test)

Example 7 with RandomUUIDFactory

use of org.apache.rya.api.function.projection.RandomUUIDFactory in project incubator-rya by apache.

the class TopologyFactoryTest method projectionStatementPattern_rebind.

@Test
public void projectionStatementPattern_rebind() throws Exception {
    final String query = "CONSTRUCT { ?person <urn:mightKnow> ?otherPerson } WHERE { " + "?person <urn:talksTo> ?otherPerson . " + "}";
    FACTORY.build(query, "source", "sink", new RandomUUIDFactory());
    final List<ProcessorEntry> entries = FACTORY.getProcessorEntry();
    assertTrue(entries.get(0).getNode() instanceof Projection);
    final StatementPattern expected = new StatementPattern(new Var("person"), TALKS_TO, new Var("otherPerson"));
    assertEquals(expected, entries.get(1).getNode());
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) RandomUUIDFactory(org.apache.rya.api.function.projection.RandomUUIDFactory) Projection(org.openrdf.query.algebra.Projection) ProcessorEntry(org.apache.rya.streams.kafka.topology.TopologyFactory.ProcessorEntry) Test(org.junit.Test)

Example 8 with RandomUUIDFactory

use of org.apache.rya.api.function.projection.RandomUUIDFactory in project incubator-rya by apache.

the class AggregationProcessorIT method average.

@Test
public void average() throws Exception {
    // A query that figures out the average age across all people.
    final String sparql = "SELECT (avg(?age) as ?avgAge) " + "WHERE { " + "?person <urn:age> ?age " + "}";
    // 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:Alice"), vf.createURI("urn:age"), vf.createLiteral(3)), ""));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:age"), vf.createLiteral(7)), ""));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:age"), vf.createLiteral(2)), ""));
    // Make the expected results.
    final Set<VisibilityBindingSet> expected = new HashSet<>();
    MapBindingSet bs = new MapBindingSet();
    bs.addBinding("avgAge", vf.createLiteral("3", XMLSchema.DECIMAL));
    expected.add(new VisibilityBindingSet(bs, ""));
    bs = new MapBindingSet();
    bs.addBinding("avgAge", vf.createLiteral("5", XMLSchema.DECIMAL));
    expected.add(new VisibilityBindingSet(bs, ""));
    bs = new MapBindingSet();
    bs.addBinding("avgAge", vf.createLiteral("4", XMLSchema.DECIMAL));
    expected.add(new VisibilityBindingSet(bs, ""));
    // 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 TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
    // Run the test.
    RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityBindingSetDeserializer.class);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) TopologyBuilder(org.apache.kafka.streams.processor.TopologyBuilder) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ArrayList(java.util.ArrayList) ValueFactory(org.openrdf.model.ValueFactory) TopologyFactory(org.apache.rya.streams.kafka.topology.TopologyFactory) VisibilityStatement(org.apache.rya.api.model.VisibilityStatement) RandomUUIDFactory(org.apache.rya.api.function.projection.RandomUUIDFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) UUID(java.util.UUID) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with RandomUUIDFactory

use of org.apache.rya.api.function.projection.RandomUUIDFactory in project incubator-rya by apache.

the class AggregationProcessorIT method max.

@Test
public void max() throws Exception {
    // A query that figures out what the oldest age is across all people.
    final String sparql = "SELECT (max(?age) as ?oldest) " + "WHERE { " + "?person <urn:age> ?age " + "}";
    // 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:Alice"), vf.createURI("urn:age"), vf.createLiteral(13)), ""));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:age"), vf.createLiteral(14)), ""));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:age"), vf.createLiteral(7)), ""));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:David"), vf.createURI("urn:age"), vf.createLiteral(5)), ""));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Eve"), vf.createURI("urn:age"), vf.createLiteral(25)), ""));
    // Make the expected results.
    final Set<VisibilityBindingSet> expected = new HashSet<>();
    MapBindingSet bs = new MapBindingSet();
    bs.addBinding("oldest", vf.createLiteral(13));
    expected.add(new VisibilityBindingSet(bs, ""));
    bs = new MapBindingSet();
    bs.addBinding("oldest", vf.createLiteral(14));
    expected.add(new VisibilityBindingSet(bs, ""));
    bs = new MapBindingSet();
    bs.addBinding("oldest", vf.createLiteral(25));
    expected.add(new VisibilityBindingSet(bs, ""));
    // 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 TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
    // Run the test.
    RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityBindingSetDeserializer.class);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) TopologyBuilder(org.apache.kafka.streams.processor.TopologyBuilder) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ArrayList(java.util.ArrayList) ValueFactory(org.openrdf.model.ValueFactory) TopologyFactory(org.apache.rya.streams.kafka.topology.TopologyFactory) VisibilityStatement(org.apache.rya.api.model.VisibilityStatement) RandomUUIDFactory(org.apache.rya.api.function.projection.RandomUUIDFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) UUID(java.util.UUID) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with RandomUUIDFactory

use of org.apache.rya.api.function.projection.RandomUUIDFactory in project incubator-rya by apache.

the class AggregationProcessorIT method min.

@Test
public void min() throws Exception {
    // A query that figures out what the youngest age is across all people.
    final String sparql = "SELECT (min(?age) as ?youngest) " + "WHERE { " + "?person <urn:age> ?age " + "}";
    // 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:Alice"), vf.createURI("urn:age"), vf.createLiteral(13)), ""));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:age"), vf.createLiteral(14)), ""));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:age"), vf.createLiteral(7)), ""));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:David"), vf.createURI("urn:age"), vf.createLiteral(5)), ""));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Eve"), vf.createURI("urn:age"), vf.createLiteral(25)), ""));
    // Make the expected results.
    final Set<VisibilityBindingSet> expected = new HashSet<>();
    MapBindingSet bs = new MapBindingSet();
    bs.addBinding("youngest", vf.createLiteral(13));
    expected.add(new VisibilityBindingSet(bs, ""));
    bs = new MapBindingSet();
    bs.addBinding("youngest", vf.createLiteral(7));
    expected.add(new VisibilityBindingSet(bs, ""));
    bs = new MapBindingSet();
    bs.addBinding("youngest", vf.createLiteral(5));
    expected.add(new VisibilityBindingSet(bs, ""));
    // 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 TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
    // Run the test.
    RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityBindingSetDeserializer.class);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) TopologyBuilder(org.apache.kafka.streams.processor.TopologyBuilder) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ArrayList(java.util.ArrayList) ValueFactory(org.openrdf.model.ValueFactory) TopologyFactory(org.apache.rya.streams.kafka.topology.TopologyFactory) VisibilityStatement(org.apache.rya.api.model.VisibilityStatement) RandomUUIDFactory(org.apache.rya.api.function.projection.RandomUUIDFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) UUID(java.util.UUID) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

RandomUUIDFactory (org.apache.rya.api.function.projection.RandomUUIDFactory)29 Test (org.junit.Test)27 TopologyBuilder (org.apache.kafka.streams.processor.TopologyBuilder)25 HashSet (java.util.HashSet)23 UUID (java.util.UUID)23 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)23 VisibilityStatement (org.apache.rya.api.model.VisibilityStatement)23 TopologyFactory (org.apache.rya.streams.kafka.topology.TopologyFactory)23 ValueFactory (org.openrdf.model.ValueFactory)23 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)23 MapBindingSet (org.openrdf.query.impl.MapBindingSet)19 ArrayList (java.util.ArrayList)18 ProcessorEntry (org.apache.rya.streams.kafka.topology.TopologyFactory.ProcessorEntry)4 Projection (org.openrdf.query.algebra.Projection)4 StatementPattern (org.openrdf.query.algebra.StatementPattern)4 Var (org.openrdf.query.algebra.Var)4 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)4 Properties (java.util.Properties)2 KafkaStreams (org.apache.kafka.streams.KafkaStreams)2 StreamsConfig (org.apache.kafka.streams.StreamsConfig)2