/** Execute without modification of the op - does <b>not</b> apply special graph name translations */ private static QueryIterator plainExecute(Op op, QueryIterator input, ExecutionContext execCxt) { // -- Execute // Switch to a non-reordering executor // The Op may be a sequence due to TransformFilterPlacement // so we need to do a full execution step, not go straight to the SolverLib. ExecutionContext ec2 = new ExecutionContext(execCxt) ; ec2.setExecutor(plainFactory) ; // Solve without going through this executor again. // There would be issues of nested patterns but this is only a // (filter (bgp...)) or (filter (quadpattern ...)) or sequences of these. // so there are no nested patterns to reorder. return QC.execute(op, input, ec2) ; }
/** Execute without modification of the op - does <b>not</b> apply special graph name translations */ private static QueryIterator plainExecute(Op op, QueryIterator input, ExecutionContext execCxt) { // -- Execute // Switch to a non-reordering executor // The Op may be a sequence due to TransformFilterPlacement // so we need to do a full execution step, not go straight to the SolverLib. ExecutionContext ec2 = new ExecutionContext(execCxt) ; ec2.setExecutor(plainFactory) ; // Solve without going through this executor again. // There would be issues of nested patterns but this is only a // (filter (bgp...)) or (filter (quadpattern ...)) or sequences of these. // so there are no nested patterns to reorder. return QC.execute(op, input, ec2) ; }
/** Execute without modification of the op - does <b>not</b> apply special graph name translations */ private static QueryIterator plainExecute(Op op, QueryIterator input, ExecutionContext execCxt) { // -- Execute // Switch to a non-reordering executor // The Op may be a sequence due to TransformFilterPlacement // so we need to do a full execution step, not go straight to the SolverLib. ExecutionContext ec2 = new ExecutionContext(execCxt) ; ec2.setExecutor(plainFactory) ; // Solve without going through this executor again. // There would be issues of nested patterns but this is only a // (filter (bgp...)) or (filter (quadpattern ...)) or sequences of these. // so there are no nested patterns to reorder. return QC.execute(op, input, ec2) ; }
private QueryIterator specialcase(Node gn, Op subOp, QueryIterator input) { // This is a placeholder for code to specially handle explicitly named // default graph and union graph. if (Quad.isDefaultGraph(gn)) { ExecutionContext cxt2 = new ExecutionContext(execCxt, execCxt.getDataset().getDefaultGraph()) ; return execute(subOp, input, cxt2) ; } // Bad news -- if ( Lib.equals(gn, Quad.tripleInQuad) ) {} return null ; }
@Override protected QueryIterator createQueryIter(List<Binding> data) { QueryIterator qIter = new QueryIterPlainWrapper(data.iterator()) ; Context cxt = new Context() ; cxt.set(ARQ.spillToDiskThreshold, 2L); return new QueryIterDistinct(qIter, new ExecutionContext(cxt, null, null, null)) ; }
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 ; }
@Override protected QueryIterator createQueryIter(List<Binding> data) { QueryIterator qIter = new QueryIterPlainWrapper(data.iterator()) ; return new QueryIterDistinctMem(qIter, new ExecutionContext(new Context(), null, null, null)) ; }
@Override public QueryIterator eval(Op op, DatasetGraph dsg, Binding binding, Context context) { if ( binding.vars().hasNext() ) op = Substitute.substitute(op, binding) ; ExecutionContext execCxt = new ExecutionContext(context, dsg.getDefaultGraph(), dsg, QC.getFactory(context)) ; Evaluator eval = EvaluatorFactory.create(execCxt) ; Table table = Eval.eval(eval, op) ; QueryIterator qIter = table.iterator(execCxt) ; return QueryIteratorCheck.check(qIter, execCxt) ; }
/** * This is partly a repetition of private functions in QC * @param op * @param context * @return */ public static QueryIterator execute(Op op, Context context) { DatasetGraph dg = DatasetGraphFactory.create(); OpExecutorFactory opExecutorFactory = QC.getFactory(context); ExecutionContext execCxt = new ExecutionContext(context, dg.getDefaultGraph(), dg, opExecutorFactory); QueryIterator qIter = QueryIterRoot.create(execCxt); OpExecutor opExecutor = opExecutorFactory.create(execCxt); QueryIterator result = opExecutor.executeOp(op, qIter); return result; }
/** * This is partly a repetition of private functions in QC * @param op * @param context * @return */ public static QueryIterator execute(Op op, Context context) { DatasetGraph dg = DatasetGraphFactory.create(); OpExecutorFactory opExecutorFactory = QC.getFactory(context); ExecutionContext execCxt = new ExecutionContext(context, dg.getDefaultGraph(), dg, opExecutorFactory); QueryIterator qIter = QueryIterRoot.create(execCxt); OpExecutor opExecutor = opExecutorFactory.create(execCxt); QueryIterator result = opExecutor.executeOp(op, qIter); return result; }
@Override public QueryIterator eval(Op op, DatasetGraph dsg, Binding input, Context context) { ExecutionContext execCxt = new ExecutionContext(context, dsg.getDefaultGraph(), dsg, QC.getFactory(context)) ; QueryIterator qIter1 = ( input.isEmpty() ) ? QueryIterRoot.create(execCxt) : QueryIterRoot.create(input, execCxt); QueryIterator qIter = QC.execute(op, qIter1, execCxt) ; // Wrap with something to check for closed iterators. qIter = QueryIteratorCheck.check(qIter, execCxt) ; // Need call back. if ( context.isTrue(ARQ.enableExecutionTimeLogging) ) qIter = QueryIteratorTiming.time(qIter) ; return qIter ; }
private static List<Binding> eval(Graph graph, Node start, String pathStr, Node finish) { Path path = SSE.parsePath(pathStr, pmap) ; QueryIterator qIter = PathLib.execTriplePath(BindingFactory.root(), start, path, finish, new ExecutionContext(ARQ.getContext(), graph, null, null)) ; return Iter.toList(qIter) ; }
@Test public void testCloseClosesSourceIterator() { Context context = new Context() ; ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null); QueryIterSort qis = new QueryIterSort(iterator, comparator, ec); qis.close(); assertTrue("source iterator should have been closed", iterator.isClosed()); }
@Test public void testTopNCloseClosesSource() { long numItems = 3; boolean distinct = false; Context context = new Context() ; ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null); QueryIterTopN tn = new QueryIterTopN(iterator, comparator, numItems, distinct, ec); tn.close(); assertTrue(iterator.isClosed()); }
private NodeValue cast(String input$) { Expr input = ExprUtils.parse(input$) ; ARQ.getContext().set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime()) ; FunctionEnv env = new ExecutionContext(ARQ.getContext(), null, null, null) ; return input.eval(null, env) ; } }
protected static QueryIterator buildIterator(Binding binding, Node graphNode, Op opExec, ExecutionContext outerCxt) { if ( !graphNode.isURI() && !graphNode.isBlank() ) // e.g. variable bound to a literal or blank node. throw new ARQInternalErrorException("QueryIterGraphInner.buildIterator: Not a URI or blank node: "+graphNode) ; // We can't just use DatasetGraph.getGraph because it may // "auto-create" graphs. Use the containsGraph function. boolean syntheticGraph = ( Quad.isDefaultGraph(graphNode) || Quad.isUnionGraph(graphNode) ) ; if ( ! syntheticGraph && ! outerCxt.getDataset().containsGraph(graphNode) ) return null ; Graph g = outerCxt.getDataset().getGraph(graphNode) ; // And the contains was true??!!!!!! if ( g == null ) return null ; //throw new ARQInternalErrorException(".containsGraph was true but .getGraph is null") ; ExecutionContext cxt2 = new ExecutionContext(outerCxt, g) ; QueryIterator subInput = QueryIterSingleton.create(binding, cxt2) ; return QC.execute(opExec, subInput, cxt2) ; }
@Test public void testExhaustionClosesSourceIterator() { iterator.setCallback(() -> {}); Context context = new Context() ; ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null); QueryIterSort qis = new QueryIterSort(iterator, comparator, ec); while (qis.hasNext()) qis.next(); assertTrue("source iterator should have been closed", iterator.isClosed()); }
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) ; } }
@Test public void testCancelClosesSourceIterator() { Context context = new Context() ; ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null); QueryIterSort qis = new QueryIterSort(iterator, comparator, ec); try { while (qis.hasNext()) qis.next(); fail("query should have been cancelled by trigger"); } catch (QueryCancelledException q) { assertTrue("source iterator should have been closed", iterator.isClosed()); } }
@Test public void testTopNExhaustionClosesSource() { iterator.setCallback(() -> {}); long numItems = 3; boolean distinct = false; Context context = new Context() ; ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null); QueryIterTopN tn = new QueryIterTopN(iterator, comparator, numItems, distinct, ec); while (tn.hasNext()) tn.next(); assertTrue(iterator.isClosed()); }