Search in sources :

Example 11 with NumericLiteralImpl

use of org.openrdf.model.impl.NumericLiteralImpl 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 12 with NumericLiteralImpl

use of org.openrdf.model.impl.NumericLiteralImpl 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)

Example 13 with NumericLiteralImpl

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

the class PcjDocumentsIntegrationTest method createAndPopulatePcj.

/**
 * Ensure the method that creates a new PCJ table, scans Rya for matches, and
 * stores them in the PCJ table works.
 * <p>
 * The method being tested is: {@link PcjTables#createAndPopulatePcj(RepositoryConnection, Connector, String, String, String[], Optional)}
 */
@Test
public void createAndPopulatePcj() throws Exception {
    final MongoDBRyaDAO dao = new MongoDBRyaDAO();
    dao.setConf(new StatefulMongoDBRdfConfiguration(conf, getMongoClient()));
    dao.init();
    final RdfCloudTripleStore ryaStore = new RdfCloudTripleStore();
    ryaStore.setRyaDAO(dao);
    ryaStore.initialize();
    final SailRepositoryConnection ryaConn = new RyaSailRepository(ryaStore).getConnection();
    ryaConn.begin();
    try {
        // 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 " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
        final String pcjTableName = "testPcj";
        // Create and populate the PCJ table.
        final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
        pcjs.createAndPopulatePcj(ryaConn, pcjTableName, sparql);
        // 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);
        // Ensure the expected results match those that were stored.
        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);
        assertEquals(expected, fetchedResults);
    } finally {
        ryaConn.close();
        ryaStore.shutDown();
    }
}
Also used : RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) MapBindingSet(org.openrdf.query.impl.MapBindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) Statement(org.openrdf.model.Statement) RyaSailRepository(org.apache.rya.rdftriplestore.RyaSailRepository) URIImpl(org.openrdf.model.impl.URIImpl) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) MongoDBRyaDAO(org.apache.rya.mongodb.MongoDBRyaDAO) LiteralImpl(org.openrdf.model.impl.LiteralImpl) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) MapBindingSet(org.openrdf.query.impl.MapBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with NumericLiteralImpl

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

the class AccumuloIndexSetColumnVisibilityTest method init.

@BeforeClass
public static void init() throws AccumuloException, AccumuloSecurityException, PCJStorageException, IOException, InterruptedException, TableNotFoundException, AlreadyInitializedException, RyaDetailsRepositoryException {
    // Setup the mini accumulo instance used by the test.
    accumulo = startMiniAccumulo();
    accumulo.getZooKeepers();
    instance = accumulo.getInstanceName();
    zooKeepers = accumulo.getZooKeepers();
    conf = getConf();
    accCon.securityOperations().changeUserAuthorizations("root", new Authorizations("U", "USA"));
    // Initialize the Rya Details for the Rya instance.
    initRyaDetails();
    // Initialize a PCJ.
    storage = new AccumuloPcjStorage(accCon, ryaInstanceName);
    pcjId = storage.createPcj("SELECT ?name ?age " + "{" + "?name <http://hasAge> ?age ." + "?name <http://playsSport> \"Soccer\" " + "}");
    // Store the PCJ's results.
    pcjBs1 = new QueryBindingSet();
    pcjBs1.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
    pcjBs1.addBinding("name", new URIImpl("http://Alice"));
    pcjBs2 = new QueryBindingSet();
    pcjBs2.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
    pcjBs2.addBinding("name", new URIImpl("http://Bob"));
    final Set<VisibilityBindingSet> visBs = new HashSet<>();
    for (final BindingSet bs : Sets.<BindingSet>newHashSet(pcjBs1, pcjBs2)) {
        visBs.add(new VisibilityBindingSet(bs, "U|USA"));
    }
    storage.addResults(pcjId, visBs);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) Authorizations(org.apache.accumulo.core.security.Authorizations) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) URIImpl(org.openrdf.model.impl.URIImpl) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) HashSet(java.util.HashSet) BeforeClass(org.junit.BeforeClass)

Example 15 with NumericLiteralImpl

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

the class PcjTablesIT 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 Connector accumuloConn = cluster.getConnector();
    // Create a PCJ table in the Mini Accumulo.
    final String pcjTableName = new PcjTableNameFactory().makeTableName(getRyaInstanceName(), "testPcj");
    final Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(new VariableOrder("name;age"));
    final PcjTables pcjs = new PcjTables();
    pcjs.createPcjTable(accumuloConn, pcjTableName, varOrders, 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(accumuloConn, 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(accumuloConn, pcjTableName, new Authorizations());
    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 : Connector(org.apache.accumulo.core.client.Connector) MapBindingSet(org.openrdf.query.impl.MapBindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) Authorizations(org.apache.accumulo.core.security.Authorizations) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) URIImpl(org.openrdf.model.impl.URIImpl) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) MapBindingSet(org.openrdf.query.impl.MapBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)23 Test (org.junit.Test)22 URIImpl (org.openrdf.model.impl.URIImpl)22 HashSet (java.util.HashSet)19 BindingSet (org.openrdf.query.BindingSet)19 Statement (org.openrdf.model.Statement)15 LiteralImpl (org.openrdf.model.impl.LiteralImpl)15 StatementImpl (org.openrdf.model.impl.StatementImpl)15 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)12 PcjTableNameFactory (org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory)11 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)11 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)10 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)10 MapBindingSet (org.openrdf.query.impl.MapBindingSet)10 Connector (org.apache.accumulo.core.client.Connector)5 MongoDBRyaDAO (org.apache.rya.mongodb.MongoDBRyaDAO)3 StatefulMongoDBRdfConfiguration (org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration)3 RdfCloudTripleStore (org.apache.rya.rdftriplestore.RdfCloudTripleStore)3 RyaSailRepository (org.apache.rya.rdftriplestore.RyaSailRepository)3 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)3