Search in sources :

Example 11 with RyaSubGraph

use of org.apache.rya.api.domain.RyaSubGraph in project incubator-rya by apache.

the class ConstructGraphTestUtils method subGraphsEqualIgnoresBlankNode.

public static void subGraphsEqualIgnoresBlankNode(Set<RyaSubGraph> subgraph1, Set<RyaSubGraph> subgraph2) {
    Map<Integer, RyaSubGraph> subGraphMap = new HashMap<>();
    for (RyaSubGraph subgraph : subgraph1) {
        int key = getKey(subgraph);
        subGraphMap.put(key, subgraph);
    }
    for (RyaSubGraph subgraph : subgraph2) {
        int key = getKey(subgraph);
        RyaSubGraph sub = subGraphMap.get(key);
        Preconditions.checkNotNull(sub);
        Set<RyaStatement> statements = sub.getStatements();
        ryaStatementsEqualIgnoresBlankNode(subgraph.getStatements(), statements);
    }
}
Also used : RyaSubGraph(org.apache.rya.api.domain.RyaSubGraph) HashMap(java.util.HashMap) RyaStatement(org.apache.rya.api.domain.RyaStatement)

Example 12 with RyaSubGraph

use of org.apache.rya.api.domain.RyaSubGraph in project incubator-rya by apache.

the class KafkaRyaSubGraphExportIT method basicConstructQuery.

@Test
public void basicConstructQuery() 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.
    final ValueFactory vf = new ValueFactoryImpl();
    final Collection<Statement> statements = Sets.newHashSet(vf.createStatement(vf.createURI("urn:Joe"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob")), vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:livesIn"), vf.createURI("urn:London")), vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:worksAt"), vf.createURI("urn:burgerShack")));
    // Create the PCJ in Fluo and load the statements into Rya.
    final String pcjId = loadStatements(sparql, statements);
    // Verify the end results of the query match the expected results.
    final Set<RyaSubGraph> results = readAllResults(pcjId);
    final Set<RyaSubGraph> expectedResults = new HashSet<>();
    RyaSubGraph subGraph = new RyaSubGraph(pcjId);
    RyaStatement statement1 = new RyaStatement(new RyaURI("urn:Joe"), new RyaURI("urn:travelsTo"), new RyaURI("urn:London"));
    RyaStatement statement2 = 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
    statement1.setColumnVisibility(new byte[0]);
    statement2.setColumnVisibility(new byte[0]);
    Set<RyaStatement> stmnts = new HashSet<>(Arrays.asList(statement1, statement2));
    subGraph.setStatements(stmnts);
    expectedResults.add(subGraph);
    ConstructGraphTestUtils.subGraphsEqualIgnoresTimestamp(expectedResults, results);
}
Also used : RyaSubGraph(org.apache.rya.api.domain.RyaSubGraph) RyaURI(org.apache.rya.api.domain.RyaURI) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactory(org.openrdf.model.ValueFactory) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with RyaSubGraph

use of org.apache.rya.api.domain.RyaSubGraph in project incubator-rya by apache.

the class KafkaRyaSubGraphExportIT method constructQueryWithVisAndMultipleSubGraphs.

