use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class TestOptimizer method combine_extend_04.
@Test
public void combine_extend_04() {
String opString = StrUtils.strjoinNL("(extend ((?x 2))", " (extend ((?y 3))", " (distinct", " (extend ((?a 'A') (?b 'B'))", " (extend ((?c 'C'))", " (table unit)", " )))))");
String opExpectedString = StrUtils.strjoinNL("(extend ((?y 3) (?x 2))", " (distinct", " (extend ((?c 'C') (?a 'A') (?b 'B'))", " (table unit))))");
Op op = SSE.parseOp(opString);
check(op, new TransformExtendCombine(), opExpectedString);
}
use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class TestOptimizer method combine_extend_01.
@Test
public void combine_extend_01() {
Op extend = OpExtend.create(OpTable.unit(), new VarExprList(Var.alloc("x"), new NodeValueInteger(1)));
extend = OpExtend.create(extend, new VarExprList(Var.alloc("y"), new NodeValueInteger(2)));
String opExpectedString = StrUtils.strjoinNL("(extend ((?x 1) (?y 2))", " (table unit))");
check(extend, new TransformExtendCombine(), opExpectedString);
}
use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class TestSemanticEquivalence method testAsAlgebra.
/**
* Tests whether an algebra expression gives the same results when run both
* with and without a given optimizer
*
* @param algStr
* Algebra
* @param ds
* Dataset
* @param opt
* Optimizer
* @param expected
* Expected number of results
*/
public static void testAsAlgebra(String algStr, Dataset ds, Symbol opt, int expected) {
Op op = SSE.parseOp(algStr);
List<String> vars = new ArrayList<>();
for (Var v : OpVars.visibleVars(op)) {
vars.add(v.getName());
}
// Track current state
boolean isEnabled = ARQ.isTrue(opt);
boolean isDisabled = ARQ.isFalse(opt);
try {
// Run first without optimization
ARQ.set(opt, false);
QueryEngineMain engine = new QueryEngineMain(op, ds.asDatasetGraph(), BindingFactory.binding(), ARQ.getContext());
QueryIterator iter = engine.eval(op, ds.asDatasetGraph(), BindingFactory.binding(), ARQ.getContext());
ResultSetRewindable rs = ResultSetFactory.makeRewindable(new ResultSetStream(vars, ModelFactory.createDefaultModel(), iter));
if (expected != rs.size()) {
System.err.println("Non-optimized results not as expected");
TextOutput output = new TextOutput((SerializationContext) null);
output.format(System.out, rs);
rs.reset();
}
Assert.assertEquals(expected, rs.size());
iter.close();
// Run with optimization
ARQ.set(opt, true);
engine = new QueryEngineMain(op, ds.asDatasetGraph(), BindingFactory.binding(), ARQ.getContext());
QueryIterator iterOpt = engine.eval(op, ds.asDatasetGraph(), BindingFactory.binding(), ARQ.getContext());
ResultSetRewindable rsOpt = ResultSetFactory.makeRewindable(new ResultSetStream(vars, ModelFactory.createDefaultModel(), iterOpt));
if (expected != rsOpt.size()) {
System.err.println("Optimized results not as expected");
TextOutput output = new TextOutput((SerializationContext) null);
output.format(System.out, rsOpt);
rsOpt.reset();
}
Assert.assertEquals(expected, rsOpt.size());
iterOpt.close();
Assert.assertTrue(ResultSetCompare.isomorphic(rs, rsOpt));
} finally {
// Restore previous state
if (isEnabled) {
ARQ.set(opt, true);
} else if (isDisabled) {
ARQ.set(opt, false);
} else {
ARQ.unset(opt);
}
}
}
use of org.apache.jena.sparql.algebra.Op 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);
}
use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class TestTransformEliminateAssignments method test.
private void test(Op original, boolean aggressive, String... output) {
// Transform
Op actual = TransformEliminateAssignments.eliminate(original, aggressive);
// Check results
if (output == null) {
// No transformation.
Assert.assertEquals(original, actual);
} else {
// Transformation expected
Op expected = SSE.parseOp(StrUtils.strjoinNL(output));
Assert.assertEquals(expected, actual);
}
}
Aggregations