Search in sources :

Example 41 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class PcjTablesWithMockTest method populatePcj.

@Test
public void populatePcj() throws RepositoryException, PcjException, TableNotFoundException, BindingSetConversionException {
    // Load some Triples into Rya.
    final Set<Statement> triples = new HashSet<>();
    triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://hasAge"), new NumericLiteralImpl(14, XMLSchema.INTEGER)));
    triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
    triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://hasAge"), new NumericLiteralImpl(16, XMLSchema.INTEGER)));
    triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
    triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://hasAge"), new NumericLiteralImpl(12, XMLSchema.INTEGER)));
    triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
    triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://hasAge"), new NumericLiteralImpl(43, XMLSchema.INTEGER)));
    triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
    for (final Statement triple : triples) {
        ryaConn.add(triple);
    }
    // Create a PCJ table that will include those triples in its results.
    final String sparql = "SELECT ?name ?age " + "{" + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
    final String pcjTableName = new PcjTableNameFactory().makeTableName(RYA_TABLE_PREFIX, "testPcj");
    final PcjTables pcjs = new PcjTables();
    pcjs.createAndPopulatePcj(ryaConn, accumuloConn, pcjTableName, sparql, new String[] { "age", "name" }, Optional.<PcjVarOrderFactory>absent());
    // Make sure the cardinality was updated.
    final PcjMetadata metadata = pcjs.getPcjMetadata(accumuloConn, pcjTableName);
    assertEquals(4, metadata.getCardinality());
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) Statement(org.openrdf.model.Statement) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) URIImpl(org.openrdf.model.impl.URIImpl) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 42 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class MongoPcjDocumentsTest method metadataExists.

@Test
public void metadataExists() throws Exception {
    final List<VariableOrder> varOrders = Lists.newArrayList(new VariableOrder("b", "a"), new VariableOrder("a", "b"));
    final MongoPcjDocuments docConverter = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
    final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
    docConverter.createPcj("pcjTest", sparql);
    PcjMetadata actual = docConverter.getPcjMetadata("pcjTest");
    PcjMetadata expected = new PcjMetadata(sparql, 0, varOrders);
    assertEquals(expected, actual);
    // Setup the binding set that will be converted.
    final MapBindingSet originalBindingSet1 = new MapBindingSet();
    originalBindingSet1.addBinding("x", new URIImpl("http://a"));
    originalBindingSet1.addBinding("y", new URIImpl("http://b"));
    originalBindingSet1.addBinding("z", new URIImpl("http://c"));
    final VisibilityBindingSet results1 = new VisibilityBindingSet(originalBindingSet1, "A&B&C");
    // Setup the binding set that will be converted.
    final MapBindingSet originalBindingSet2 = new MapBindingSet();
    originalBindingSet2.addBinding("x", new URIImpl("http://1"));
    originalBindingSet2.addBinding("y", new URIImpl("http://2"));
    originalBindingSet2.addBinding("z", new URIImpl("http://3"));
    final VisibilityBindingSet results2 = new VisibilityBindingSet(originalBindingSet2, "A&B&C");
    final List<VisibilityBindingSet> bindingSets = new ArrayList<>();
    bindingSets.add(results1);
    bindingSets.add(results2);
    docConverter.addResults("pcjTest", bindingSets);
    actual = docConverter.getPcjMetadata("pcjTest");
    expected = new PcjMetadata(sparql, 2, varOrders);
    assertEquals(expected, actual);
    docConverter.purgePcjs("pcjTest");
    actual = docConverter.getPcjMetadata("pcjTest");
    expected = new PcjMetadata(sparql, 0, varOrders);
    assertEquals(expected, actual);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) ArrayList(java.util.ArrayList) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) URIImpl(org.openrdf.model.impl.URIImpl) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Example 43 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class PcjDocumentsIntegrationTest method listResults.

