use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class TupleTable method iterator.
public QueryIterator iterator() {
SDBRequest request = new SDBRequest(store, null);
String tableName = desc.getTableName();
SQLBridge b = store.getSQLBridgeFactory().create(request, sqlTable, vars);
b.build();
try {
String sqlStr = store.getSQLGenerator().generateSQL(request, b.getSqlNode());
//System.out.println(sqlStr) ;
ResultSetJDBC tableData = store.getConnection().execQuery(sqlStr);
ExecutionContext execCxt = new ExecutionContext(new Context(), null, null, null);
return b.assembleResults(tableData, BindingRoot.create(), execCxt);
} catch (SQLException ex) {
throw new SDBExceptionSQL(ex);
}
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class Eval method evalGraph.
static Table evalGraph(OpGraph opGraph, Evaluator evaluator) {
ExecutionContext execCxt = evaluator.getExecContext();
if (!Var.isVar(opGraph.getNode())) {
DatasetGraph dsg = execCxt.getDataset();
Node graphNode = opGraph.getNode();
if (!dsg.containsGraph(graphNode))
return new TableEmpty();
Graph graph = execCxt.getDataset().getGraph(opGraph.getNode());
if (// But contains was true?!!
graph == null)
throw new InternalErrorException("Graph was present, now it's not");
ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
Evaluator e2 = EvaluatorFactory.create(execCxt2);
return eval(e2, opGraph.getSubOp());
}
// Graph node is a variable.
Var gVar = Var.alloc(opGraph.getNode());
Table current = null;
for (Iterator<Node> iter = execCxt.getDataset().listGraphNodes(); iter.hasNext(); ) {
Node gn = iter.next();
Graph graph = execCxt.getDataset().getGraph(gn);
ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
Evaluator e2 = EvaluatorFactory.create(execCxt2);
Table tableVarURI = TableFactory.create(gVar, gn);
// Evaluate the pattern, join with this graph node possibility.
// XXX If Var.ANON then no-opt.
Table patternTable = eval(e2, opGraph.getSubOp());
Table stepResult = evaluator.join(patternTable, tableVarURI);
if (current == null)
current = stepResult;
else
current = evaluator.union(current, stepResult);
}
if (current == null)
// Nothing to loop over
return new TableEmpty();
return current;
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class PathLib method existsPath.
private static int existsPath(Graph graph, Node subject, Path path, final Node object, ExecutionContext execCxt) {
if (!subject.isConcrete() || !object.isConcrete())
throw new ARQInternalErrorException("Non concrete node for existsPath evaluation");
Iterator<Node> iter = PathEval.eval(graph, subject, path, execCxt.getContext());
Predicate<Node> filter = node -> Objects.equals(node, object);
// See if we got to the node we're interested in finishing at.
iter = Iter.filter(iter, filter);
long x = Iter.count(iter);
return (int) x;
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class ExprUtils method eval.
public static NodeValue eval(Expr expr, Binding binding) {
Context context = ARQ.getContext().copy();
context.set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime());
FunctionEnv env = new ExecutionContext(context, null, null, null);
NodeValue r = expr.eval(binding, env);
return r;
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class TestCancelDistinct method testUnbaggedCancelPropagates.
/**
* test that of a QueryIterDistinct is cancelled, so is the
* iterator that it wraps.
*/
@Test
public void testUnbaggedCancelPropagates() {
// Something better than null would be good. But making
// an ExecutionContext is non-trivial.
ExecutionContext c = null;
QueryIteratorBase base = new MockQueryIterator();
QueryIterDistinct d = new QueryIterDistinct(base, null, c);
assertFalse(base.getRequestingCancel());
d.cancel();
assertTrue(base.getRequestingCancel());
}
Aggregations