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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations