Search in sources :

Example 6 with MapBindingSet

use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.

the class StatementOutputFormatterTest method missingObject.

@Test
public void missingObject() {
    // Create the input binding set.
    final ValueFactory vf = new ValueFactoryImpl();
    final MapBindingSet bindingSet = new MapBindingSet();
    bindingSet.addBinding("subject", vf.createURI("urn:Alice"));
    bindingSet.addBinding("predicate", vf.createURI("urn:age"));
    final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
    // Mock the processor context that will be invoked.
    final ProcessorContext context = mock(ProcessorContext.class);
    // Run the test.
    final StatementOutputFormatter formatter = new StatementOutputFormatter();
    formatter.init(context);
    formatter.process("key", ProcessorResult.make(new UnaryResult(visBs)));
    // Verify the mock was never invoked.
    verify(context, times(0)).forward(any(), any());
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) StatementOutputFormatter(org.apache.rya.streams.kafka.processors.output.StatementOutputFormatterSupplier.StatementOutputFormatter) UnaryResult(org.apache.rya.streams.kafka.processors.ProcessorResult.UnaryResult) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) Test(org.junit.Test)

Example 7 with MapBindingSet

use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.

the class StatementOutputFormatterTest method binaryResult.

@Test
public void binaryResult() {
    // Create the input binding set.
    final ValueFactory vf = new ValueFactoryImpl();
    final MapBindingSet bindingSet = new MapBindingSet();
    bindingSet.addBinding("subject", vf.createURI("urn:Alice"));
    bindingSet.addBinding("predicate", vf.createURI("urn:age"));
    bindingSet.addBinding("object", vf.createLiteral(34));
    final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
    // Mock the processor context that will be invoked.
    final ProcessorContext context = mock(ProcessorContext.class);
    // Run the test.
    final StatementOutputFormatter formatter = new StatementOutputFormatter();
    formatter.init(context);
    formatter.process("key", ProcessorResult.make(new BinaryResult(Side.LEFT, visBs)));
    // Verify the mock was invoked with the expected output.
    final VisibilityStatement expectedStmt = new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:age"), vf.createLiteral(34)), "a");
    verify(context, times(1)).forward(eq("key"), eq(expectedStmt));
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) StatementOutputFormatter(org.apache.rya.streams.kafka.processors.output.StatementOutputFormatterSupplier.StatementOutputFormatter) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) VisibilityStatement(org.apache.rya.api.model.VisibilityStatement) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) BinaryResult(org.apache.rya.streams.kafka.processors.ProcessorResult.BinaryResult) Test(org.junit.Test)

Example 8 with MapBindingSet

use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.

the class StatementOutputFormatterTest method unaryResult.

@Test
public void unaryResult() {
    // Create the input binding set.
    final ValueFactory vf = new ValueFactoryImpl();
    final MapBindingSet bindingSet = new MapBindingSet();
    bindingSet.addBinding("subject", vf.createURI("urn:Alice"));
    bindingSet.addBinding("predicate", vf.createURI("urn:age"));
    bindingSet.addBinding("object", vf.createLiteral(34));
    final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
    // Mock the processor context that will be invoked.
    final ProcessorContext context = mock(ProcessorContext.class);
    // Run the test.
    final StatementOutputFormatter formatter = new StatementOutputFormatter();
    formatter.init(context);
    formatter.process("key", ProcessorResult.make(new UnaryResult(visBs)));
    // Verify the mock was invoked with the expected output.
    final VisibilityStatement expectedStmt = new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:age"), vf.createLiteral(34)), "a");
    verify(context, times(1)).forward(eq("key"), eq(expectedStmt));
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) StatementOutputFormatter(org.apache.rya.streams.kafka.processors.output.StatementOutputFormatterSupplier.StatementOutputFormatter) UnaryResult(org.apache.rya.streams.kafka.processors.ProcessorResult.UnaryResult) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) VisibilityStatement(org.apache.rya.api.model.VisibilityStatement) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) Test(org.junit.Test)

Example 9 with MapBindingSet

use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.

the class AccumuloBatchUpdatePCJIT method batchUpdate.

