Search in sources :

Example 11 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.

the class OpTriple method asBGP.

public final OpBGP asBGP() {
    if (opBGP == null) {
        BasicPattern bp = new BasicPattern();
        bp.add(getTriple());
        opBGP = new OpBGP(bp);
    }
    return opBGP;
}
Also used : BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 12 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.

the class OpRewriterTest method testBGP.

@Test
public void testBGP() {
    SecurityEvaluator securityEvaluator = new MockSecurityEvaluator(true, true, true, true, true, true);
    rewriter = new OpRewriter(securityEvaluator, "http://example.com/dummy");
    rewriter.visit(new OpBGP(BasicPattern.wrap(Arrays.asList(triples))));
    Op op = rewriter.getResult();
    Assert.assertTrue("Should have been an OpFilter", op instanceof OpFilter);
    OpFilter filter = (OpFilter) op;
    ExprList eLst = filter.getExprs();
    Assert.assertEquals(1, eLst.size());
    Assert.assertTrue("Should have been a SecuredFunction", eLst.get(0) instanceof SecuredFunction);
    op = filter.getSubOp();
    Assert.assertTrue("Should have been a OpBGP", op instanceof OpBGP);
    BasicPattern basicPattern = ((OpBGP) op).getPattern();
    Assert.assertEquals(3, basicPattern.size());
    Triple t = basicPattern.get(0);
    Assert.assertEquals(NodeFactory.createVariable("foo"), t.getSubject());
    Assert.assertEquals(RDF.type.asNode(), t.getPredicate());
    Assert.assertEquals(NodeFactory.createURI("http://example.com/class"), t.getObject());
    t = basicPattern.get(1);
    Assert.assertEquals(NodeFactory.createVariable("foo"), t.getSubject());
    Assert.assertTrue("Should have been blank", t.getPredicate().isBlank());
    Assert.assertEquals(NodeFactory.createVariable("bar"), t.getObject());
    t = basicPattern.get(2);
    Assert.assertEquals(NodeFactory.createVariable("bar"), t.getSubject());
    Assert.assertTrue("Should have been blank", t.getPredicate().isBlank());
    Assert.assertEquals(NodeFactory.createVariable("baz"), t.getObject());
}
Also used : Triple(org.apache.jena.graph.Triple) Op(org.apache.jena.sparql.algebra.Op) SecuredFunction(org.apache.jena.permissions.query.rewriter.SecuredFunction) ExprList(org.apache.jena.sparql.expr.ExprList) MockSecurityEvaluator(org.apache.jena.permissions.MockSecurityEvaluator) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) SecurityEvaluator(org.apache.jena.permissions.SecurityEvaluator) MockSecurityEvaluator(org.apache.jena.permissions.MockSecurityEvaluator) BasicPattern(org.apache.jena.sparql.core.BasicPattern) OpFilter(org.apache.jena.sparql.algebra.op.OpFilter) OpRewriter(org.apache.jena.permissions.query.rewriter.OpRewriter) Test(org.junit.Test)

Example 13 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.

the class OpExecutorTDB1 method execute.

@Override
protected QueryIterator execute(OpQuadPattern quadPattern, QueryIterator input) {
    if (!isForTDB)
        return super.execute(quadPattern, input);
    //        DatasetGraph dg = execCxt.getDataset() ;
    //        if ( ! ( dg instanceof DatasetGraphTDB ) )
    //            throw new InternalErrorException("Not a TDB backed dataset in quad pattern execution") ;
    DatasetGraphTDB ds = (DatasetGraphTDB) execCxt.getDataset();
    BasicPattern bgp = quadPattern.getBasicPattern();
    Node gn = quadPattern.getGraphNode();
    return optimizeExecuteQuads(ds, input, gn, bgp, null, execCxt);
}
Also used : Node(org.apache.jena.graph.Node) BasicPattern(org.apache.jena.sparql.core.BasicPattern) DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB)

Example 14 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.

the class ReorderProcIndexes method reorder.

/** Return a new basic pattern with the same triples as the input,
     *  but ordered as per the index list of this reorder processor. 
     */
@Override
public BasicPattern reorder(BasicPattern bgp) {
    if (indexes.length != bgp.size()) {
        String str = String.format("Expected size = %d : actual basic pattern size = %d", indexes.length, bgp.size());
        Log.error(this, str);
        throw new ARQException(str);
    }
    BasicPattern bgp2 = new BasicPattern();
    for (int idx : indexes) {
        Triple t = bgp.get(idx);
        bgp2.add(t);
    }
    return bgp2;
}
Also used : Triple(org.apache.jena.graph.Triple) ARQException(org.apache.jena.sparql.ARQException) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 15 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.

the class TestService method testStringTimeout2.

@Test
public void testStringTimeout2() {
    BasicPattern basicPattern = new BasicPattern();
    basicPattern.add(Triple.ANY);
    Node serviceNode = NodeFactory.createURI(SERVICE);
    OpService opService = new OpService(serviceNode, new OpBGP(basicPattern), false);
    Context context = new Context();
    ARQ.setNormalMode(context);
    context.set(Service.queryTimeout, "10,10000");
    try {
        Service.exec(opService, context);
        Assert.fail("Expected QueryExceptionHTTP");
    } catch (QueryExceptionHTTP expected) {
        Throwable thrown = expected.getCause();
        if (thrown instanceof SocketException || thrown instanceof ConnectTimeoutException) {
        // expected
        } else {
            Assert.fail(String.format("Expected SocketException or ConnectTimeoutException, instead got: %s %s", thrown.getClass().getName(), thrown.getMessage()));
        }
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) SocketException(java.net.SocketException) Node(org.apache.jena.graph.Node) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) OpService(org.apache.jena.sparql.algebra.op.OpService) BasicPattern(org.apache.jena.sparql.core.BasicPattern) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) Test(org.junit.Test)

Aggregations

BasicPattern (org.apache.jena.sparql.core.BasicPattern)44 Node (org.apache.jena.graph.Node)15 Triple (org.apache.jena.graph.Triple)13 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)13 Op (org.apache.jena.sparql.algebra.Op)11 Test (org.junit.Test)11 Var (org.apache.jena.sparql.core.Var)5 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)5 Binding (org.apache.jena.sparql.engine.binding.Binding)5 ArrayList (java.util.ArrayList)4 BaseTest (org.apache.jena.atlas.junit.BaseTest)4 OpQuadPattern (org.apache.jena.sparql.algebra.op.OpQuadPattern)4 Quad (org.apache.jena.sparql.core.Quad)4 SocketException (java.net.SocketException)3 HashMap (java.util.HashMap)3 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)3 OpService (org.apache.jena.sparql.algebra.op.OpService)3 QueryExceptionHTTP (org.apache.jena.sparql.engine.http.QueryExceptionHTTP)3 Context (org.apache.jena.sparql.util.Context)3 IndentedLineBuffer (org.apache.jena.atlas.io.IndentedLineBuffer)2