use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class QueryUtils method checkOp.
public static void checkOp(Query query, boolean optimizeAlgebra) {
IndentedLineBuffer buff = new IndentedLineBuffer();
Op op = Algebra.compile(query);
if (optimizeAlgebra)
op = Algebra.optimize(op);
WriterSSE.out(buff, op, query);
String str = buff.toString();
try {
Op op2 = SSE.parseOp(str);
if (op.hashCode() != op2.hashCode()) {
op.hashCode();
op2.hashCode();
dump(op, op2);
throw new QueryCheckException("reparsed algebra expression hashCode does not equal algebra from query");
}
if (!op.equals(op2)) {
dump(op, op2);
throw new QueryCheckException("reparsed algebra expression does not equal query algebra");
}
} catch (SSEParseException | BuildException ex) {
System.err.println(str);
throw ex;
}
// Breakpoint
}
use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class QueryOutputUtils method printOp.
public static void printOp(IndentedWriter out, Query query, boolean printOptimized) {
Op op = Algebra.compile(query);
if (printOptimized)
op = Algebra.optimize(op);
WriterSSE.out(out, op, query);
out.flush();
}
use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class TestCustomAggregates method customAgg_22.
@Test
public void customAgg_22() {
String qs = "SELECT (<" + aggIRI + ">(?o) AS ?x) {?s ?p ?o }";
Query q = QueryFactory.create(qs, Syntax.syntaxARQ);
Op op = Algebra.compile(q);
String x = StrUtils.strjoinNL("(project (?x)", " (extend ((?x ?.0))", " (group () ((?.0 (agg <http://example.test/agg> ?o)))", " (bgp (triple ?s ?p ?o)))))");
Op op2 = SSE.parseOp(x);
assertEquals(op2, op);
}
use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class tdbreorder method main.
public static void main(String... args) {
if (args.length != 2) {
System.err.println("Usage: PATTERN STATS");
System.exit(1);
}
LogCtl.enable(StatsMatcher.class);
LogCtl.enable(ReorderTransformationSubstitution.class);
if (args.length != 2) {
System.err.println("Usage: op stats");
System.exit(1);
}
String pattern = args[0];
String statsFile = args[1];
Op op = SSE.readOp(pattern);
BasicPattern bgp;
if (op instanceof OpQuadPattern) {
bgp = ((OpQuadPattern) op).getBasicPattern();
} else if (op instanceof OpBGP) {
bgp = ((OpBGP) op).getPattern();
} else {
System.err.println("Not a quad or triple pattern");
System.exit(2);
bgp = null;
}
ReorderTransformation reorder = chooseReorder(statsFile);
// ReorderTransformation reorder = ReorderLib.fixed() ;
BasicPattern bgp2 = reorder.reorder(bgp);
System.out.println();
print(bgp);
System.out.println();
System.out.println(" ======== >>>>>>>>");
print(bgp2);
System.out.println();
}
use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class OpExecutorTDB1 method optimizeExecuteTriples.
/** Execute, with optimization, a basic graph pattern on the default graph storage */
private static QueryIterator optimizeExecuteTriples(DatasetGraphTDB dsgtdb, QueryIterator input, BasicPattern pattern, ExprList exprs, ExecutionContext execCxt) {
if (!input.hasNext())
return input;
// Must pass this iterator into the next stage.
if (pattern.size() >= 2) {
// Must be 2 or triples to reorder.
ReorderTransformation transform = dsgtdb.getReorderTransform();
if (transform != null) {
QueryIterPeek peek = QueryIterPeek.create(input, execCxt);
// Must pass on
input = peek;
pattern = reorder(pattern, peek, transform);
}
}
// -- Filter placement
Op op = null;
if (exprs != null)
op = TransformFilterPlacement.transform(exprs, pattern);
else
op = new OpBGP(pattern);
return plainExecute(op, input, execCxt);
}
Aggregations