private Pair<ILogicalOperator, LogicalVariable> produceSelectPlan(boolean isSubquery, Mutable<ILogicalOperator> returnOpRef, LogicalVariable resVar) { if (isSubquery) { return aggListifyForSubquery(resVar, returnOpRef, false); } else { ProjectOperator pr = new ProjectOperator(resVar); pr.getInputs().add(returnOpRef); pr.setSourceLocation(returnOpRef.getValue().getSourceLocation()); return new Pair<>(pr, resVar); } }
private static boolean pushAllProjectionsOnTopOf(Collection<LogicalVariable> toPush, Mutable<ILogicalOperator> opRef, IOptimizationContext context, ILogicalOperator initialOp) throws AlgebricksException { if (toPush.isEmpty()) { return false; } AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (context.checkAndAddToAlreadyCompared(initialOp, op)) { return false; } if (op.getOperatorTag() == LogicalOperatorTag.PROJECT) { return false; } ProjectOperator pi2 = new ProjectOperator(new ArrayList<LogicalVariable>(toPush)); pi2.setSourceLocation(op.getSourceLocation()); pi2.getInputs().add(new MutableObject<ILogicalOperator>(op)); opRef.setValue(pi2); pi2.setExecutionMode(op.getExecutionMode()); context.computeAndSetTypeEnvironmentForOperator(pi2); return true; }
protected Pair<ILogicalOperator, LogicalVariable> aggListifyForSubquery(LogicalVariable var, Mutable<ILogicalOperator> opRef, boolean bProject) { SourceLocation sourceLoc = opRef.getValue().getSourceLocation(); AggregateFunctionCallExpression funAgg = BuiltinFunctions.makeAggregateFunctionExpression(BuiltinFunctions.LISTIFY, new ArrayList<>()); funAgg.getArguments().add(new MutableObject<>(new VariableReferenceExpression(var))); funAgg.setSourceLocation(sourceLoc); LogicalVariable varListified = context.newSubplanOutputVar(); AggregateOperator agg = new AggregateOperator(mkSingletonArrayList(varListified), mkSingletonArrayList(new MutableObject<>(funAgg))); agg.getInputs().add(opRef); agg.setSourceLocation(sourceLoc); ILogicalOperator res; if (bProject) { ProjectOperator pr = new ProjectOperator(varListified); pr.getInputs().add(new MutableObject<>(agg)); pr.setSourceLocation(sourceLoc); res = pr; } else { res = agg; } return new Pair<>(res, varListified); }
@Override public Pair<ILogicalOperator, LogicalVariable> visit(Query q, Mutable<ILogicalOperator> tupSource) throws CompilationException { Expression queryBody = q.getBody(); SourceLocation sourceLoc = queryBody.getSourceLocation(); if (queryBody.getKind() == Kind.SELECT_EXPRESSION) { SelectExpression selectExpr = (SelectExpression) queryBody; if (q.isTopLevel()) { selectExpr.setSubquery(false); } return queryBody.accept(this, tupSource); } else { LogicalVariable var = context.newVar(); Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(queryBody, tupSource); AssignOperator assignOp = new AssignOperator(var, new MutableObject<>(eo.first)); assignOp.getInputs().add(eo.second); assignOp.setSourceLocation(sourceLoc); ProjectOperator projectOp = new ProjectOperator(var); projectOp.getInputs().add(new MutableObject<>(assignOp)); projectOp.setSourceLocation(sourceLoc); return new Pair<>(projectOp, var); } }