@Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { if (finalResults == null) { executeAggregation(ctx, nRecords);
@Override public String prettyPrint(int depth, int indent) { String spaces = OExecutionStepInternal.getIndent(depth, indent); String result = spaces + "+ CALCULATE AGGREGATE PROJECTIONS"; if (profilingEnabled) { result += " (" + getCostFormatted() + ")"; } result += "\n" + spaces + " " + projection.toString() + "" + (groupBy == null ? "" : (spaces + "\n " + groupBy.toString())); return result; }
private static void handleProjections(OSelectExecutionPlan result, QueryPlanningInfo info, OCommandContext ctx, boolean profilingEnabled) { if (!info.projectionsCalculated && info.projection != null) { if (info.preAggregateProjection != null) { result.chain(new ProjectionCalculationStep(info.preAggregateProjection, ctx, profilingEnabled)); } if (info.aggregateProjection != null) { result.chain(new AggregateProjectionCalculationStep(info.aggregateProjection, info.groupBy, ctx, profilingEnabled)); if (isCountOnly(info) && info.groupBy == null) { result.chain(new GuaranteeEmptyCountStep(info.aggregateProjection.getItems().get(0), ctx, profilingEnabled)); } } result.chain(new ProjectionCalculationStep(info.projection, ctx, profilingEnabled)); info.projectionsCalculated = true; } }
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()); } } } }
indexCond.setRight(((OBinaryCondition) condition).getRight().copy()); result.chain(new FetchFromIndexStep(classIndex, indexCond, null, ctx, profilingEnabled)); result.chain(new AggregateProjectionCalculationStep(info.aggregateProjection, info.groupBy, ctx, profilingEnabled)); result.chain(new GuaranteeEmptyCountStep(info.aggregateProjection.getItems().get(0), ctx, profilingEnabled)); result.chain(new ProjectionCalculationStep(info.projection, ctx, profilingEnabled));