@Override public Long visitSelectOperator(SelectOperator op, Void arg) throws AlgebricksException { return adjustCardinalityForTupleReductionOperator(op.getInputs().get(0).getValue().accept(this, arg)); }
@Override public Void visitSelectOperator(SelectOperator op, IOptimizationContext ctx) throws AlgebricksException { ILogicalOperator childOp = op.getInputs().get(0).getValue(); Map<LogicalVariable, EquivalenceClass> equivalenceClasses = getOrComputeEqClasses(childOp, ctx); ctx.putEquivalenceClassMap(op, equivalenceClasses); List<FunctionalDependency> functionalDependencies = new ArrayList<FunctionalDependency>(); ctx.putFDList(op, functionalDependencies); functionalDependencies.addAll(getOrComputeFDs(childOp, ctx)); equivalenceClasses.putAll(getOrComputeEqClasses(childOp, ctx)); ILogicalExpression expr = op.getCondition().getValue(); expr.getConstraintsAndEquivClasses(functionalDependencies, equivalenceClasses); return null; }
@Override public Pair<ILogicalOperator, LogicalVariable> visit(HavingClause havingClause, Mutable<ILogicalOperator> tupSource) throws CompilationException { Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(havingClause.getFilterExpression(), tupSource); SelectOperator s = new SelectOperator(new MutableObject<>(p.first), false, null); s.getInputs().add(p.second); return new Pair<>(s, null); }
private static boolean propagateSelectionRec(Mutable<ILogicalOperator> sigmaRef, Mutable<ILogicalOperator> opRef2) throws AlgebricksException { AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue(); if (op2.getInputs().size() != 1 || op2.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN || !OperatorPropertiesUtil.isMovable(op2)) { return false; } SelectOperator sigma = (SelectOperator) sigmaRef.getValue(); LinkedList<LogicalVariable> usedInSigma = new LinkedList<LogicalVariable>(); sigma.getCondition().getValue().getUsedVariables(usedInSigma); LinkedList<LogicalVariable> produced2 = new LinkedList<LogicalVariable>(); VariableUtilities.getProducedVariables(op2, produced2); if (OperatorPropertiesUtil.disjoint(produced2, usedInSigma)) { // just swap opRef2.setValue(sigma); sigmaRef.setValue(op2); List<Mutable<ILogicalOperator>> sigmaInpList = sigma.getInputs(); sigmaInpList.clear(); sigmaInpList.addAll(op2.getInputs()); List<Mutable<ILogicalOperator>> op2InpList = op2.getInputs(); op2InpList.clear(); op2InpList.add(opRef2); propagateSelectionRec(opRef2, sigma.getInputs().get(0)); return true; } return false; }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); // Look for select. if (op.getOperatorTag() != LogicalOperatorTag.SELECT) { return false; } SelectOperator select = (SelectOperator) op; Mutable<ILogicalExpression> condExpr = select.getCondition(); // Gather assigns below this select. List<AssignOperator> assigns = new ArrayList<AssignOperator>(); AbstractLogicalOperator childOp = (AbstractLogicalOperator) select.getInputs().get(0).getValue(); // Skip selects. while (childOp.getOperatorTag() == LogicalOperatorTag.SELECT) { childOp = (AbstractLogicalOperator) childOp.getInputs().get(0).getValue(); } while (childOp.getOperatorTag() == LogicalOperatorTag.ASSIGN) { assigns.add((AssignOperator) childOp); childOp = (AbstractLogicalOperator) childOp.getInputs().get(0).getValue(); } return replaceSelectConditionExprs(condExpr, assigns, context); }
/** * Check that the given SELECT condition is a function call. * Call initSubTree() to initialize the optimizable subtree that collects information from * the operators below the given SELECT operator. * In order to transform the given plan, a datasource should be configured * since we are going to transform a datasource into an unnest-map operator. */ protected boolean checkSelectOpConditionAndInitSubTree(IOptimizationContext context) throws AlgebricksException { // Set and analyze select. ILogicalExpression condExpr = selectOp.getCondition().getValue(); typeEnvironment = context.getOutputTypeEnvironment(selectOp); if (condExpr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return false; } selectCond = (AbstractFunctionCallExpression) condExpr; // Initialize the subtree information. // Match and put assign, unnest, and datasource information. boolean res = subTree.initFromSubTree(selectOp.getInputs().get(0)); return res && subTree.hasDataSourceScan(); }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.SELECT) { return false; } SelectOperator select = (SelectOperator) op; ILogicalExpression cond = select.getCondition().getValue(); if (alwaysHold(cond)) { opRef.setValue(select.getInputs().get(0).getValue()); return true; } return false; }
@Override public Pair<ILogicalOperator, LogicalVariable> visit(WhereClause w, Mutable<ILogicalOperator> tupSource) throws CompilationException { Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(w.getWhereExpr(), tupSource); SelectOperator s = new SelectOperator(new MutableObject<>(p.first), false, null); s.getInputs().add(p.second); s.setSourceLocation(w.getSourceLocation()); return new Pair<>(s, null); }
ILogicalExpression newJoinCond = makeCondition(eqVarVarComps, context); join.getCondition().setValue(newJoinCond); select.getInputs().add(new MutableObject<ILogicalOperator>(join)); opRef.setValue(select); context.computeAndSetTypeEnvironmentForOperator(select);
Mutable<ILogicalOperator> childOfSelect = select.getInputs().get(0); boolean fst = true; ILogicalOperator botOp = select;
new SelectOperator(new MutableObject<ILogicalExpression>(isFilterableExpr), false, null); isFilterableSelectOp.setSourceLocation(sourceLoc); isFilterableSelectOp.getInputs().add(new MutableObject<ILogicalOperator>(inputOp)); isFilterableSelectOp.setExecutionMode(ExecutionMode.LOCAL); context.computeAndSetTypeEnvironmentForOperator(isFilterableSelectOp); new SelectOperator(new MutableObject<ILogicalExpression>(isNotFilterableExpr), false, null); isNotFilterableSelectOp.setSourceLocation(sourceLoc); isNotFilterableSelectOp.getInputs().add(new MutableObject<ILogicalOperator>(inputOp)); isNotFilterableSelectOp.setExecutionMode(ExecutionMode.LOCAL); context.computeAndSetTypeEnvironmentForOperator(isNotFilterableSelectOp);
ILogicalOperator child = select.getInputs().get(0).getValue(); InlineVariablesRule.InlineVariablesVisitor inlineVisitor = null; Map<LogicalVariable, ILogicalExpression> varAssignRhs = null;
if (qe.getQuantifier() == Quantifier.SOME) { s = new SelectOperator(new MutableObject<>(eo2.first), false, null); s.getInputs().add(eo2.second); s.setSourceLocation(sourceLoc); fAgg = BuiltinFunctions.makeAggregateFunctionExpression(BuiltinFunctions.NON_EMPTY_STREAM, notExpr.setSourceLocation(sourceLoc); s = new SelectOperator(new MutableObject<>(notExpr), false, null); s.getInputs().add(eo2.second); s.setSourceLocation(sourceLoc); fAgg = BuiltinFunctions.makeAggregateFunctionExpression(BuiltinFunctions.EMPTY_STREAM, new ArrayList<>());
@Override public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema opSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException { SelectOperator select = (SelectOperator) op; IExpressionRuntimeProvider expressionRuntimeProvider = context.getExpressionRuntimeProvider(); IScalarEvaluatorFactory cond = expressionRuntimeProvider.createEvaluatorFactory( select.getCondition().getValue(), context.getTypeEnvironment(op), inputSchemas, context); StreamSelectRuntimeFactory runtime = new StreamSelectRuntimeFactory(cond, null, context.getBinaryBooleanInspectorFactory(), select.getRetainMissing(), inputSchemas[0].findVariable(select.getMissingPlaceholderVariable()), context.getMissingWriterFactory()); runtime.setSourceLocation(select.getSourceLocation()); // contribute one Asterix framewriter RecordDescriptor recDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), opSchema, context); builder.contributeMicroOperator(select, runtime, recDesc); // and contribute one edge from its child ILogicalOperator src = select.getInputs().get(0).getValue(); builder.contributeGraphEdge(src, 0, select, 0); }
select.getInputs().add(new MutableObject<>(ntsOp)); select.setSourceLocation(selectExpr.getValue().getSourceLocation());
select.getInputs().add(mutable(tCtx.op)); tCtx.op = select; List<LogicalVariable> vars = new ArrayList<LogicalVariable>();
selectNonSystemNull.getInputs().add(ntsBeforeNestedGby);
SelectOperator topSelectOp = new SelectOperator(conditionRef, isLeftOuterJoin, newNullPlaceHolderVar); topSelectOp.setSourceLocation(finalIndexSearchOp.getSourceLocation()); topSelectOp.getInputs().add(indexSubTree.getRootRef()); topSelectOp.setExecutionMode(ExecutionMode.LOCAL); context.computeAndSetTypeEnvironmentForOperator(topSelectOp);
jOp.setSourceLocation(sourceLoc); jOp.getInputs().add(new MutableObject<>(unn)); jOp.getInputs().add(select.getInputs().get(0));