Search in sources :

Example 1 with TransformCopy

use of org.apache.jena.sparql.algebra.TransformCopy in project jena by apache.

the class TestTransformConstantFolding method test.

private void test(String input, String expected, ExprTransform transform) {
    Op opOrig = SSE.parseOp(input);
    Op opExpected = SSE.parseOp(expected != null ? expected : input);
    Op opOptimized = Transformer.transform(new TransformCopy(), transform, opOrig);
    Assert.assertEquals(opExpected, opOptimized);
}
Also used : Op(org.apache.jena.sparql.algebra.Op) TransformCopy(org.apache.jena.sparql.algebra.TransformCopy)

Example 2 with TransformCopy

use of org.apache.jena.sparql.algebra.TransformCopy in project jena by apache.

the class TestTransformFilterEquality method equality_expression_1.

// JENA -1202
@Test
public void equality_expression_1() {
    // Need to fold to a string or URI to trigger equality.
    Op op = SSE.parseOp("(filter (= ?o (+ 'a' 'b')) (bgp (?x <http://p2> ?o)))");
    // Fold constants.
    Op op1 = Transformer.transform(new TransformCopy(), new ExprTransformConstantFold(), op);
    // Then apply filter-equality.
    check(op1, t_equality, "(assign ((?o 'ab')) (bgp (?x <http://p2> 'ab')) )");
}
Also used : Op(org.apache.jena.sparql.algebra.Op) TransformCopy(org.apache.jena.sparql.algebra.TransformCopy) Test(org.junit.Test)

Example 3 with TransformCopy

use of org.apache.jena.sparql.algebra.TransformCopy in project jena by apache.

the class TestTransformFilters method nested_02.

@Test
public void nested_02() {
    Transform tableChanger = new TransformCopy() {

        @Override
        public Op transform(OpTable opTable) {
            // Always a new object
            return OpTable.create(opTable.getTable());
        }
    };
    testOp("(filter (?A) (filter (?B) (table unit)))", tableChanger, "(filter (exprlist ?B ?A) (table unit))");
}
Also used : TransformCopy(org.apache.jena.sparql.algebra.TransformCopy) OpTable(org.apache.jena.sparql.algebra.op.OpTable) Transform(org.apache.jena.sparql.algebra.Transform) Test(org.junit.Test)

Example 4 with TransformCopy

use of org.apache.jena.sparql.algebra.TransformCopy in project jena by apache.

the class ExprTransformConstantFold method transform.

@Override
public Expr transform(ExprFunctionOp funcOp, ExprList args, Op opArg) {
    // Manually transform each argument
    Op op = Transformer.transform(new TransformCopy(), this, funcOp.getGraphPattern());
    ExprList newArgs = new ExprList();
    for (int i = 0; i < args.size(); i++) {
        Expr curr = args.get(i);
        Expr newArg = ExprTransformer.transform(this, curr);
        newArgs.add(newArg);
    }
    return funcOp.copy(newArgs, op);
}
Also used : Op(org.apache.jena.sparql.algebra.Op) TransformCopy(org.apache.jena.sparql.algebra.TransformCopy)

Aggregations

TransformCopy (org.apache.jena.sparql.algebra.TransformCopy)4 Op (org.apache.jena.sparql.algebra.Op)3 Test (org.junit.Test)2 Transform (org.apache.jena.sparql.algebra.Transform)1 OpTable (org.apache.jena.sparql.algebra.op.OpTable)1