Search in sources :

Example 21 with NumericLiteralImpl

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

the class AccumuloIndexSetTest method accumuloIndexSetTestWithTwoDirectProductBindingSetsWithMapping.

@Test
public void accumuloIndexSetTestWithTwoDirectProductBindingSetsWithMapping() throws RepositoryException, PcjException, TableNotFoundException, RyaTypeResolverException, MalformedQueryException, SailException, QueryEvaluationException, AccumuloException, AccumuloSecurityException {
    // 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 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 = new PcjTableNameFactory().makeTableName(prefix, "testPcj");
    // Create and populate the PCJ table.
    PcjIntegrationTestingUtil.createAndPopulatePcj(ryaConn, accumuloConn, pcjTableName, sparql, new String[] { "name", "age" }, Optional.<PcjVarOrderFactory>absent());
    final String sparql2 = "SELECT ?x ?y " + "{" + "FILTER(?y < 30) ." + "?x <http://hasAge> ?y." + "?x <http://playsSport> \"Soccer\" " + "}";
    final SPARQLParser p = new SPARQLParser();
    final ParsedQuery pq = p.parseQuery(sparql2, null);
    final Map<String, String> map = new HashMap<>();
    map.put("x", "name");
    map.put("y", "age");
    final AccumuloIndexSet ais = new AccumuloIndexSet(conf, pcjTableName);
    ais.setProjectionExpr((Projection) pq.getTupleExpr());
    ais.setTableVarMap(map);
    ais.setSupportedVariableOrderMap(Lists.<String>newArrayList("x;y", "y;x"));
    final QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("birthDate", new LiteralImpl("1983-03-17", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
    bs.addBinding("x", new URIImpl("http://Alice"));
    final QueryBindingSet bs2 = new QueryBindingSet();
    bs2.addBinding("birthDate", new LiteralImpl("1983-04-18", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
    bs2.addBinding("x", new URIImpl("http://Bob"));
    final Set<BindingSet> bSets = Sets.<BindingSet>newHashSet(bs, bs2);
    final CloseableIteration<BindingSet, QueryEvaluationException> results = ais.evaluate(bSets);
    final QueryBindingSet alice = new QueryBindingSet();
    alice.addBinding("x", new URIImpl("http://Alice"));
    alice.addBinding("y", new NumericLiteralImpl(14, XMLSchema.INTEGER));
    alice.addBinding("birthDate", new LiteralImpl("1983-03-17", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
    final QueryBindingSet bob = new QueryBindingSet();
    bob.addBinding("x", new URIImpl("http://Bob"));
    bob.addBinding("y", new NumericLiteralImpl(16, XMLSchema.INTEGER));
    bob.addBinding("birthDate", new LiteralImpl("1983-04-18", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
    final Set<BindingSet> fetchedResults = new HashSet<>();
    while (results.hasNext()) {
        final BindingSet next = results.next();
        System.out.println(next);
        fetchedResults.add(next);
    }
    Assert.assertEquals(Sets.<BindingSet>newHashSet(alice, bob), fetchedResults);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) HashMap(java.util.HashMap) Statement(org.openrdf.model.Statement) URIImpl(org.openrdf.model.impl.URIImpl) PcjTableNameFactory(org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with NumericLiteralImpl

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

the class AccumuloIndexSetTest method accumuloIndexSetTestWithNoBindingSet.

@Test
public void accumuloIndexSetTestWithNoBindingSet() throws RepositoryException, PcjException, TableNotFoundException, RyaTypeResolverException, MalformedQueryException, SailException, QueryEvaluationException, AccumuloException, AccumuloSecurityException {
    // 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 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 = new PcjTableNameFactory().makeTableName(prefix, "testPcj");
    // Create and populate the PCJ table.
    PcjIntegrationTestingUtil.createAndPopulatePcj(ryaConn, accumuloConn, pcjTableName, sparql, new String[] { "name", "age" }, Optional.<PcjVarOrderFactory>absent());
    final AccumuloIndexSet ais = new AccumuloIndexSet(conf, pcjTableName);
    final CloseableIteration<BindingSet, QueryEvaluationException> results = ais.evaluate(new HashSet<BindingSet>());
    Assert.assertEquals(false, results.hasNext());
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) URIImpl(org.openrdf.model.impl.URIImpl) PcjTableNameFactory(org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory) LiteralImpl(org.openrdf.model.impl.LiteralImpl) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with NumericLiteralImpl

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

the class AccumuloIndexSetTest method accumuloIndexSetTestAttemptJoinAccrossTypes.

@Test
public void accumuloIndexSetTestAttemptJoinAccrossTypes() throws Exception {
    // 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")));
    for (final Statement triple : triples) {
        ryaConn.add(triple);
    }
    // Create a PCJ table 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(prefix, "testPcj");
    // Create and populate the PCJ table.
    PcjIntegrationTestingUtil.createAndPopulatePcj(ryaConn, accumuloConn, pcjTableName, sparql, new String[] { "name", "age" }, Optional.<PcjVarOrderFactory>absent());
    final AccumuloIndexSet ais = new AccumuloIndexSet(conf, pcjTableName);
    final QueryBindingSet bs1 = new QueryBindingSet();
    bs1.addBinding("age", new LiteralImpl("16"));
    final QueryBindingSet bs2 = new QueryBindingSet();
    bs2.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
    final Set<BindingSet> bSets = Sets.<BindingSet>newHashSet(bs1, bs2);
    final CloseableIteration<BindingSet, QueryEvaluationException> results = ais.evaluate(bSets);
    final Set<BindingSet> fetchedResults = new HashSet<>();
    while (results.hasNext()) {
        final BindingSet next = results.next();
        fetchedResults.add(next);
    }
    bs2.addBinding("name", new URIImpl("http://Alice"));
    Assert.assertEquals(Sets.<BindingSet>newHashSet(bs2), fetchedResults);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) URIImpl(org.openrdf.model.impl.URIImpl) PcjTableNameFactory(org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) 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