Search in sources :

Example 6 with QueryBindingSet

use of org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.

the class AccumuloPcjSerializerTest method basicShortMixLiteralBsTest.

@Test
public void basicShortMixLiteralBsTest() throws BindingSetConversionException {
    final QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("X", VF.createLiteral("literal1"));
    bs.addBinding("Y", VF.createLiteral("5", VF.createIRI("http://www.w3.org/2001/XMLSchema#integer")));
    final VariableOrder varOrder = new VariableOrder("X", "Y");
    BindingSetConverter<byte[]> converter = new AccumuloPcjSerializer();
    final byte[] byteVal = converter.convert(bs, varOrder);
    final BindingSet newBs = converter.convert(byteVal, varOrder);
    assertEquals(bs, newBs);
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) MapBindingSet(org.eclipse.rdf4j.query.impl.MapBindingSet) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 7 with QueryBindingSet

use of org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.

the class AccumuloPcjSerializerTest method basicShortStringLiteralBsTest.

@Test
public void basicShortStringLiteralBsTest() throws BindingSetConversionException {
    final QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("X", VF.createLiteral("literal1"));
    bs.addBinding("Y", VF.createLiteral("literal2"));
    final VariableOrder varOrder = new VariableOrder("X", "Y");
    BindingSetConverter<byte[]> converter = new AccumuloPcjSerializer();
    final byte[] byteVal = converter.convert(bs, varOrder);
    final BindingSet newBs = converter.convert(byteVal, varOrder);
    assertEquals(bs, newBs);
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) MapBindingSet(org.eclipse.rdf4j.query.impl.MapBindingSet) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 8 with QueryBindingSet

use of org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.

the class BindingHashShardingFunctionTest method shardAddAndRemoveTest.

@Test
public void shardAddAndRemoveTest() {
    String nodeId = NodeType.generateNewFluoIdForType(NodeType.STATEMENT_PATTERN);
    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("entity", VF.createIRI("urn:entity"));
    bs.addBinding("location", VF.createLiteral("location_1"));
    VisibilityBindingSet vBs = new VisibilityBindingSet(bs);
    VariableOrder varOrder = new VariableOrder("entity", "location");
    Bytes row = RowKeyUtil.makeRowKey(nodeId, varOrder, vBs);
    Bytes shardedRow = BindingHashShardingFunction.addShard(nodeId, varOrder, vBs);
    Bytes shardlessRow = BindingHashShardingFunction.removeHash(Bytes.of(SP_PREFIX), shardedRow);
    Assert.assertEquals(row, shardlessRow);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 9 with QueryBindingSet

use of org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.

the class ConstructGraphTest method testConstructGraph.

@Test
public void testConstructGraph() throws MalformedQueryException, UnsupportedEncodingException {
    String query = "select ?x where { ?x <uri:talksTo> <uri:Bob>. ?y <uri:worksAt> ?z }";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
    ConstructGraph graph = new ConstructGraph(patterns);
    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("x", VF.createIRI("uri:Joe"));
    bs.addBinding("y", VF.createIRI("uri:Bob"));
    bs.addBinding("z", VF.createIRI("uri:BurgerShack"));
    VisibilityBindingSet vBs = new VisibilityBindingSet(bs, "FOUO");
    Set<RyaStatement> statements = graph.createGraphFromBindingSet(vBs);
    RyaStatement statement1 = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), new RyaIRI("uri:Bob"));
    RyaStatement statement2 = new RyaStatement(new RyaIRI("uri:Bob"), new RyaIRI("uri:worksAt"), new RyaIRI("uri:BurgerShack"));
    Set<RyaStatement> expected = Sets.newHashSet(Arrays.asList(statement1, statement2));
    expected.forEach(x -> x.setColumnVisibility("FOUO".getBytes()));
    ConstructGraphTestUtils.ryaStatementSetsEqualIgnoresTimestamp(expected, statements);
}
Also used : StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) RyaIRI(org.apache.rya.api.domain.RyaIRI) RyaStatement(org.apache.rya.api.domain.RyaStatement) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 10 with QueryBindingSet

use of org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.

the class ConstructGraphTest method testConstructGraphBNode.

@Test
public void testConstructGraphBNode() throws MalformedQueryException {
    String query = "select ?x where { _:b <uri:talksTo> ?x. _:b <uri:worksAt> ?z }";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
    ConstructGraph graph = new ConstructGraph(patterns);
    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("x", VF.createIRI("uri:Joe"));
    bs.addBinding("z", VF.createIRI("uri:BurgerShack"));
    VisibilityBindingSet vBs = new VisibilityBindingSet(bs, "FOUO");
    Set<RyaStatement> statements = graph.createGraphFromBindingSet(vBs);
    Set<RyaStatement> statements2 = graph.createGraphFromBindingSet(vBs);
    RyaIRI subject = null;
    for (RyaStatement statement : statements) {
        RyaIRI subjURI = statement.getSubject();
        if (subject == null) {
            subject = subjURI;
        } else {
            assertEquals(subjURI, subject);
        }
    }
    RyaIRI subject2 = null;
    for (RyaStatement statement : statements2) {
        RyaIRI subjURI = statement.getSubject();
        if (subject2 == null) {
            subject2 = subjURI;
        } else {
            assertEquals(subjURI, subject2);
        }
    }
    assertTrue(!subject.equals(subject2));
    ConstructGraphTestUtils.ryaStatementsEqualIgnoresBlankNode(statements, statements2);
}
Also used : StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) RyaIRI(org.apache.rya.api.domain.RyaIRI) RyaStatement(org.apache.rya.api.domain.RyaStatement) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Aggregations

QueryBindingSet (org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet)111 Test (org.junit.Test)84 BindingSet (org.eclipse.rdf4j.query.BindingSet)83 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)56 RyaIRI (org.apache.rya.api.domain.RyaIRI)46 RyaStatement (org.apache.rya.api.domain.RyaStatement)45 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)42 SPARQLParser (org.eclipse.rdf4j.query.parser.sparql.SPARQLParser)42 ParsedQuery (org.eclipse.rdf4j.query.parser.ParsedQuery)41 RyaType (org.apache.rya.api.domain.RyaType)39 ArrayList (java.util.ArrayList)30 HashSet (java.util.HashSet)28 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)26 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)20 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)16 StatementMetadataNode (org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode)15 Statement (org.eclipse.rdf4j.model.Statement)15 Value (org.eclipse.rdf4j.model.Value)14 Collection (java.util.Collection)13 BatchWriter (org.apache.accumulo.core.client.BatchWriter)12