@Test
public void batchUpdate() throws Exception {
    // Setup a Rya Client.
    final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(super.getUsername(), super.getPassword().toCharArray(), super.getInstanceName(), super.getZookeepers());
    final RyaClient ryaClient = AccumuloRyaClientFactory.build(connectionDetails, super.getConnector());
    // Install an instance of Rya on the mini accumulo cluster.
    ryaClient.getInstall().install(RYA_INSTANCE_NAME, InstallConfiguration.builder().setEnablePcjIndex(true).build());
    Sail sail = null;
    try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(super.getConnector(), RYA_INSTANCE_NAME)) {
        // Get a Sail connection backed by the installed Rya instance.
        final AccumuloRdfConfiguration ryaConf = new AccumuloRdfConfiguration();
        ryaConf.setTablePrefix(RYA_INSTANCE_NAME);
        ryaConf.set(ConfigUtils.CLOUDBASE_USER, super.getUsername());
        ryaConf.set(ConfigUtils.CLOUDBASE_PASSWORD, super.getPassword());
        ryaConf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, super.getZookeepers());
        ryaConf.set(ConfigUtils.CLOUDBASE_INSTANCE, super.getInstanceName());
        ryaConf.set(ConfigUtils.USE_PCJ, "true");
        ryaConf.set(ConfigUtils.PCJ_STORAGE_TYPE, PrecomputedJoinStorageType.ACCUMULO.toString());
        ryaConf.set(ConfigUtils.PCJ_UPDATER_TYPE, PrecomputedJoinUpdaterType.NO_UPDATE.toString());
        sail = RyaSailFactory.getInstance(ryaConf);
        // Load some statements into the Rya instance.
        final ValueFactory vf = sail.getValueFactory();
        final SailConnection sailConn = sail.getConnection();
        sailConn.begin();
        sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:Bob"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:David"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:Eve"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:Frank"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:George"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:Hillary"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
        sailConn.addStatement(vf.createURI("urn:Bob"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
        sailConn.addStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
        sailConn.addStatement(vf.createURI("urn:David"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
        sailConn.addStatement(vf.createURI("urn:Eve"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
        sailConn.addStatement(vf.createURI("urn:Frank"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
        sailConn.addStatement(vf.createURI("urn:George"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:green"));
        sailConn.addStatement(vf.createURI("urn:Hillary"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:brown"));
        sailConn.commit();
        sailConn.close();
        // Create a PCJ for a SPARQL query.
        final String sparql = "SELECT ?name WHERE { ?name <urn:likes> <urn:icecream> . ?name <urn:hasEyeColor> <urn:blue> . }";
        final String pcjId = pcjStorage.createPcj(sparql);
        // Run the test.
        ryaClient.getBatchUpdatePCJ().batchUpdate(RYA_INSTANCE_NAME, pcjId);
        // Verify the correct results were loaded into the PCJ table.
        final Set<BindingSet> expectedResults = new HashSet<>();
        MapBindingSet bs = new MapBindingSet();
        bs.addBinding("name", vf.createURI("urn:Alice"));
        expectedResults.add(bs);
        bs = new MapBindingSet();
        bs.addBinding("name", vf.createURI("urn:Bob"));
        expectedResults.add(bs);
        bs = new MapBindingSet();
        bs.addBinding("name", vf.createURI("urn:Charlie"));
        expectedResults.add(bs);
        bs = new MapBindingSet();
        bs.addBinding("name", vf.createURI("urn:David"));
        expectedResults.add(bs);
        bs = new MapBindingSet();
        bs.addBinding("name", vf.createURI("urn:Eve"));
        expectedResults.add(bs);
        bs = new MapBindingSet();
        bs.addBinding("name", vf.createURI("urn:Frank"));
        expectedResults.add(bs);
        final Set<BindingSet> results = new HashSet<>();
        try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
            while (resultsIt.hasNext()) {
                results.add(resultsIt.next());
            }
        }
        assertEquals(expectedResults, results);
    } finally {
        if (sail != null) {
            sail.shutDown();
        }
    }
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) RyaClient(org.apache.rya.api.client.RyaClient) ValueFactory(org.openrdf.model.ValueFactory) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) SailConnection(org.openrdf.sail.SailConnection) Sail(org.openrdf.sail.Sail) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MapBindingSet(org.openrdf.query.impl.MapBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with MapBindingSet

use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.

the class AccumuloDeletePCJIT method deletePCJ.

@Test
public void deletePCJ() throws InstanceDoesNotExistException, RyaClientException, PCJStorageException, RepositoryException {
    // Initialize the commands that will be used by this test.
    final CreatePCJ createPCJ = new AccumuloCreatePCJ(createConnectionDetails(), accumuloConn);
    // Create a PCJ.
    final String sparql = "SELECT ?x " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?x <http://worksAt> <http://TacoJoint>." + "}";
    final String pcjId = createPCJ.createPCJ(getRyaInstanceName(), sparql);
    // Verify a Query ID was added for the query within the Fluo app.
    List<String> fluoQueryIds = new ListQueryIds().listQueryIds(fluoClient);
    assertEquals(1, fluoQueryIds.size());
    // Insert some statements into Rya.
    final ValueFactory vf = ryaRepo.getValueFactory();
    ryaConn.add(vf.createURI("http://Alice"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
    ryaConn.add(vf.createURI("http://Bob"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
    ryaConn.add(vf.createURI("http://Charlie"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
    ryaConn.add(vf.createURI("http://Eve"), vf.createURI("http://helps"), vf.createURI("http://Kevin"));
    ryaConn.add(vf.createURI("http://Bob"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
    ryaConn.add(vf.createURI("http://Charlie"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
    ryaConn.add(vf.createURI("http://Eve"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
    ryaConn.add(vf.createURI("http://David"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
    // Verify the correct results were exported.
    fluo.waitForObservers();
    try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumuloConn, getRyaInstanceName())) {
        final Set<BindingSet> results = Sets.newHashSet(pcjStorage.listResults(pcjId));
        final MapBindingSet bob = new MapBindingSet();
        bob.addBinding("x", vf.createURI("http://Bob"));
        final MapBindingSet charlie = new MapBindingSet();
        charlie.addBinding("x", vf.createURI("http://Charlie"));
        final Set<BindingSet> expected = Sets.<BindingSet>newHashSet(bob, charlie);
        assertEquals(expected, results);
        // Delete the PCJ.
        final DeletePCJ deletePCJ = new AccumuloDeletePCJ(createConnectionDetails(), accumuloConn);
        deletePCJ.deletePCJ(getRyaInstanceName(), pcjId);
        // Ensure the PCJ's metadata has been removed from the storage.
        assertTrue(pcjStorage.listPcjs().isEmpty());
        // Ensure the PCJ has been removed from the Fluo application.
        fluo.waitForObservers();
        // Verify a Query ID was added for the query within the Fluo app.
        fluoQueryIds = new ListQueryIds().listQueryIds(fluoClient);
        assertEquals(0, fluoQueryIds.size());
    }
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) CreatePCJ(org.apache.rya.api.client.CreatePCJ) ValueFactory(org.openrdf.model.ValueFactory) ListQueryIds(org.apache.rya.indexing.pcj.fluo.api.ListQueryIds) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MapBindingSet(org.openrdf.query.impl.MapBindingSet) DeletePCJ(org.apache.rya.api.client.DeletePCJ) Test(org.junit.Test)

Aggregations

MapBindingSet (org.openrdf.query.impl.MapBindingSet)174 Test (org.junit.Test)155 ValueFactory (org.openrdf.model.ValueFactory)99 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)96 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)91 BindingSet (org.openrdf.query.BindingSet)84 HashSet (java.util.HashSet)81 Statement (org.openrdf.model.Statement)43 URIImpl (org.openrdf.model.impl.URIImpl)31 ArrayList (java.util.ArrayList)30 VisibilityStatement (org.apache.rya.api.model.VisibilityStatement)24 UUID (java.util.UUID)23 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)20 TopologyFactory (org.apache.rya.streams.kafka.topology.TopologyFactory)20 TopologyBuilder (org.apache.kafka.streams.processor.TopologyBuilder)19 RandomUUIDFactory (org.apache.rya.api.function.projection.RandomUUIDFactory)19 Connector (org.apache.accumulo.core.client.Connector)18 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)16 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)15 RyaURI (org.apache.rya.api.domain.RyaURI)14