@Override public Void visitSelectOperator(SelectOperator op, Pair<LogicalVariable, LogicalVariable> pair) { op.getCondition().getValue().substituteVar(pair.first, pair.second); return null; }
@Override public String visitSelectOperator(SelectOperator op, Boolean showDetails) { stringBuilder.setLength(0); stringBuilder.append("select (").append(op.getCondition().getValue().toString()).append(")"); appendSchema(op, showDetails); appendAnnotations(op, showDetails); appendPhysicalOperatorInfo(op, showDetails); return stringBuilder.toString(); }
@Override public Boolean visitSelectOperator(SelectOperator op, ILogicalOperator arg) throws AlgebricksException { AbstractLogicalOperator aop = (AbstractLogicalOperator) arg; if (aop.getOperatorTag() != LogicalOperatorTag.SELECT) { return Boolean.FALSE; } SelectOperator selectOpArg = (SelectOperator) copyAndSubstituteVar(op, arg); boolean isomorphic = op.getCondition().getValue().equals(selectOpArg.getCondition().getValue()); return isomorphic; }
@Override public Void visitSelectOperator(SelectOperator op, Void arg) { op.getCondition().getValue().getUsedVariables(usedVariables); return null; }
@Override public Void visitSelectOperator(SelectOperator op, Integer indent) throws AlgebricksException { addIndent(indent).append("\"operator\": \"select\",\n"); addIndent(indent).append("\"expressions\": \"" + op.getCondition().getValue().accept(exprVisitor, indent).replace('"', ' ') + "\""); return null; }
@Override public ILogicalOperator visitSelectOperator(SelectOperator op, Void arg) throws AlgebricksException { return new SelectOperator(deepCopyExpressionRef(op.getCondition()), op.getRetainMissing(), op.getMissingPlaceholderVariable()); }
@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 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); }
private boolean checkIfRuleIsApplicable(Mutable<ILogicalOperator> opRef, IOptimizationContext context) { // First check that the operator is a select and its condition is a function call. AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (context.checkIfInDontApplySet(this, op)) { return false; } if (op.getOperatorTag() != LogicalOperatorTag.SELECT) { return false; } ILogicalExpression condExpr = ((SelectOperator) op).getCondition().getValue(); if (condExpr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return false; } return true; }
/** * 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 ILogicalOperator visitSelectOperator(SelectOperator op, ILogicalOperator arg) throws AlgebricksException { SelectOperator opCopy = new SelectOperator(exprDeepCopyVisitor.deepCopyExpressionReference(op.getCondition()), op.getRetainMissing(), deepCopyVariable(op.getMissingPlaceholderVariable())); deepCopyInputsAnnotationsAndExecutionMode(op, arg, opCopy); return opCopy; }
private static void copySelectToBranch(SelectOperator select, Mutable<ILogicalOperator> branch, IOptimizationContext context) throws AlgebricksException { ILogicalOperator newSelect = new SelectOperator(select.getCondition(), select.getRetainMissing(), select.getMissingPlaceholderVariable()); Mutable<ILogicalOperator> newRef = new MutableObject<ILogicalOperator>(branch.getValue()); newSelect.getInputs().add(newRef); branch.setValue(newSelect); context.computeAndSetTypeEnvironmentForOperator(newSelect); }
@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 Void visitSelectOperator(SelectOperator op, Integer indent) throws AlgebricksException { addIndent(indent).append("select (").append(op.getCondition().getValue().accept(exprVisitor, indent)) .append(")"); return null; }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.SELECT) { return false; } SelectOperator selectOp = (SelectOperator) op; Mutable<ILogicalExpression> exprRef = selectOp.getCondition(); ILogicalExpression expr = exprRef.getValue(); if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return false; } AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr; if (funcExpr.getArguments().size() != 2) { return false; } if (!hasTranslatableInterval(funcExpr)) { return false; } return translateIntervalExpression(exprRef, funcExpr); }
@Override public boolean applySelectPlanTransformation(List<Mutable<ILogicalOperator>> afterSelectRefs, Mutable<ILogicalOperator> selectRef, OptimizableOperatorSubTree subTree, Index chosenIndex, AccessMethodAnalysisContext analysisCtx, IOptimizationContext context) throws AlgebricksException { SelectOperator selectOp = (SelectOperator) selectRef.getValue(); ILogicalOperator indexPlanRootOp = createIndexSearchPlan(afterSelectRefs, selectRef, selectOp.getCondition(), subTree.getAssignsAndUnnestsRefs(), subTree, null, chosenIndex, analysisCtx, false, false, subTree.getDataSourceRef().getValue() .getInputs().get(0).getValue().getExecutionMode() == ExecutionMode.UNPARTITIONED, context, null); // Replace the datasource scan with the new plan rooted at primaryIndexUnnestMap. subTree.getDataSourceRef().setValue(indexPlanRootOp); return true; }
private static void addCondToJoin(SelectOperator select, AbstractBinaryJoinOperator join, IOptimizationContext context) { ILogicalExpression cond = join.getCondition().getValue(); if (OperatorPropertiesUtil.isAlwaysTrueCond(cond)) { // the join was a product join.getCondition().setValue(select.getCondition().getValue()); } else { boolean bAddedToConj = false; if (cond.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { AbstractFunctionCallExpression fcond = (AbstractFunctionCallExpression) cond; if (fcond.getFunctionIdentifier().equals(AlgebricksBuiltinFunctions.AND)) { AbstractFunctionCallExpression newCond = new ScalarFunctionCallExpression( context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.AND)); newCond.getArguments().add(select.getCondition()); newCond.getArguments().addAll(fcond.getArguments()); join.getCondition().setValue(newCond); bAddedToConj = true; } } if (!bAddedToConj) { AbstractFunctionCallExpression newCond = new ScalarFunctionCallExpression( context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.AND), select.getCondition(), new MutableObject<ILogicalExpression>(join.getCondition().getValue())); join.getCondition().setValue(newCond); } } }
@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 condition = select.getCondition().getValue(); IVariableTypeEnvironment env = select.computeOutputTypeEnvironment(context); IAType condType = (IAType) env.getType(condition); if (condType.getTypeTag() != ATypeTag.BOOLEAN && condType.getTypeTag() != ATypeTag.ANY && !isPossibleBoolean(condType)) { throw new CompilationException(ErrorCode.COMPILATION_ERROR, condition.getSourceLocation(), "The select condition " + LogRedactionUtil.userData(condition.toString()) + " should be of the " + "boolean type."); } return false; }
private Pair<Boolean, ILogicalExpression> checkSelect(SelectOperator select) { ILogicalExpression condition = select.getCondition().getValue(); if (condition.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return new Pair<>(false, null); } AbstractFunctionCallExpression conditionFunc = (AbstractFunctionCallExpression) condition; if (!conditionFunc.getFunctionIdentifier().equals(BuiltinFunctions.NOT)) { return new Pair<>(false, null); } condition = conditionFunc.getArguments().get(0).getValue(); if (condition.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return new Pair<>(false, null); } conditionFunc = (AbstractFunctionCallExpression) condition; if (!conditionFunc.getFunctionIdentifier().equals(BuiltinFunctions.IS_MISSING)) { return new Pair<>(false, null); } ILogicalExpression conditionArg = conditionFunc.getArguments().get(0).getValue(); return new Pair<>(true, conditionArg); }
@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); }