@Test
public void listResults() throws Exception {
    final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
    final String pcjTableName = "testPcj";
    final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
    pcjs.createPcj(pcjTableName, sparql);
    // Add a few results to the PCJ table.
    final MapBindingSet alice = new MapBindingSet();
    alice.addBinding("name", new URIImpl("http://Alice"));
    alice.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
    final MapBindingSet bob = new MapBindingSet();
    bob.addBinding("name", new URIImpl("http://Bob"));
    bob.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
    final MapBindingSet charlie = new MapBindingSet();
    charlie.addBinding("name", new URIImpl("http://Charlie"));
    charlie.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
    pcjs.addResults(pcjTableName, Sets.<VisibilityBindingSet>newHashSet(new VisibilityBindingSet(alice), new VisibilityBindingSet(bob), new VisibilityBindingSet(charlie)));
    // Fetch the Binding Sets that have been stored in the PCJ table.
    final Set<BindingSet> results = new HashSet<>();
    final CloseableIterator<BindingSet> resultsIt = pcjs.listResults(pcjTableName);
    try {
        while (resultsIt.hasNext()) {
            results.add(resultsIt.next());
        }
    } finally {
        resultsIt.close();
    }
    // Verify the fetched results match the expected ones.
    final Set<BindingSet> expected = Sets.<BindingSet>newHashSet(alice, bob, charlie);
    assertEquals(expected, results);
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) URIImpl(org.openrdf.model.impl.URIImpl) MapBindingSet(org.openrdf.query.impl.MapBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 44 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class PcjDocumentsIntegrationTest method purge.

@Test
public void purge() throws Exception {
    final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
    final String pcjTableName = "testPcj";
    final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
    pcjs.createPcj(pcjTableName, sparql);
    // Add a few results to the PCJ table.
    final MapBindingSet alice = new MapBindingSet();
    alice.addBinding("name", new URIImpl("http://Alice"));
    alice.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
    final MapBindingSet bob = new MapBindingSet();
    bob.addBinding("name", new URIImpl("http://Bob"));
    bob.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
    final MapBindingSet charlie = new MapBindingSet();
    charlie.addBinding("name", new URIImpl("http://Charlie"));
    charlie.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
    pcjs.addResults(pcjTableName, Sets.<VisibilityBindingSet>newHashSet(new VisibilityBindingSet(alice), new VisibilityBindingSet(bob), new VisibilityBindingSet(charlie)));
    // Make sure the cardinality was updated.
    PcjMetadata metadata = pcjs.getPcjMetadata(pcjTableName);
    assertEquals(3, metadata.getCardinality());
    // Purge the data.
    pcjs.purgePcjs(pcjTableName);
    // Make sure the cardinality was updated to 0.
    metadata = pcjs.getPcjMetadata(pcjTableName);
    assertEquals(0, metadata.getCardinality());
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) URIImpl(org.openrdf.model.impl.URIImpl) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Example 45 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class PcjDocumentsIntegrationTest method addResults.

/**
 * Ensure when results have been written to the PCJ table that they are in Accumulo.
 * <p>
 * The method being tested is {@link PcjTables#addResults(Connector, String, java.util.Collection)}
 */
@Test
public void addResults() throws Exception {
    final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
    final String pcjTableName = "testPcj";
    final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
    pcjs.createPcj(pcjTableName, sparql);
    // Add a few results to the PCJ table.
    final MapBindingSet alice = new MapBindingSet();
    alice.addBinding("name", new URIImpl("http://Alice"));
    alice.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
    final MapBindingSet bob = new MapBindingSet();
    bob.addBinding("name", new URIImpl("http://Bob"));
    bob.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
    final MapBindingSet charlie = new MapBindingSet();
    charlie.addBinding("name", new URIImpl("http://Charlie"));
    charlie.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
    final Set<BindingSet> expected = Sets.<BindingSet>newHashSet(alice, bob, charlie);
    pcjs.addResults(pcjTableName, Sets.<VisibilityBindingSet>newHashSet(new VisibilityBindingSet(alice), new VisibilityBindingSet(bob), new VisibilityBindingSet(charlie)));
    // Make sure the cardinality was updated.
    final PcjMetadata metadata = pcjs.getPcjMetadata(pcjTableName);
    assertEquals(3, metadata.getCardinality());
    // Scan Accumulo for the stored results.
    final Collection<BindingSet> fetchedResults = loadPcjResults(pcjTableName);
    assertEquals(expected, fetchedResults);
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) URIImpl(org.openrdf.model.impl.URIImpl) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Aggregations

URIImpl (org.openrdf.model.impl.URIImpl)165 Test (org.junit.Test)116 LiteralImpl (org.openrdf.model.impl.LiteralImpl)61 URI (org.openrdf.model.URI)58 BindingSet (org.openrdf.query.BindingSet)50 MapBindingSet (org.openrdf.query.impl.MapBindingSet)36 RyaURI (org.apache.rya.api.domain.RyaURI)33 HashSet (java.util.HashSet)31 Statement (org.openrdf.model.Statement)30 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)30 ArrayList (java.util.ArrayList)29 RyaType (org.apache.rya.api.domain.RyaType)25 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)24 RyaStatement (org.apache.rya.api.domain.RyaStatement)23 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)22 Value (org.openrdf.model.Value)21 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)21 StatementPattern (org.openrdf.query.algebra.StatementPattern)20 StatementImpl (org.openrdf.model.impl.StatementImpl)19 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)16