use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class TransformSliceProject method transform.
@Override
public Op transform(OpSlice opSlice, Op subOp) {
// (slice (project...)) ==> (project (slice ...))
if (subOp instanceof OpProject) {
OpProject p = (OpProject) subOp;
Op sub = p.getSubOp();
Op x = new OpSlice(sub, opSlice.getStart(), opSlice.getLength());
x = new OpProject(x, p.getVars());
return x;
}
return super.transform(opSlice, subOp);
}
use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class QueryIterOpSQL method nextStage.
@Override
protected QueryIterator nextStage(Binding binding) {
OpSQL execSQL = this.opSQL;
if (binding != null && !isRoot(binding)) {
QueryCompiler qc = opSQL.getRequest().getStore().getQueryCompilerFactory().createQueryCompiler(request);
Op op2 = Substitute.substitute(opSQL.getOriginal(), binding);
Op op = qc.compile(op2);
if (op instanceof OpSQL)
execSQL = (OpSQL) op;
else
throw new SDBInternalError("Failed to recompile the OpSQL to an OpSQL");
}
return execSQL.exec(binding, getExecContext());
// QueryIterator qIter = execSQL.exec(binding, getExecContext()) ;
// List<Binding> x = Iter.toList(qIter) ;
// qIter = new QueryIterPlainWrapper(x.iterator(), getExecContext()) ;
// System.out.println("SQL Eval:") ;
// x.forEach(b -> System.out.println(" "+b) );
// System.out.println() ;
// return qIter ;
}
use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class AlgebraEx method main.
public static void main(String[] args) {
String s = "SELECT DISTINCT ?s { ?s ?p ?o }";
// Parse
Query query = QueryFactory.create(s);
System.out.println(query);
// Generate algebra
Op op = Algebra.compile(query);
op = Algebra.optimize(op);
System.out.println(op);
// Execute it.
QueryIterator qIter = Algebra.exec(op, ExQuerySelect1.createModel());
// Results
for (; qIter.hasNext(); ) {
Binding b = qIter.nextBinding();
System.out.println(b);
}
qIter.close();
}
use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class TransformExtendCombine method transform.
@Override
public Op transform(OpAssign opAssign, Op subOp) {
if (subOp instanceof OpAssign) {
// If a variable is assigned twice, don't do anything.
// (assign (?x 2) (assign (?x 1) op)) => leave alone.
// This is the safest option in a rare case.
// It would be OK if addAll does a replacement without checking
// but having it check and complain about duplicates adds robustness.
// In OpExtend, it's actually illegal.
OpAssign x = (OpAssign) subOp;
VarExprList outerVarExprList = opAssign.getVarExprList();
// Copy
VarExprList innerVarExprList = new VarExprList(x.getVarExprList());
Op r = OpAssign.assign(x.getSubOp(), innerVarExprList);
// This contains an "if already (assign)" test.
r = OpAssign.assign(r, outerVarExprList);
return r;
}
return super.transform(opAssign, subOp);
}
use of org.apache.jena.sparql.algebra.Op in project jena by apache.
the class OpN method equalsSubOps.
// Tests the sub-elements for equalTo.
protected boolean equalsSubOps(OpN op, NodeIsomorphismMap labelMap) {
if (elements.size() != op.elements.size())
return false;
Iterator<Op> iter1 = elements.listIterator();
Iterator<Op> iter2 = op.elements.listIterator();
for (; iter1.hasNext(); ) {
Op op1 = iter1.next();
Op op2 = iter2.next();
if (!op1.equalTo(op2, labelMap))
return false;
}
return true;
}
Aggregations