Search in sources :

Example 6 with RyaSubGraph

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;
}
Also used : RyaSubGraphKafkaSerDe(org.apache.rya.indexing.pcj.fluo.app.export.kafka.RyaSubGraphKafkaSerDe) RyaSubGraph(org.apache.rya.api.domain.RyaSubGraph) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) Properties(java.util.Properties)

Example 7 with RyaSubGraph

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);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaSubGraph(org.apache.rya.api.domain.RyaSubGraph) RyaStatement(org.apache.rya.api.domain.RyaStatement) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with RyaSubGraph

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);
}
Also used : RyaSubGraph(org.apache.rya.api.domain.RyaSubGraph) RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) Test(org.junit.Test)

Example 9 with RyaSubGraph

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);
}
Also used : RyaSubGraph(org.apache.rya.api.domain.RyaSubGraph) RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

Example 10 with RyaSubGraph

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);
    }
}
Also used : RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) RyaSubGraph(org.apache.rya.api.domain.RyaSubGraph) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) ResultExportException(org.apache.rya.indexing.pcj.fluo.app.export.IncrementalBindingSetExporter.ResultExportException)

Aggregations

RyaSubGraph (org.apache.rya.api.domain.RyaSubGraph)15 RyaStatement (org.apache.rya.api.domain.RyaStatement)10 RyaURI (org.apache.rya.api.domain.RyaURI)7 Test (org.junit.Test)7 HashSet (java.util.HashSet)5 RyaType (org.apache.rya.api.domain.RyaType)2 ResultExportException (org.apache.rya.indexing.pcj.fluo.app.export.IncrementalBindingSetExporter.ResultExportException)2 Statement (org.openrdf.model.Statement)2 ValueFactory (org.openrdf.model.ValueFactory)2 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 Bytes (org.apache.fluo.api.data.Bytes)1 Column (org.apache.fluo.api.data.Column)1 KafkaConsumer (org.apache.kafka.clients.consumer.KafkaConsumer)1 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)1 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)1 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)1