List of usage examples for org.apache.commons.lang3.mutable Mutable getValue
T getValue();
From source file:edu.uci.ics.asterix.optimizer.rules.am.RTreeAccessMethod.java
@Override public boolean applyJoinPlanTransformation(Mutable<ILogicalOperator> joinRef, OptimizableOperatorSubTree leftSubTree, OptimizableOperatorSubTree rightSubTree, Index chosenIndex, AccessMethodAnalysisContext analysisCtx, IOptimizationContext context, boolean isLeftOuterJoin, boolean hasGroupBy) throws AlgebricksException { // Determine if the index is applicable on the left or right side (if both, we arbitrarily prefer the left side). Dataset dataset = analysisCtx.indexDatasetMap.get(chosenIndex); // Determine probe and index subtrees based on chosen index. OptimizableOperatorSubTree indexSubTree = null; OptimizableOperatorSubTree probeSubTree = null; if (!isLeftOuterJoin && leftSubTree.hasDataSourceScan() && dataset.getDatasetName().equals(leftSubTree.dataset.getDatasetName())) { indexSubTree = leftSubTree;/*from w w w .j a v a 2 s. com*/ probeSubTree = rightSubTree; } else if (rightSubTree.hasDataSourceScan() && dataset.getDatasetName().equals(rightSubTree.dataset.getDatasetName())) { indexSubTree = rightSubTree; probeSubTree = leftSubTree; } if (indexSubTree == null) { //This may happen for left outer join case return false; } LogicalVariable newNullPlaceHolderVar = null; if (isLeftOuterJoin) { //get a new null place holder variable that is the first field variable of the primary key //from the indexSubTree's datasourceScanOp newNullPlaceHolderVar = indexSubTree.getDataSourceVariables().get(0); } // TODO: We can probably do something smarter here based on selectivity or MBR area. IOptimizableFuncExpr optFuncExpr = AccessMethodUtils.chooseFirstOptFuncExpr(chosenIndex, analysisCtx); ILogicalOperator primaryIndexUnnestOp = createSecondaryToPrimaryPlan(indexSubTree, probeSubTree, chosenIndex, optFuncExpr, analysisCtx, true, isLeftOuterJoin, true, context); if (primaryIndexUnnestOp == null) { return false; } if (isLeftOuterJoin && hasGroupBy) { //reset the null place holder variable AccessMethodUtils.resetLOJNullPlaceholderVariableInGroupByOp(analysisCtx, newNullPlaceHolderVar, context); } indexSubTree.dataSourceRef.setValue(primaryIndexUnnestOp); // Change join into a select with the same condition. AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) joinRef.getValue(); SelectOperator topSelect = new SelectOperator(joinOp.getCondition(), isLeftOuterJoin, newNullPlaceHolderVar); topSelect.getInputs().add(indexSubTree.rootRef); topSelect.setExecutionMode(ExecutionMode.LOCAL); context.computeAndSetTypeEnvironmentForOperator(topSelect); // Replace the original join with the new subtree rooted at the select op. joinRef.setValue(topSelect); return true; }
From source file:edu.uci.ics.asterix.translator.AqlExpressionToPlanTranslator.java
private Pair<ILogicalExpression, Mutable<ILogicalOperator>> aqlExprToAlgExpression(Expression expr, Mutable<ILogicalOperator> topOp) throws AsterixException { switch (expr.getKind()) { case VARIABLE_EXPRESSION: { VariableReferenceExpression ve = new VariableReferenceExpression( context.getVar(((VariableExpr) expr).getVar().getId())); return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(ve, topOp); }//from w ww . ja va 2s . co m case LITERAL_EXPRESSION: { LiteralExpr val = (LiteralExpr) expr; return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(new ConstantExpression( new AsterixConstantValue(ConstantHelper.objectFromLiteral(val.getValue()))), topOp); } default: { // Mutable<ILogicalOperator> src = new // Mutable<ILogicalOperator>(); // Mutable<ILogicalOperator> src = topOp; if (expressionNeedsNoNesting(expr)) { Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, topOp); ILogicalExpression exp = ((AssignOperator) p.first).getExpressions().get(0).getValue(); return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(exp, p.first.getInputs().get(0)); } else { Mutable<ILogicalOperator> src = new MutableObject<ILogicalOperator>(); Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, src); if (((AbstractLogicalOperator) p.first).getOperatorTag() == LogicalOperatorTag.SUBPLAN) { src.setValue(topOp.getValue()); Mutable<ILogicalOperator> top2 = new MutableObject<ILogicalOperator>(p.first); return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>( new VariableReferenceExpression(p.second), top2); } else { SubplanOperator s = new SubplanOperator(); s.getInputs().add(topOp); src.setValue(new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(s))); Mutable<ILogicalOperator> planRoot = new MutableObject<ILogicalOperator>(p.first); s.setRootOp(planRoot); return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>( new VariableReferenceExpression(p.second), new MutableObject<ILogicalOperator>(s)); } } } } }
From source file:edu.uci.ics.asterix.optimizer.rules.am.InvertedIndexAccessMethod.java
@Override public boolean applyJoinPlanTransformation(Mutable<ILogicalOperator> joinRef, OptimizableOperatorSubTree leftSubTree, OptimizableOperatorSubTree rightSubTree, Index chosenIndex, AccessMethodAnalysisContext analysisCtx, IOptimizationContext context, boolean isLeftOuterJoin, boolean hasGroupBy) throws AlgebricksException { // Figure out if the index is applicable on the left or right side (if both, we arbitrarily prefer the left side). Dataset dataset = analysisCtx.indexDatasetMap.get(chosenIndex); // Determine probe and index subtrees based on chosen index. OptimizableOperatorSubTree indexSubTree = null; OptimizableOperatorSubTree probeSubTree = null; if (!isLeftOuterJoin && leftSubTree.hasDataSourceScan() && dataset.getDatasetName().equals(leftSubTree.dataset.getDatasetName())) { indexSubTree = leftSubTree;/*from w w w.j a v a 2 s . co m*/ probeSubTree = rightSubTree; } else if (rightSubTree.hasDataSourceScan() && dataset.getDatasetName().equals(rightSubTree.dataset.getDatasetName())) { indexSubTree = rightSubTree; probeSubTree = leftSubTree; } if (indexSubTree == null) { //This may happen for left outer join case return false; } IOptimizableFuncExpr optFuncExpr = AccessMethodUtils.chooseFirstOptFuncExpr(chosenIndex, analysisCtx); // The arguments of edit-distance-contains() function are asymmetrical, we can only use index // if the dataset of index subtree and the dataset of first argument's subtree is the same if (optFuncExpr.getFuncExpr().getFunctionIdentifier() == AsterixBuiltinFunctions.EDIT_DISTANCE_CONTAINS && optFuncExpr.getOperatorSubTree(0).dataset != null && !optFuncExpr.getOperatorSubTree(0).dataset .getDatasetName().equals(indexSubTree.dataset.getDatasetName())) { return false; } //if LOJ, reset null place holder variable LogicalVariable newNullPlaceHolderVar = null; if (isLeftOuterJoin && hasGroupBy) { //get a new null place holder variable that is the first field variable of the primary key //from the indexSubTree's datasourceScanOp newNullPlaceHolderVar = indexSubTree.getDataSourceVariables().get(0); //reset the null place holder variable AccessMethodUtils.resetLOJNullPlaceholderVariableInGroupByOp(analysisCtx, newNullPlaceHolderVar, context); } AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) joinRef.getValue(); // Remember the original probe subtree, and its primary-key variables, // so we can later retrieve the missing attributes via an equi join. List<LogicalVariable> originalSubTreePKs = new ArrayList<LogicalVariable>(); // Remember the primary-keys of the new probe subtree for the top-level equi join. List<LogicalVariable> surrogateSubTreePKs = new ArrayList<LogicalVariable>(); // Copy probe subtree, replacing their variables with new ones. We will use the original variables // to stitch together a top-level equi join. Mutable<ILogicalOperator> originalProbeSubTreeRootRef = copyAndReinitProbeSubTree(probeSubTree, join.getCondition().getValue(), optFuncExpr, originalSubTreePKs, surrogateSubTreePKs, context); // Remember original live variables from the index sub tree. List<LogicalVariable> indexSubTreeLiveVars = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(indexSubTree.root, indexSubTreeLiveVars); // Clone the original join condition because we may have to modify it (and we also need the original). ILogicalExpression joinCond = join.getCondition().getValue().cloneExpression(); // Create "panic" (non indexed) nested-loop join path if necessary. Mutable<ILogicalOperator> panicJoinRef = null; Map<LogicalVariable, LogicalVariable> panicVarMap = null; if (optFuncExpr.getFuncExpr().getFunctionIdentifier() == AsterixBuiltinFunctions.EDIT_DISTANCE_CHECK || optFuncExpr.getFuncExpr() .getFunctionIdentifier() == AsterixBuiltinFunctions.EDIT_DISTANCE_CONTAINS) { panicJoinRef = new MutableObject<ILogicalOperator>(joinRef.getValue()); panicVarMap = new HashMap<LogicalVariable, LogicalVariable>(); Mutable<ILogicalOperator> newProbeRootRef = createPanicNestedLoopJoinPlan(panicJoinRef, indexSubTree, probeSubTree, optFuncExpr, chosenIndex, panicVarMap, context); probeSubTree.rootRef.setValue(newProbeRootRef.getValue()); probeSubTree.root = newProbeRootRef.getValue(); } // Create regular indexed-nested loop join path. ILogicalOperator indexPlanRootOp = createSecondaryToPrimaryPlan(indexSubTree, probeSubTree, chosenIndex, optFuncExpr, true, isLeftOuterJoin, true, context); indexSubTree.dataSourceRef.setValue(indexPlanRootOp); // Change join into a select with the same condition. SelectOperator topSelect = new SelectOperator(new MutableObject<ILogicalExpression>(joinCond), isLeftOuterJoin, newNullPlaceHolderVar); topSelect.getInputs().add(indexSubTree.rootRef); topSelect.setExecutionMode(ExecutionMode.LOCAL); context.computeAndSetTypeEnvironmentForOperator(topSelect); ILogicalOperator topOp = topSelect; // Hook up the indexed-nested loop join path with the "panic" (non indexed) nested-loop join path by putting a union all on top. if (panicJoinRef != null) { LogicalVariable inputSearchVar = getInputSearchVar(optFuncExpr, indexSubTree); indexSubTreeLiveVars.addAll(originalSubTreePKs); indexSubTreeLiveVars.add(inputSearchVar); List<LogicalVariable> panicPlanLiveVars = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(panicJoinRef.getValue(), panicPlanLiveVars); // Create variable mapping for union all operator. List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = new ArrayList<Triple<LogicalVariable, LogicalVariable, LogicalVariable>>(); for (int i = 0; i < indexSubTreeLiveVars.size(); i++) { LogicalVariable indexSubTreeVar = indexSubTreeLiveVars.get(i); LogicalVariable panicPlanVar = panicVarMap.get(indexSubTreeVar); if (panicPlanVar == null) { panicPlanVar = indexSubTreeVar; } varMap.add(new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(indexSubTreeVar, panicPlanVar, indexSubTreeVar)); } UnionAllOperator unionAllOp = new UnionAllOperator(varMap); unionAllOp.getInputs().add(new MutableObject<ILogicalOperator>(topOp)); unionAllOp.getInputs().add(panicJoinRef); unionAllOp.setExecutionMode(ExecutionMode.PARTITIONED); context.computeAndSetTypeEnvironmentForOperator(unionAllOp); topOp = unionAllOp; } // Place a top-level equi-join on top to retrieve the missing variables from the original probe subtree. // The inner (build) branch of the join is the subtree with the data scan, since the result of the similarity join could potentially be big. // This choice may not always be the most efficient, but it seems more robust than the alternative. Mutable<ILogicalExpression> eqJoinConditionRef = createPrimaryKeysEqJoinCondition(originalSubTreePKs, surrogateSubTreePKs); InnerJoinOperator topEqJoin = new InnerJoinOperator(eqJoinConditionRef, originalProbeSubTreeRootRef, new MutableObject<ILogicalOperator>(topOp)); topEqJoin.setExecutionMode(ExecutionMode.PARTITIONED); joinRef.setValue(topEqJoin); context.computeAndSetTypeEnvironmentForOperator(topEqJoin); return true; }
From source file:edu.uci.ics.asterix.optimizer.rules.am.InvertedIndexAccessMethod.java
private Mutable<ILogicalOperator> createPanicNestedLoopJoinPlan(Mutable<ILogicalOperator> joinRef, OptimizableOperatorSubTree indexSubTree, OptimizableOperatorSubTree probeSubTree, IOptimizableFuncExpr optFuncExpr, Index chosenIndex, Map<LogicalVariable, LogicalVariable> panicVarMap, IOptimizationContext context) throws AlgebricksException { LogicalVariable inputSearchVar = getInputSearchVar(optFuncExpr, indexSubTree); // We split the plan into two "branches", and add selections on each side. AbstractLogicalOperator replicateOp = new ReplicateOperator(2); replicateOp.getInputs().add(new MutableObject<ILogicalOperator>(probeSubTree.root)); replicateOp.setExecutionMode(ExecutionMode.PARTITIONED); context.computeAndSetTypeEnvironmentForOperator(replicateOp); // Create select ops for removing tuples that are filterable and not filterable, respectively. IVariableTypeEnvironment probeTypeEnv = context.getOutputTypeEnvironment(probeSubTree.root); IAType inputSearchVarType;//from w ww . java 2 s. c o m if (chosenIndex.isEnforcingKeyFileds()) inputSearchVarType = optFuncExpr.getFieldType(optFuncExpr.findLogicalVar(inputSearchVar)); else inputSearchVarType = (IAType) probeTypeEnv.getVarType(inputSearchVar); Mutable<ILogicalOperator> isFilterableSelectOpRef = new MutableObject<ILogicalOperator>(); Mutable<ILogicalOperator> isNotFilterableSelectOpRef = new MutableObject<ILogicalOperator>(); createIsFilterableSelectOps(replicateOp, inputSearchVar, inputSearchVarType, optFuncExpr, chosenIndex, context, isFilterableSelectOpRef, isNotFilterableSelectOpRef); List<LogicalVariable> originalLiveVars = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(indexSubTree.root, originalLiveVars); // Copy the scan subtree in indexSubTree. Counter counter = new Counter(context.getVarCounter()); LogicalOperatorDeepCopyVisitor deepCopyVisitor = new LogicalOperatorDeepCopyVisitor(counter); ILogicalOperator scanSubTree = deepCopyVisitor.deepCopy(indexSubTree.root, null); context.setVarCounter(counter.get()); Map<LogicalVariable, LogicalVariable> copyVarMap = deepCopyVisitor.getVariableMapping(); panicVarMap.putAll(copyVarMap); List<LogicalVariable> copyLiveVars = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(scanSubTree, copyLiveVars); // Replace the inputs of the given join op, and replace variables in its // condition since we deep-copied one of the scanner subtrees which // changed variables. AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) joinRef.getValue(); for (Map.Entry<LogicalVariable, LogicalVariable> entry : copyVarMap.entrySet()) { joinOp.getCondition().getValue().substituteVar(entry.getKey(), entry.getValue()); } joinOp.getInputs().clear(); joinOp.getInputs().add(new MutableObject<ILogicalOperator>(scanSubTree)); // Make sure that the build input (which may be materialized causing blocking) comes from // the split+select, otherwise the plan will have a deadlock. joinOp.getInputs().add(isNotFilterableSelectOpRef); context.computeAndSetTypeEnvironmentForOperator(joinOp); // Return the new root of the probeSubTree. return isFilterableSelectOpRef; }
From source file:edu.uci.ics.asterix.optimizer.rules.am.IntroduceJoinAccessMethodRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { clear();/*from w w w. j a va 2s .c om*/ setMetadataDeclarations(context); // Match operator pattern and initialize optimizable sub trees. if (!matchesOperatorPattern(opRef, context)) { return false; } // Analyze condition on those optimizable subtrees that have a datasource scan. Map<IAccessMethod, AccessMethodAnalysisContext> analyzedAMs = new HashMap<IAccessMethod, AccessMethodAnalysisContext>(); boolean matchInLeftSubTree = false; boolean matchInRightSubTree = false; if (leftSubTree.hasDataSource()) { matchInLeftSubTree = analyzeCondition(joinCond, leftSubTree.assignsAndUnnests, analyzedAMs); } if (rightSubTree.hasDataSource()) { matchInRightSubTree = analyzeCondition(joinCond, rightSubTree.assignsAndUnnests, analyzedAMs); } if (!matchInLeftSubTree && !matchInRightSubTree) { return false; } // Set dataset and type metadata. AqlMetadataProvider metadataProvider = (AqlMetadataProvider) context.getMetadataProvider(); boolean checkLeftSubTreeMetadata = false; boolean checkRightSubTreeMetadata = false; if (matchInLeftSubTree) { checkLeftSubTreeMetadata = leftSubTree.setDatasetAndTypeMetadata(metadataProvider); } if (matchInRightSubTree) { checkRightSubTreeMetadata = rightSubTree.setDatasetAndTypeMetadata(metadataProvider); } if (!checkLeftSubTreeMetadata && !checkRightSubTreeMetadata) { return false; } if (checkLeftSubTreeMetadata) { fillSubTreeIndexExprs(leftSubTree, analyzedAMs, context); } if (checkRightSubTreeMetadata) { fillSubTreeIndexExprs(rightSubTree, analyzedAMs, context); } pruneIndexCandidates(analyzedAMs); //Remove possibly chosen indexes from left Tree if (isLeftOuterJoin) { Iterator<Map.Entry<IAccessMethod, AccessMethodAnalysisContext>> amIt = analyzedAMs.entrySet() .iterator(); // Check applicability of indexes by access method type. while (amIt.hasNext()) { Map.Entry<IAccessMethod, AccessMethodAnalysisContext> entry = amIt.next(); AccessMethodAnalysisContext amCtx = entry.getValue(); Iterator<Map.Entry<Index, List<Pair<Integer, Integer>>>> indexIt = amCtx.indexExprsAndVars .entrySet().iterator(); while (indexIt.hasNext()) { Map.Entry<Index, List<Pair<Integer, Integer>>> indexEntry = indexIt.next(); Index chosenIndex = indexEntry.getKey(); if (!chosenIndex.getDatasetName().equals(rightSubTree.dataset.getDatasetName())) { indexIt.remove(); } } } } // Choose index to be applied. Pair<IAccessMethod, Index> chosenIndex = chooseIndex(analyzedAMs); if (chosenIndex == null) { context.addToDontApplySet(this, join); return false; } // Apply plan transformation using chosen index. AccessMethodAnalysisContext analysisCtx = analyzedAMs.get(chosenIndex.first); //For LOJ with GroupBy, prepare objects to reset LOJ nullPlaceHolderVariable in GroupByOp if (isLeftOuterJoin && hasGroupBy) { analysisCtx.setLOJGroupbyOpRef(opRef); ScalarFunctionCallExpression isNullFuncExpr = AccessMethodUtils .findLOJIsNullFuncInGroupBy((GroupByOperator) opRef.getValue()); analysisCtx.setLOJIsNullFuncInGroupBy(isNullFuncExpr); } boolean res = chosenIndex.first.applyJoinPlanTransformation(joinRef, leftSubTree, rightSubTree, chosenIndex.second, analysisCtx, context, isLeftOuterJoin, hasGroupBy); if (res) { OperatorPropertiesUtil.typeOpRec(opRef, context); } context.addToDontApplySet(this, join); return res; }
From source file:org.apache.asterix.app.resource.RequiredCapacityVisitor.java
private void visitInternal(ILogicalOperator op, boolean toAddOuputBuffer) throws AlgebricksException { for (Mutable<ILogicalOperator> inputOpRef : op.getInputs()) { inputOpRef.getValue().accept(this, null); }/*from w w w . j a v a2 s . c o m*/ if (toAddOuputBuffer) { addOutputBuffer(op); } setAvailableCores(op); }
From source file:org.apache.asterix.bad.rules.InsertBrokerNotifierForChannelRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue(); if (op1.getOperatorTag() != LogicalOperatorTag.DISTRIBUTE_RESULT) { return false; }/*from ww w .j a v a 2s . co m*/ boolean push = false; AbstractLogicalOperator op = (AbstractLogicalOperator) op1.getInputs().get(0).getValue(); if (op.getOperatorTag() != LogicalOperatorTag.DELEGATE_OPERATOR) { if (op.getOperatorTag() != LogicalOperatorTag.PROJECT) { return false; } push = true; } DataSourceScanOperator subscriptionsScan; String channelDataverse; String channelName; if (!push) { DelegateOperator eOp = (DelegateOperator) op; if (!(eOp.getDelegate() instanceof CommitOperator)) { return false; } AbstractLogicalOperator descendantOp = (AbstractLogicalOperator) eOp.getInputs().get(0).getValue(); if (descendantOp.getOperatorTag() != LogicalOperatorTag.INSERT_DELETE_UPSERT) { return false; } InsertDeleteUpsertOperator insertOp = (InsertDeleteUpsertOperator) descendantOp; if (insertOp.getOperation() != InsertDeleteUpsertOperator.Kind.INSERT) { return false; } DatasetDataSource dds = (DatasetDataSource) insertOp.getDataSource(); String datasetName = dds.getDataset().getDatasetName(); if (!dds.getDataset().getItemTypeDataverseName().equals("Metadata") || !dds.getDataset().getItemTypeName().equals("ChannelResultsType") || !datasetName.endsWith("Results")) { return false; } channelDataverse = dds.getDataset().getDataverseName(); //Now we know that we are inserting into results channelName = datasetName.substring(0, datasetName.length() - 7); String subscriptionsName = channelName + "Subscriptions"; subscriptionsScan = (DataSourceScanOperator) findOp(op, subscriptionsName); if (subscriptionsScan == null) { return false; } } else { //if push, get the channel name here instead subscriptionsScan = (DataSourceScanOperator) findOp(op, ""); if (subscriptionsScan == null) { return false; } DatasetDataSource dds = (DatasetDataSource) subscriptionsScan.getDataSource(); String datasetName = dds.getDataset().getDatasetName(); channelDataverse = dds.getDataset().getDataverseName(); channelName = datasetName.substring(0, datasetName.length() - 13); } //Now we need to get the broker EndPoint LogicalVariable brokerEndpointVar = context.newVar(); AbstractLogicalOperator opAboveBrokersScan = findOp(op, "brokers"); if (opAboveBrokersScan == null) { return false; } //get subscriptionIdVar LogicalVariable subscriptionIdVar = subscriptionsScan.getVariables().get(0); //The channelExecutionTime is created just before the scan ILogicalOperator channelExecutionAssign = subscriptionsScan.getInputs().get(0).getValue(); if (channelExecutionAssign.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return false; } LogicalVariable channelExecutionVar = ((AssignOperator) channelExecutionAssign).getVariables().get(0); if (!channelExecutionVar.toString().equals("$$" + BADConstants.ChannelExecutionTime)) { return false; } if (!push) { ((CommitOperator) ((DelegateOperator) op).getDelegate()).setSink(false); } AssignOperator assignOp = createbrokerEndPointAssignOperator(brokerEndpointVar, opAboveBrokersScan); //now brokerNameVar holds the brokerName for use farther up in the plan context.computeAndSetTypeEnvironmentForOperator(assignOp); context.computeAndSetTypeEnvironmentForOperator(opAboveBrokersScan); context.computeAndSetTypeEnvironmentForOperator(op); ProjectOperator badProject = (ProjectOperator) findOp(op1, "project"); badProject.getVariables().add(subscriptionIdVar); badProject.getVariables().add(brokerEndpointVar); badProject.getVariables().add(channelExecutionVar); context.computeAndSetTypeEnvironmentForOperator(badProject); //Create my brokerNotify plan above the extension Operator DelegateOperator dOp = push ? createNotifyBrokerPushPlan(brokerEndpointVar, badProject.getVariables().get(0), channelExecutionVar, context, op, (DistributeResultOperator) op1, channelDataverse, channelName) : createNotifyBrokerPullPlan(brokerEndpointVar, subscriptionIdVar, channelExecutionVar, context, op, (DistributeResultOperator) op1, channelDataverse, channelName); opRef.setValue(dOp); return true; }
From source file:org.apache.asterix.bad.rules.InsertBrokerNotifierForChannelRule.java
private AssignOperator createbrokerEndPointAssignOperator(LogicalVariable brokerEndpointVar, AbstractLogicalOperator opAboveBrokersScan) { Mutable<ILogicalExpression> fieldRef = new MutableObject<ILogicalExpression>( new ConstantExpression(new AsterixConstantValue(new AString(BADConstants.BrokerEndPoint)))); DataSourceScanOperator brokerScan = null; int index = 0; for (Mutable<ILogicalOperator> subOp : opAboveBrokersScan.getInputs()) { if (isBrokerScan((AbstractLogicalOperator) subOp.getValue())) { brokerScan = (DataSourceScanOperator) subOp.getValue(); break; }/*from w w w . j ava 2s.c o m*/ index++; } Mutable<ILogicalExpression> varRef = new MutableObject<ILogicalExpression>( new VariableReferenceExpression(brokerScan.getVariables().get(2))); ScalarFunctionCallExpression fieldAccessByName = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_NAME), varRef, fieldRef); ArrayList<LogicalVariable> varArray = new ArrayList<LogicalVariable>(1); varArray.add(brokerEndpointVar); ArrayList<Mutable<ILogicalExpression>> exprArray = new ArrayList<Mutable<ILogicalExpression>>(1); exprArray.add(new MutableObject<ILogicalExpression>(fieldAccessByName)); AssignOperator assignOp = new AssignOperator(varArray, exprArray); //Place assignOp between the scan and the op above it assignOp.getInputs().add(new MutableObject<ILogicalOperator>(brokerScan)); opAboveBrokersScan.getInputs().set(index, new MutableObject<ILogicalOperator>(assignOp)); return assignOp; }
From source file:org.apache.asterix.bad.rules.InsertBrokerNotifierForChannelRule.java
private AbstractLogicalOperator findOp(AbstractLogicalOperator op, String lookingForString) { if (!op.hasInputs()) { return null; }// w w w. jav a 2s.com for (Mutable<ILogicalOperator> subOp : op.getInputs()) { if (lookingForString.equals("brokers")) { if (isBrokerScan((AbstractLogicalOperator) subOp.getValue())) { return op; } else { AbstractLogicalOperator nestedOp = findOp((AbstractLogicalOperator) subOp.getValue(), lookingForString); if (nestedOp != null) { return nestedOp; } } } else if (lookingForString.equals("project")) { if (subOp.getValue().getOperatorTag() == LogicalOperatorTag.PROJECT) { return (AbstractLogicalOperator) subOp.getValue(); } else { AbstractLogicalOperator nestedOp = findOp((AbstractLogicalOperator) subOp.getValue(), lookingForString); if (nestedOp != null) { return nestedOp; } } } else { if (isSubscriptionsScan((AbstractLogicalOperator) subOp.getValue(), lookingForString)) { return (AbstractLogicalOperator) subOp.getValue(); } else { AbstractLogicalOperator nestedOp = findOp((AbstractLogicalOperator) subOp.getValue(), lookingForString); if (nestedOp != null) { return nestedOp; } } } } return null; }
From source file:org.apache.asterix.jobgen.QueryLogicalExpressionJobGen.java
private IScalarEvaluatorFactory[] codegenArguments(AbstractFunctionCallExpression expr, IVariableTypeEnvironment env, IOperatorSchema[] inputSchemas, JobGenContext context) throws AlgebricksException { List<Mutable<ILogicalExpression>> arguments = expr.getArguments(); int n = arguments.size(); IScalarEvaluatorFactory[] args = new IScalarEvaluatorFactory[n]; int i = 0;//from www .j a va2 s.com for (Mutable<ILogicalExpression> a : arguments) { args[i++] = createEvaluatorFactory(a.getValue(), env, inputSchemas, context); } return args; }