use of org.apache.rya.api.domain.RyaSubGraph in project incubator-rya by apache.
the class KafkaRyaSubGraphExportIT method makeRyaSubGraphConsumer.
protected KafkaConsumer<String, RyaSubGraph> makeRyaSubGraphConsumer(final String TopicName) {
// setup consumer
final Properties consumerProps = new Properties();
consumerProps.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BROKERHOST + ":" + BROKERPORT);
consumerProps.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "group0");
consumerProps.setProperty(ConsumerConfig.CLIENT_ID_CONFIG, "consumer0");
consumerProps.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
consumerProps.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, RyaSubGraphKafkaSerDe.class.getName());
// to make sure the consumer starts from the beginning of the topic
consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
final KafkaConsumer<String, RyaSubGraph> consumer = new KafkaConsumer<>(consumerProps);
consumer.subscribe(Arrays.asList(TopicName));
return consumer;
}
use of org.apache.rya.api.domain.RyaSubGraph in project incubator-rya by apache.
the class KafkaRyaSubGraphExportIT method basicConstructQueryWithVis.
@Test
public void basicConstructQueryWithVis() throws Exception {
// A query that groups what is aggregated by one of the keys.
final String sparql = "CONSTRUCT { ?customer <urn:travelsTo> ?city . ?customer <urn:friendsWith> ?worker }" + "WHERE { " + "?customer <urn:talksTo> ?worker. " + "?worker <urn:livesIn> ?city. " + "?worker <urn:worksAt> <urn:burgerShack>. " + "}";
// Create the Statements that will be loaded into Rya.
RyaStatement statement1 = new RyaStatement(new RyaURI("urn:Joe"), new RyaURI("urn:talksTo"), new RyaURI("urn:Bob"));
RyaStatement statement2 = new RyaStatement(new RyaURI("urn:Bob"), new RyaURI("urn:livesIn"), new RyaURI("urn:London"));
RyaStatement statement3 = new RyaStatement(new RyaURI("urn:Bob"), new RyaURI("urn:worksAt"), new RyaURI("urn:burgerShack"));
statement1.setColumnVisibility("U&W".getBytes("UTF-8"));
statement2.setColumnVisibility("V".getBytes("UTF-8"));
statement3.setColumnVisibility("W".getBytes("UTF-8"));
// Create the PCJ in Fluo and load the statements into Rya.
final String pcjId = loadRyaStatements(sparql, Arrays.asList(statement1, statement2, statement3));
// Verify the end results of the query match the expected results.
final Set<RyaSubGraph> results = readAllResults(pcjId);
// Create the expected results of the SPARQL query once the PCJ has been
// computed.
final Set<RyaSubGraph> expectedResults = new HashSet<>();
RyaSubGraph subGraph = new RyaSubGraph(pcjId);
RyaStatement statement4 = new RyaStatement(new RyaURI("urn:Joe"), new RyaURI("urn:travelsTo"), new RyaURI("urn:London"));
RyaStatement statement5 = new RyaStatement(new RyaURI("urn:Joe"), new RyaURI("urn:friendsWith"), new RyaURI("urn:Bob"));
// if no visibility indicated, then visibilities set to empty byte in
// Fluo - they are null by default in RyaStatement
// need to set visibility to empty byte so that RyaStatement's equals
// will return true
statement4.setColumnVisibility("U&V&W".getBytes("UTF-8"));
statement5.setColumnVisibility("U&V&W".getBytes("UTF-8"));
Set<RyaStatement> stmnts = new HashSet<>(Arrays.asList(statement4, statement5));
subGraph.setStatements(stmnts);
expectedResults.add(subGraph);
ConstructGraphTestUtils.subGraphsEqualIgnoresTimestamp(expectedResults, results);
}
use of org.apache.rya.api.domain.RyaSubGraph in project incubator-rya by apache.
the class RyaSubGraphKafkaSerDeTest method serializationTestWithURI.
@Test
public void serializationTestWithURI() {
RyaSubGraph bundle = new RyaSubGraph(UUID.randomUUID().toString());
bundle.addStatement(new RyaStatement(new RyaURI("uri:123"), new RyaURI("uri:234"), new RyaURI("uri:345")));
bundle.addStatement(new RyaStatement(new RyaURI("uri:345"), new RyaURI("uri:567"), new RyaURI("uri:789")));
byte[] bundleBytes = serializer.toBytes(bundle);
RyaSubGraph deserializedBundle = serializer.fromBytes(bundleBytes);
assertEquals(bundle, deserializedBundle);
}
use of org.apache.rya.api.domain.RyaSubGraph in project incubator-rya by apache.
the class RyaSubGraphKafkaSerDeTest method serializationTestWithLiteral.
@Test
public void serializationTestWithLiteral() {
RyaSubGraph bundle = new RyaSubGraph(UUID.randomUUID().toString());
bundle.addStatement(new RyaStatement(new RyaURI("uri:123"), new RyaURI("uri:234"), new RyaType(XMLSchema.INTEGER, "345")));
bundle.addStatement(new RyaStatement(new RyaURI("uri:345"), new RyaURI("uri:567"), new RyaType(XMLSchema.INTEGER, "789")));
byte[] bundleBytes = serializer.toBytes(bundle);
RyaSubGraph deserializedBundle = serializer.fromBytes(bundleBytes);
assertEquals(bundle, deserializedBundle);
}
use of org.apache.rya.api.domain.RyaSubGraph in project incubator-rya by apache.
the class KafkaRyaSubGraphExporter method export.
/**
* Exports the RyaSubGraph to a Kafka topic equivalent to the result returned by {@link RyaSubGraph#getId()}
* @param subgraph - RyaSubGraph exported to Kafka
* @param contructID - rowID of result that is exported. Used for logging purposes.
*/
@Override
public void export(final String constructID, final RyaSubGraph subGraph) throws ResultExportException {
checkNotNull(constructID);
checkNotNull(subGraph);
try {
// Send the result to the topic whose name matches the PCJ ID.
final ProducerRecord<String, RyaSubGraph> rec = new ProducerRecord<>(subGraph.getId(), subGraph);
final Future<RecordMetadata> future = producer.send(rec);
// Don't let the export return until the result has been written to the topic. Otherwise we may lose results.
future.get();
log.debug("Producer successfully sent record with id: {} and statements: {}", constructID, subGraph.getStatements());
} catch (final Throwable e) {
throw new ResultExportException("A result could not be exported to Kafka.", e);
}
}
Aggregations