@Override public OResultSet fetchNext(int n) { return lastStep.syncPull(ctx, n); }
@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { int limitVal = limit.getValue(ctx); if (limitVal == -1) { return getPrev().get().syncPull(ctx, nRecords); } if (limitVal <= loaded) { return new OInternalResultSet(); } int nextBlockSize = Math.min(nRecords, limitVal - loaded); OResultSet result = prev.get().syncPull(ctx, nextBlockSize); loaded += nextBlockSize; return result; }
@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { if (this.expiryTime == null) { this.expiryTime = System.currentTimeMillis() + timeout.getVal().longValue(); } if (System.currentTimeMillis() > expiryTime) { return fail(); } return getPrev().get().syncPull(ctx, nRecords);//TODO do it more granular }
@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { OResultSet upstream = getPrev().get().syncPull(ctx, nRecords); return new OResultSet() { @Override public boolean hasNext() { return upstream.hasNext(); } @Override public OResult next() { return upstream.next(); } @Override public void close() { } @Override public Optional<OExecutionPlan> getExecutionPlan() { return null; } @Override public Map<String, Long> getQueryStats() { return null; } }; }
@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { getPrev().ifPresent(x -> x.syncPull(ctx, nRecords)); return subExecuitonPlan.fetchNext(nRecords); }
@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { getPrev().ifPresent(x -> x.syncPull(ctx, nRecords)); OInternalResultSet result = new OInternalResultSet(); return result; }
@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { OResultSet upstream = getPrev().get().syncPull(ctx, nRecords); return new OResultSet() { @Override public boolean hasNext() { return upstream.hasNext(); } @Override public OResult next() { return filter(upstream.next()); } @Override public void close() { } @Override public Optional<OExecutionPlan> getExecutionPlan() { return null; } @Override public Map<String, Long> getQueryStats() { return null; } }; }
@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { prev.ifPresent(x -> x.syncPull(ctx, nRecords)); if (finalResult != null) { return finalResult.syncPull(ctx, nRecords); } while (condition.evaluate(new OResultInternal(), ctx)) { if (OExecutionThreadLocal.isInterruptCurrentOperation()) throw new OCommandInterruptedException("The command has been interrupted"); OScriptExecutionPlan plan = initPlan(ctx); OExecutionStepInternal result = plan.executeFull(); if (result != null) { this.finalResult = result; return result.syncPull(ctx, nRecords); } } finalResult = new EmptyStep(ctx, false); return finalResult.syncPull(ctx, nRecords); }
@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { getPrev().ifPresent(x -> x.syncPull(ctx, nRecords)); calculate(ctx); return new OInternalResultSet(); }
@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { getPrev().ifPresent(x -> x.syncPull(ctx, nRecords)); calculate(ctx); return new OInternalResultSet(); }
private void fetchRidsToFind(OCommandContext ctx, int nRecords) { ridsToFind = new HashSet<>(); OExecutionStepInternal prevStep = getPrev().get(); OResultSet nextSlot = prevStep.syncPull(ctx, nRecords); while (nextSlot.hasNext()) { while (nextSlot.hasNext()) { OResult nextRes = nextSlot.next(); if (nextRes.isElement()) { ridsToFind.add(nextRes.getElement().get().getIdentity()); } } nextSlot = prevStep.syncPull(ctx, nRecords); } }
@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { prev.get().syncPull(ctx, nRecords); if (finalResult != null) { return finalResult.syncPull(ctx, nRecords); } init(ctx); while (iterator.hasNext()) { if (OExecutionThreadLocal.isInterruptCurrentOperation()) { throw new OCommandInterruptedException("The command has been interrupted"); } ctx.setVariable(loopVariable.getStringValue(), iterator.next()); OScriptExecutionPlan plan = initPlan(ctx); OExecutionStepInternal result = plan.executeFull(); if (result != null) { this.finalResult = result; return result.syncPull(ctx, nRecords); } } finalResult = new EmptyStep(ctx, false); return finalResult.syncPull(ctx, nRecords); }
@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { if (applied) { return getPrev().get().syncPull(ctx, nRecords); } applied = true; OResultSet upstream = getPrev().get().syncPull(ctx, nRecords); if (upstream.hasNext()) { return upstream; } OInternalResultSet result = new OInternalResultSet(); result.add(createNewRecord(commandTarget, initialFilter)); return result; }
private void fetchNext(OCommandContext ctx, int n) { do { if (nextSubsequence != null && nextSubsequence.hasNext()) { nextElement = nextSubsequence.next(); break; } if (nextSubsequence == null || !nextSubsequence.hasNext()) { if (lastResult == null || !lastResult.hasNext()) { lastResult = getPrev().get().syncPull(ctx, n); } if (!lastResult.hasNext()) { return; } } OResult nextAggregateItem = lastResult.next(); nextSubsequence = unroll(nextAggregateItem, ctx).iterator(); } while (true); }
private void fetchNext(OCommandContext ctx, int n) { do { if (nextSubsequence != null && nextSubsequence.hasNext()) { nextElement = nextSubsequence.next(); break; } if (nextSubsequence == null || !nextSubsequence.hasNext()) { if (lastResult == null || !lastResult.hasNext()) { lastResult = getPrev().get().syncPull(ctx, n); } if (!lastResult.hasNext()) { return; } } OResult nextAggregateItem = lastResult.next(); nextSubsequence = unwind(nextAggregateItem, unwindFields, ctx).iterator(); } while (true); }
@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { if (finished == true) { return new OInternalResultSet();//empty } int skipValue = skip.getValue(ctx); while (skipped < skipValue) { //fetch and discard OResultSet rs = prev.get().syncPull(ctx, Math.min(100, skipValue - skipped));//fetch blocks of 100, at most if (!rs.hasNext()) { finished = true; return new OInternalResultSet();//empty } while (rs.hasNext()) { rs.next(); skipped++; } } return prev.get().syncPull(ctx, nRecords); }
private void executeAggregation(OCommandContext ctx, int nRecords) { if (!prev.isPresent()) { throw new OCommandExecutionException("Cannot execute an aggregation or a GROUP BY without a previous result"); } OExecutionStepInternal prevStep = prev.get(); OResultSet lastRs = prevStep.syncPull(ctx, nRecords); while (lastRs.hasNext()) { aggregate(lastRs.next(), ctx); if (!lastRs.hasNext()) { lastRs = prevStep.syncPull(ctx, nRecords); } } finalResults = new ArrayList<>(); finalResults.addAll(aggregateResults.values()); aggregateResults.clear(); for (OResultInternal item : finalResults) { for (String name : item.getPropertyNames()) { Object prevVal = item.getProperty(name); if (prevVal instanceof AggregationContext) { item.setProperty(name, ((AggregationContext) prevVal).getFinalValue()); } } } }
@Override protected void fetchNextEntryPoints(OCommandContext ctx, int nRecords) { OResultSet nextN = getPrev().get().syncPull(ctx, nRecords); while (nextN.hasNext()) { while (nextN.hasNext()) { OResult item = toTraverseResult(nextN.next()); if(item != null){ List<ORID> stack = new ArrayList<>(); item.getIdentity().ifPresent(x -> stack.add(x)); ((OResultInternal) item).setMetadata("$stack", stack); List<OIdentifiable> path = new ArrayList<>(); path.add(item.getIdentity().get()); ((OResultInternal) item).setMetadata("$path", path); if (item != null && item.isElement() && !traversed.contains(item.getElement().get().getIdentity())) { tryAddEntryPoint(item, ctx); } } } nextN = getPrev().get().syncPull(ctx, nRecords); } }
private void doExecute(int n) { if (!executed) { executeUntilReturn(); executed = true; finalResult = new OInternalResultSet(); OResultSet partial = lastStep.syncPull(ctx, n); while (partial.hasNext()) { while (partial.hasNext()) { ((OInternalResultSet) finalResult).add(partial.next()); } partial = lastStep.syncPull(ctx, n); } if (lastStep instanceof ScriptLineStep) { ((OInternalResultSet) finalResult).setPlan(((ScriptLineStep) lastStep).plan); } } }
@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { if (!executed) { getPrev().ifPresent(x -> x.syncPull(ctx, nRecords)); OResultSet nextBlock = prefetchExecutionPlan.fetchNext(nRecords); List<OResult> prefetched = new ArrayList<>(); while (nextBlock.hasNext()) { while (nextBlock.hasNext()) { prefetched.add(nextBlock.next()); } nextBlock = prefetchExecutionPlan.fetchNext(nRecords); } prefetchExecutionPlan.close(); ctx.setVariable(PREFETCHED_MATCH_ALIAS_PREFIX + alias, prefetched); executed = true; } return new OInternalResultSet(); }