@Test
public void constructQueryWithVisAndMultipleSubGraphs() 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"));
    RyaStatement statement4 = new RyaStatement(new RyaURI("urn:John"), new RyaURI("urn:talksTo"), new RyaURI("urn:Evan"));
    RyaStatement statement5 = new RyaStatement(new RyaURI("urn:Evan"), new RyaURI("urn:livesIn"), new RyaURI("urn:SanFrancisco"));
    RyaStatement statement6 = new RyaStatement(new RyaURI("urn:Evan"), 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"));
    statement4.setColumnVisibility("A&B".getBytes("UTF-8"));
    statement5.setColumnVisibility("B".getBytes("UTF-8"));
    statement6.setColumnVisibility("C".getBytes("UTF-8"));
    // Create the PCJ in Fluo and load the statements into Rya.
    final String pcjId = loadRyaStatements(sparql, Arrays.asList(statement1, statement2, statement3, statement4, statement5, statement6));
    // 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.
    RyaStatement statement7 = new RyaStatement(new RyaURI("urn:Joe"), new RyaURI("urn:travelsTo"), new RyaURI("urn:London"));
    RyaStatement statement8 = new RyaStatement(new RyaURI("urn:Joe"), new RyaURI("urn:friendsWith"), new RyaURI("urn:Bob"));
    RyaStatement statement9 = new RyaStatement(new RyaURI("urn:John"), new RyaURI("urn:travelsTo"), new RyaURI("urn:SanFrancisco"));
    RyaStatement statement10 = new RyaStatement(new RyaURI("urn:John"), new RyaURI("urn:friendsWith"), new RyaURI("urn:Evan"));
    statement7.setColumnVisibility("U&V&W".getBytes("UTF-8"));
    statement8.setColumnVisibility("U&V&W".getBytes("UTF-8"));
    statement9.setColumnVisibility("A&B&C".getBytes("UTF-8"));
    statement10.setColumnVisibility("A&B&C".getBytes("UTF-8"));
    final Set<RyaSubGraph> expectedResults = new HashSet<>();
    RyaSubGraph subGraph1 = new RyaSubGraph(pcjId);
    Set<RyaStatement> stmnts1 = new HashSet<>(Arrays.asList(statement7, statement8));
    subGraph1.setStatements(stmnts1);
    expectedResults.add(subGraph1);
    RyaSubGraph subGraph2 = new RyaSubGraph(pcjId);
    Set<RyaStatement> stmnts2 = new HashSet<>(Arrays.asList(statement9, statement10));
    subGraph2.setStatements(stmnts2);
    expectedResults.add(subGraph2);
    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 14 with RyaSubGraph

use of org.apache.rya.api.domain.RyaSubGraph in project incubator-rya by apache.

the class KafkaRyaSubGraphExportIT method constructQueryWithBlankNodesAndMultipleSubGraphs.

@Test
public void constructQueryWithBlankNodesAndMultipleSubGraphs() throws Exception {
    // A query that groups what is aggregated by one of the keys.
    final String sparql = "CONSTRUCT { _:b <urn:travelsTo> ?city . _:b <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"));
    RyaStatement statement4 = new RyaStatement(new RyaURI("urn:John"), new RyaURI("urn:talksTo"), new RyaURI("urn:Evan"));
    RyaStatement statement5 = new RyaStatement(new RyaURI("urn:Evan"), new RyaURI("urn:livesIn"), new RyaURI("urn:SanFrancisco"));
    RyaStatement statement6 = new RyaStatement(new RyaURI("urn:Evan"), 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"));
    statement4.setColumnVisibility("A&B".getBytes("UTF-8"));
    statement5.setColumnVisibility("B".getBytes("UTF-8"));
    statement6.setColumnVisibility("C".getBytes("UTF-8"));
    // Create the PCJ in Fluo and load the statements into Rya.
    final String pcjId = loadRyaStatements(sparql, Arrays.asList(statement1, statement2, statement3, statement4, statement5, statement6));
    // 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.
    RyaStatement statement7 = new RyaStatement(new RyaURI("urn:Joe"), new RyaURI("urn:travelsTo"), new RyaURI("urn:London"));
    RyaStatement statement8 = new RyaStatement(new RyaURI("urn:Joe"), new RyaURI("urn:friendsWith"), new RyaURI("urn:Bob"));
    RyaStatement statement9 = new RyaStatement(new RyaURI("urn:John"), new RyaURI("urn:travelsTo"), new RyaURI("urn:SanFrancisco"));
    RyaStatement statement10 = new RyaStatement(new RyaURI("urn:John"), new RyaURI("urn:friendsWith"), new RyaURI("urn:Evan"));
    statement7.setColumnVisibility("U&V&W".getBytes("UTF-8"));
    statement8.setColumnVisibility("U&V&W".getBytes("UTF-8"));
    statement9.setColumnVisibility("A&B&C".getBytes("UTF-8"));
    statement10.setColumnVisibility("A&B&C".getBytes("UTF-8"));
    final Set<RyaSubGraph> expectedResults = new HashSet<>();
    RyaSubGraph subGraph1 = new RyaSubGraph(pcjId);
    Set<RyaStatement> stmnts1 = new HashSet<>(Arrays.asList(statement7, statement8));
    subGraph1.setStatements(stmnts1);
    expectedResults.add(subGraph1);
    RyaSubGraph subGraph2 = new RyaSubGraph(pcjId);
    Set<RyaStatement> stmnts2 = new HashSet<>(Arrays.asList(statement9, statement10));
    subGraph2.setStatements(stmnts2);
    expectedResults.add(subGraph2);
    ConstructGraphTestUtils.subGraphsEqualIgnoresBlankNode(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 15 with RyaSubGraph

use of org.apache.rya.api.domain.RyaSubGraph in project incubator-rya by apache.

the class ExporterManager method exportSubGraph.

/**
 * Exports RyaSubGraph using the exporters for a given {@link QueryType}.
 * @param exporters - exporters corresponding to a given queryType
 * @param strategies - export strategies used to export results (possibly a subset of those in the exporters map)
 * @param pcjId - id of the query whose results are being exported
 * @param data - serialized RyaSubGraph result
 * @throws ResultExportException
 */
private void exportSubGraph(final Map<ExportStrategy, IncrementalResultExporter> exporters, final Set<ExportStrategy> strategies, final String pcjId, final Bytes data) throws ResultExportException {
    final RyaSubGraph subGraph = SG_SERDE.fromBytes(data.toArray());
    try {
        simplifyVisibilities(subGraph);
    } catch (final UnsupportedEncodingException e) {
        throw new ResultExportException("Undable to deserialize provided RyaSubgraph", e);
    }
    try {
        for (final ExportStrategy strategy : strategies) {
            final IncrementalRyaSubGraphExporter exporter = (IncrementalRyaSubGraphExporter) exporters.get(strategy);
            exporter.export(pcjId, subGraph);
        }
    } catch (final Exception e) {
        throw new ResultExportException("Unable to export the given subgraph " + subGraph + " using all of the ExportStrategies " + strategies);
    }
}
Also used : RyaSubGraph(org.apache.rya.api.domain.RyaSubGraph) ExportStrategy(org.apache.rya.api.client.CreatePCJ.ExportStrategy) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ResultExportException(org.apache.rya.indexing.pcj.fluo.app.export.IncrementalBindingSetExporter.ResultExportException) ResultExportException(org.apache.rya.indexing.pcj.fluo.app.export.IncrementalBindingSetExporter.ResultExportException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

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