List of usage examples for org.apache.commons.lang3.mutable MutableObject MutableObject
public MutableObject(final T value)
From source file:edu.uci.ics.asterix.optimizer.rules.PushFieldAccessRule.java
@SuppressWarnings("unchecked") private boolean propagateFieldAccessRec(Mutable<ILogicalOperator> opRef, IOptimizationContext context, String finalAnnot) throws AlgebricksException { AssignOperator access = (AssignOperator) opRef.getValue(); Mutable<ILogicalOperator> opRef2 = access.getInputs().get(0); AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue(); // If it's not an indexed field, it is pushed so that scan can be // rewritten into index search. if (op2.getOperatorTag() == LogicalOperatorTag.PROJECT || context.checkAndAddToAlreadyCompared(access, op2) && !(op2.getOperatorTag() == LogicalOperatorTag.SELECT && isAccessToIndexedField(access, context))) { return false; }//from ww w .ja va 2s . com if (tryingToPushThroughSelectionWithSameDataSource(access, op2)) { return false; } if (testAndModifyRedundantOp(access, op2)) { propagateFieldAccessRec(opRef2, context, finalAnnot); return true; } List<LogicalVariable> usedInAccess = new LinkedList<LogicalVariable>(); VariableUtilities.getUsedVariables(access, usedInAccess); List<LogicalVariable> produced2 = new LinkedList<LogicalVariable>(); if (op2.getOperatorTag() == LogicalOperatorTag.GROUP) { VariableUtilities.getLiveVariables(op2, produced2); } else { VariableUtilities.getProducedVariables(op2, produced2); } boolean pushItDown = false; List<LogicalVariable> inter = new ArrayList<LogicalVariable>(usedInAccess); if (inter.isEmpty()) { // ground value return false; } inter.retainAll(produced2); if (inter.isEmpty()) { pushItDown = true; } else if (op2.getOperatorTag() == LogicalOperatorTag.GROUP) { GroupByOperator g = (GroupByOperator) op2; List<Pair<LogicalVariable, LogicalVariable>> varMappings = new ArrayList<Pair<LogicalVariable, LogicalVariable>>(); for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : g.getDecorList()) { ILogicalExpression e = p.second.getValue(); if (e.getExpressionTag() == LogicalExpressionTag.VARIABLE) { LogicalVariable decorVar = GroupByOperator.getDecorVariable(p); if (inter.contains(decorVar)) { inter.remove(decorVar); LogicalVariable v1 = ((VariableReferenceExpression) e).getVariableReference(); varMappings.add(new Pair<LogicalVariable, LogicalVariable>(decorVar, v1)); } } } if (inter.isEmpty()) { boolean changed = false; for (Pair<LogicalVariable, LogicalVariable> m : varMappings) { LogicalVariable v2 = context.newVar(); LogicalVariable oldVar = access.getVariables().get(0); g.getDecorList().add(new Pair<LogicalVariable, Mutable<ILogicalExpression>>(oldVar, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(v2)))); changed = true; access.getVariables().set(0, v2); VariableUtilities.substituteVariables(access, m.first, m.second, context); } if (changed) { context.computeAndSetTypeEnvironmentForOperator(g); } usedInAccess.clear(); VariableUtilities.getUsedVariables(access, usedInAccess); pushItDown = true; } } if (pushItDown) { if (op2.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) { Mutable<ILogicalOperator> childOfSubplan = ((NestedTupleSourceOperator) op2) .getDataSourceReference().getValue().getInputs().get(0); pushAccessDown(opRef, op2, childOfSubplan, context, finalAnnot); return true; } if (op2.getInputs().size() == 1 && !op2.hasNestedPlans()) { pushAccessDown(opRef, op2, op2.getInputs().get(0), context, finalAnnot); return true; } else { for (Mutable<ILogicalOperator> inp : op2.getInputs()) { HashSet<LogicalVariable> v2 = new HashSet<LogicalVariable>(); VariableUtilities.getLiveVariables(inp.getValue(), v2); if (v2.containsAll(usedInAccess)) { pushAccessDown(opRef, op2, inp, context, finalAnnot); return true; } } } if (op2.hasNestedPlans()) { AbstractOperatorWithNestedPlans nestedOp = (AbstractOperatorWithNestedPlans) op2; for (ILogicalPlan plan : nestedOp.getNestedPlans()) { for (Mutable<ILogicalOperator> root : plan.getRoots()) { HashSet<LogicalVariable> v2 = new HashSet<LogicalVariable>(); VariableUtilities.getLiveVariables(root.getValue(), v2); if (v2.containsAll(usedInAccess)) { pushAccessDown(opRef, op2, root, context, finalAnnot); return true; } } } } throw new AsterixRuntimeException("Field access " + access.getExpressions().get(0).getValue() + " does not correspond to any input of operator " + op2); } else { // Check if the accessed field is not one of the partitioning key // fields. If yes, we can equate the two variables. if (op2.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) { DataSourceScanOperator scan = (DataSourceScanOperator) op2; int n = scan.getVariables().size(); LogicalVariable scanRecordVar = scan.getVariables().get(n - 1); AbstractFunctionCallExpression accessFun = (AbstractFunctionCallExpression) access.getExpressions() .get(0).getValue(); ILogicalExpression e0 = accessFun.getArguments().get(0).getValue(); LogicalExpressionTag tag = e0.getExpressionTag(); if (tag == LogicalExpressionTag.VARIABLE) { VariableReferenceExpression varRef = (VariableReferenceExpression) e0; if (varRef.getVariableReference() == scanRecordVar) { ILogicalExpression e1 = accessFun.getArguments().get(1).getValue(); if (e1.getExpressionTag() == LogicalExpressionTag.CONSTANT) { IDataSource<AqlSourceId> dataSource = (IDataSource<AqlSourceId>) scan.getDataSource(); AqlDataSourceType dsType = ((AqlDataSource) dataSource).getDatasourceType(); if (dsType == AqlDataSourceType.FEED || dsType == AqlDataSourceType.LOADABLE) { return false; } AqlSourceId asid = dataSource.getId(); AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider(); Dataset dataset = mp.findDataset(asid.getDataverseName(), asid.getDatasourceName()); if (dataset == null) { throw new AlgebricksException( "Dataset " + asid.getDatasourceName() + " not found."); } if (dataset.getDatasetType() != DatasetType.INTERNAL) { setAsFinal(access, context, finalAnnot); return false; } ConstantExpression ce = (ConstantExpression) e1; IAObject obj = ((AsterixConstantValue) ce.getValue()).getObject(); String fldName; if (obj.getType().getTypeTag() == ATypeTag.STRING) { fldName = ((AString) obj).getStringValue(); } else { int pos = ((AInt32) obj).getIntegerValue(); String tName = dataset.getItemTypeName(); IAType t = mp.findType(dataset.getDataverseName(), tName); if (t.getTypeTag() != ATypeTag.RECORD) { return false; } ARecordType rt = (ARecordType) t; if (pos >= rt.getFieldNames().length) { setAsFinal(access, context, finalAnnot); return false; } fldName = rt.getFieldNames()[pos]; } int p = DatasetUtils.getPositionOfPartitioningKeyField(dataset, fldName); if (p < 0) { // not one of the partitioning fields setAsFinal(access, context, finalAnnot); return false; } LogicalVariable keyVar = scan.getVariables().get(p); access.getExpressions().get(0).setValue(new VariableReferenceExpression(keyVar)); return true; } } } } setAsFinal(access, context, finalAnnot); return false; } }
From source file:edu.uci.ics.asterix.optimizer.rules.SimilarityCheckRule.java
private boolean replaceWithFunctionCallArg(Mutable<ILogicalExpression> expRef, FunctionIdentifier normFuncIdent, AsterixConstantValue constVal, AbstractFunctionCallExpression funcExpr) throws AlgebricksException { // Analyze func expr to see if it is an optimizable similarity function. ScalarFunctionCallExpression simCheckFuncExpr = getSimilarityCheckExpr(normFuncIdent, constVal, funcExpr); // Replace the expr in the select condition. if (simCheckFuncExpr != null) { // Get item 0 from var. List<Mutable<ILogicalExpression>> getItemArgs = new ArrayList<Mutable<ILogicalExpression>>(); // First arg is the similarity-check function call. getItemArgs.add(new MutableObject<ILogicalExpression>(simCheckFuncExpr)); // Second arg is the item index to be accessed. getItemArgs.add(new MutableObject<ILogicalExpression>( new ConstantExpression(new AsterixConstantValue(new AInt32(0))))); ILogicalExpression getItemExpr = new ScalarFunctionCallExpression( FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.GET_ITEM), getItemArgs); // Replace the old similarity function call with the new getItemExpr. expRef.setValue(getItemExpr);// w w w .j av a 2s .c om return true; } return false; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.IntroduceGroupByForSubplanRule.java
private Map<LogicalVariable, LogicalVariable> buildVarExprList(Collection<LogicalVariable> vars, IOptimizationContext context, GroupByOperator g, List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> outVeList) throws AlgebricksException { Map<LogicalVariable, LogicalVariable> m = new HashMap<LogicalVariable, LogicalVariable>(); for (LogicalVariable ov : vars) { LogicalVariable newVar = context.newVar(); ILogicalExpression varExpr = new VariableReferenceExpression(newVar); outVeList.add(new Pair<LogicalVariable, Mutable<ILogicalExpression>>(ov, new MutableObject<ILogicalExpression>(varExpr))); for (ILogicalPlan p : g.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { OperatorManipulationUtil.substituteVarRec((AbstractLogicalOperator) r.getValue(), ov, newVar, true, context);/*from w w w . j a v a 2s . com*/ } } AbstractLogicalOperator opUnder = (AbstractLogicalOperator) g.getInputs().get(0).getValue(); OperatorManipulationUtil.substituteVarRec(opUnder, ov, newVar, true, context); m.put(ov, newVar); } return m; }
From source file:edu.uci.ics.hyracks.algebricks.examples.piglet.compiler.PigletCompiler.java
private Relation translate(RelationNode rn, Map<String, Relation> symMap) throws PigletException { switch (rn.getTag()) { case LOAD: {//from www. j a v a 2s . c o m LoadNode ln = (LoadNode) rn; String file = ln.getDataFile(); Schema schema = ln.getSchema(); List<Pair<String, Type>> fieldsSchema = schema.getSchema(); List<LogicalVariable> variables = new ArrayList<LogicalVariable>(); List<Object> types = new ArrayList<Object>(); Relation rel = new Relation(); for (Pair<String, Type> p : fieldsSchema) { LogicalVariable v = newVariable(); rel.schema.put(p.first, v); variables.add(v); types.add(p.second); } PigletFileDataSource ds = new PigletFileDataSource(file, types.toArray()); rel.op = new DataSourceScanOperator(variables, ds); rel.op.getInputs().add(new MutableObject<ILogicalOperator>( previousOp == null ? new EmptyTupleSourceOperator() : previousOp)); return rel; } case FILTER: { FilterNode fn = (FilterNode) rn; String alias = fn.getAlias(); ExpressionNode conditionNode = fn.getExpression(); Relation inputRel = findInputRelation(alias, symMap); Pair<Relation, LogicalVariable> tempInput = translateScalarExpression(inputRel, conditionNode); Relation rel = new Relation(); rel.op = new SelectOperator( new MutableObject<ILogicalExpression>(new VariableReferenceExpression(tempInput.second)), false, null); rel.op.getInputs().add(new MutableObject<ILogicalOperator>(tempInput.first.op)); rel.schema.putAll(tempInput.first.schema); return rel; } } throw new IllegalArgumentException("Unknown node: " + rn.getTag() + " encountered"); }
From source file:edu.uci.ics.asterix.translator.AqlPlusExpressionToPlanTranslator.java
public ILogicalPlan translate(Query expr, AqlMetadataProvider metadata) throws AlgebricksException, AsterixException { IDataFormat format = metadata.getFormat(); if (format == null) { throw new AlgebricksException("Data format has not been set."); }/*from ww w . j a va 2 s .c o m*/ format.registerRuntimeFunctions(); Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, new MutableObject<ILogicalOperator>(new EmptyTupleSourceOperator())); ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<Mutable<ILogicalOperator>>(); boolean isTransactionalWrite = false; ILogicalOperator topOp = p.first; ProjectOperator project = (ProjectOperator) topOp; LogicalVariable resVar = project.getVariables().get(0); if (outputDatasetName == null) { List<Mutable<ILogicalExpression>> writeExprList = new ArrayList<Mutable<ILogicalExpression>>(1); writeExprList.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(resVar))); FileSplitSinkId fssi = new FileSplitSinkId(metadata.getOutputFile()); FileSplitDataSink sink = new FileSplitDataSink(fssi, null); topOp = new WriteOperator(writeExprList, sink); topOp.getInputs().add(new MutableObject<ILogicalOperator>(project)); } else { Dataset dataset = metadata.findDataset(stmt.getDataverseName(), outputDatasetName); if (dataset == null) { throw new AlgebricksException("Cannot find dataset " + outputDatasetName); } if (dataset.getDatasetType() == DatasetType.EXTERNAL) { throw new AlgebricksException("Cannot write output to an external dataset."); } ARecordType itemType = (ARecordType) metadata.findType(dataset.getDataverseName(), dataset.getItemTypeName()); List<List<String>> partitioningKeys = DatasetUtils.getPartitioningKeys(dataset); ArrayList<LogicalVariable> vars = new ArrayList<LogicalVariable>(); ArrayList<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>(); List<Mutable<ILogicalExpression>> varRefsForLoading = new ArrayList<Mutable<ILogicalExpression>>(); for (List<String> partitioningKey : partitioningKeys) { Triple<ICopyEvaluatorFactory, ScalarFunctionCallExpression, IAType> partitioner = format .partitioningEvaluatorFactory(itemType, partitioningKey); AbstractFunctionCallExpression f = partitioner.second.cloneExpression(); f.substituteVar(METADATA_DUMMY_VAR, resVar); exprs.add(new MutableObject<ILogicalExpression>(f)); LogicalVariable v = context.newVar(); vars.add(v); varRefsForLoading.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(v))); } AssignOperator assign = new AssignOperator(vars, exprs); assign.getInputs().add(new MutableObject<ILogicalOperator>(project)); } globalPlanRoots.add(new MutableObject<ILogicalOperator>(topOp)); ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots); return plan; }
From source file:edu.uci.ics.asterix.translator.AqlExpressionToPlanTranslator.java
public ILogicalPlan translateLoad() throws AlgebricksException { CompiledLoadFromFileStatement clffs = (CompiledLoadFromFileStatement) stmt; Dataset dataset = metadataProvider.findDataset(clffs.getDataverseName(), clffs.getDatasetName()); if (dataset == null) { // This would never happen since we check for this in AqlTranslator throw new AlgebricksException( "Unable to load dataset " + clffs.getDatasetName() + " since it does not exist"); }//from w ww. j av a 2 s . co m IAType itemType = metadataProvider.findType(clffs.getDataverseName(), dataset.getItemTypeName()); DatasetDataSource targetDatasource = validateDatasetInfo(metadataProvider, stmt.getDataverseName(), stmt.getDatasetName()); List<List<String>> partitionKeys = DatasetUtils.getPartitioningKeys(targetDatasource.getDataset()); LoadableDataSource lds; try { lds = new LoadableDataSource(dataset, itemType, clffs.getAdapter(), clffs.getProperties()); } catch (IOException e) { throw new AlgebricksException(e); } // etsOp is a dummy input operator used to keep the compiler happy. it // could be removed but would result in // the need to fix many rewrite rules that assume that datasourcescan // operators always have input. ILogicalOperator etsOp = new EmptyTupleSourceOperator(); // Add a logical variable for the record. List<LogicalVariable> payloadVars = new ArrayList<LogicalVariable>(); payloadVars.add(context.newVar()); // Create a scan operator and make the empty tuple source its input DataSourceScanOperator dssOp = new DataSourceScanOperator(payloadVars, lds); dssOp.getInputs().add(new MutableObject<ILogicalOperator>(etsOp)); ILogicalExpression payloadExpr = new VariableReferenceExpression(payloadVars.get(0)); Mutable<ILogicalExpression> payloadRef = new MutableObject<ILogicalExpression>(payloadExpr); // Creating the assign to extract the PK out of the record ArrayList<LogicalVariable> pkVars = new ArrayList<LogicalVariable>(); ArrayList<Mutable<ILogicalExpression>> pkExprs = new ArrayList<Mutable<ILogicalExpression>>(); List<Mutable<ILogicalExpression>> varRefsForLoading = new ArrayList<Mutable<ILogicalExpression>>(); LogicalVariable payloadVar = payloadVars.get(0); for (List<String> keyFieldName : partitionKeys) { prepareVarAndExpression(keyFieldName, payloadVar, pkVars, pkExprs, varRefsForLoading); } AssignOperator assign = new AssignOperator(pkVars, pkExprs); assign.getInputs().add(new MutableObject<ILogicalOperator>(dssOp)); // If the input is pre-sorted, we set the ordering property explicitly in the assign if (clffs.alreadySorted()) { List<OrderColumn> orderColumns = new ArrayList<OrderColumn>(); for (int i = 0; i < pkVars.size(); ++i) { orderColumns.add(new OrderColumn(pkVars.get(i), OrderKind.ASC)); } assign.setExplicitOrderingProperty(new LocalOrderProperty(orderColumns)); } List<String> additionalFilteringField = DatasetUtils.getFilterField(targetDatasource.getDataset()); List<LogicalVariable> additionalFilteringVars = null; List<Mutable<ILogicalExpression>> additionalFilteringAssignExpressions = null; List<Mutable<ILogicalExpression>> additionalFilteringExpressions = null; AssignOperator additionalFilteringAssign = null; if (additionalFilteringField != null) { additionalFilteringVars = new ArrayList<LogicalVariable>(); additionalFilteringAssignExpressions = new ArrayList<Mutable<ILogicalExpression>>(); additionalFilteringExpressions = new ArrayList<Mutable<ILogicalExpression>>(); prepareVarAndExpression(additionalFilteringField, payloadVar, additionalFilteringVars, additionalFilteringAssignExpressions, additionalFilteringExpressions); additionalFilteringAssign = new AssignOperator(additionalFilteringVars, additionalFilteringAssignExpressions); } InsertDeleteOperator insertOp = new InsertDeleteOperator(targetDatasource, payloadRef, varRefsForLoading, InsertDeleteOperator.Kind.INSERT, true); insertOp.setAdditionalFilteringExpressions(additionalFilteringExpressions); if (additionalFilteringAssign != null) { additionalFilteringAssign.getInputs().add(new MutableObject<ILogicalOperator>(assign)); insertOp.getInputs().add(new MutableObject<ILogicalOperator>(additionalFilteringAssign)); } else { insertOp.getInputs().add(new MutableObject<ILogicalOperator>(assign)); } ILogicalOperator leafOperator = new SinkOperator(); leafOperator.getInputs().add(new MutableObject<ILogicalOperator>(insertOp)); return new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(leafOperator)); }
From source file:edu.uci.ics.asterix.optimizer.rules.SimilarityCheckRule.java
private ScalarFunctionCallExpression getSimilarityCheckExpr(FunctionIdentifier normFuncIdent, AsterixConstantValue constVal, AbstractFunctionCallExpression funcExpr) throws AlgebricksException { // Remember args from original similarity function to add them to the similarity-check function later. ArrayList<Mutable<ILogicalExpression>> similarityArgs = null; ScalarFunctionCallExpression simCheckFuncExpr = null; // Look for jaccard function call, and GE or GT. if (funcExpr.getFunctionIdentifier() == AsterixBuiltinFunctions.SIMILARITY_JACCARD) { IAObject jaccThresh;//w w w. j ava2s . c om if (normFuncIdent == AlgebricksBuiltinFunctions.GE) { if (constVal.getObject() instanceof AFloat) { jaccThresh = constVal.getObject(); } else { jaccThresh = new AFloat((float) ((ADouble) constVal.getObject()).getDoubleValue()); } } else if (normFuncIdent == AlgebricksBuiltinFunctions.GT) { float threshVal = 0.0f; if (constVal.getObject() instanceof AFloat) { threshVal = ((AFloat) constVal.getObject()).getFloatValue(); } else { threshVal = (float) ((ADouble) constVal.getObject()).getDoubleValue(); } float f = threshVal + Float.MIN_VALUE; if (f > 1.0f) f = 1.0f; jaccThresh = new AFloat(f); } else { return null; } similarityArgs = new ArrayList<Mutable<ILogicalExpression>>(); similarityArgs.addAll(funcExpr.getArguments()); similarityArgs.add(new MutableObject<ILogicalExpression>( new ConstantExpression(new AsterixConstantValue(jaccThresh)))); simCheckFuncExpr = new ScalarFunctionCallExpression( FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.SIMILARITY_JACCARD_CHECK), similarityArgs); } // Look for edit-distance function call, and LE or LT. if (funcExpr.getFunctionIdentifier() == AsterixBuiltinFunctions.EDIT_DISTANCE) { AInt32 aInt = new AInt32(0); try { aInt = (AInt32) ATypeHierarchy.convertNumericTypeObject(constVal.getObject(), ATypeTag.INT32); } catch (AsterixException e) { throw new AlgebricksException(e); } AInt32 edThresh; if (normFuncIdent == AlgebricksBuiltinFunctions.LE) { edThresh = aInt; } else if (normFuncIdent == AlgebricksBuiltinFunctions.LT) { int ed = aInt.getIntegerValue() - 1; if (ed < 0) ed = 0; edThresh = new AInt32(ed); } else { return null; } similarityArgs = new ArrayList<Mutable<ILogicalExpression>>(); similarityArgs.addAll(funcExpr.getArguments()); similarityArgs.add(new MutableObject<ILogicalExpression>( new ConstantExpression(new AsterixConstantValue(edThresh)))); simCheckFuncExpr = new ScalarFunctionCallExpression( FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.EDIT_DISTANCE_CHECK), similarityArgs); } // Preserve all annotations. if (simCheckFuncExpr != null) { simCheckFuncExpr.getAnnotations().putAll(funcExpr.getAnnotations()); } return simCheckFuncExpr; }
From source file:edu.uci.ics.hyracks.algebricks.examples.piglet.compiler.PigletCompiler.java
private Pair<Relation, LogicalVariable> translateScalarExpression(Relation inputRel, ExpressionNode expressionNode) throws PigletException { switch (expressionNode.getTag()) { case FIELD_ACCESS: { FieldAccessExpressionNode faen = (FieldAccessExpressionNode) expressionNode; String fieldName = faen.getFieldName(); LogicalVariable lVar = findField(fieldName, inputRel.schema); return new Pair<Relation, LogicalVariable>(inputRel, lVar); }/*from ww w. ja v a 2 s . c o m*/ case LITERAL: { LiteralExpressionNode len = (LiteralExpressionNode) expressionNode; String image = len.getImage(); Type type = len.getType(); ConstantExpression ce = new ConstantExpression(new ConstantValue(type, image)); Relation rel = new Relation(); LogicalVariable var = newVariable(); List<LogicalVariable> vars = new ArrayList<LogicalVariable>(); vars.add(var); List<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>(); exprs.add(new MutableObject<ILogicalExpression>(ce)); rel.op = new AssignOperator(vars, exprs); rel.op.getInputs().add(new MutableObject<ILogicalOperator>(inputRel.op)); rel.schema.putAll(inputRel.schema); return new Pair<Relation, LogicalVariable>(rel, var); } case SCALAR_FUNCTION: { ScalarFunctionExpressionNode sfen = (ScalarFunctionExpressionNode) expressionNode; List<Mutable<ILogicalExpression>> argExprs = new ArrayList<Mutable<ILogicalExpression>>(); List<ASTNode> arguments = sfen.getArguments(); Relation rel = inputRel; for (ASTNode a : arguments) { Pair<Relation, LogicalVariable> argPair = translateScalarExpression(rel, (ExpressionNode) a); rel = argPair.first; argExprs.add( new MutableObject<ILogicalExpression>(new VariableReferenceExpression(argPair.second))); } Relation outRel = new Relation(); outRel.schema.putAll(rel.schema); LogicalVariable var = newVariable(); List<LogicalVariable> vars = new ArrayList<LogicalVariable>(); vars.add(var); IFunctionInfo fInfo = lookupFunction(sfen.getFunctionTag(), sfen.getFunctionName()); List<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>(); exprs.add(new MutableObject<ILogicalExpression>(new ScalarFunctionCallExpression(fInfo, argExprs))); outRel.op = new AssignOperator(vars, exprs); outRel.op.getInputs().add(new MutableObject<ILogicalOperator>(rel.op)); return new Pair<Relation, LogicalVariable>(outRel, var); } } return null; }
From source file:edu.uci.ics.asterix.algebra.base.LogicalOperatorDeepCopyVisitor.java
@Override public ILogicalOperator visitNestedTupleSourceOperator(NestedTupleSourceOperator op, ILogicalOperator arg) throws AlgebricksException { NestedTupleSourceOperator opCopy = new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(arg)); deepCopyInputs(op, opCopy, arg);// w w w. j ava2 s. c o m copyAnnotations(op, opCopy); opCopy.setExecutionMode(op.getExecutionMode()); return opCopy; }
From source file:edu.uci.ics.asterix.optimizer.rules.PushAggregateIntoGroupbyRule.java
private void rewriteGroupByAggregate(LogicalVariable oldAggVar, GroupByOperator gbyOp, AggregateFunctionCallExpression aggFun, LogicalVariable newAggVar, IOptimizationContext context) throws AlgebricksException { for (int j = 0; j < gbyOp.getNestedPlans().size(); j++) { AggregateOperator aggOp = (AggregateOperator) gbyOp.getNestedPlans().get(j).getRoots().get(0) .getValue();//from w w w .j a v a2 s . c o m int n = aggOp.getVariables().size(); for (int i = 0; i < n; i++) { LogicalVariable v = aggOp.getVariables().get(i); if (v.equals(oldAggVar)) { AbstractFunctionCallExpression oldAggExpr = (AbstractFunctionCallExpression) aggOp .getExpressions().get(i).getValue(); AggregateFunctionCallExpression newAggFun = AsterixBuiltinFunctions .makeAggregateFunctionExpression(aggFun.getFunctionIdentifier(), new ArrayList<Mutable<ILogicalExpression>>()); for (Mutable<ILogicalExpression> arg : oldAggExpr.getArguments()) { ILogicalExpression cloned = ((AbstractLogicalExpression) arg.getValue()).cloneExpression(); newAggFun.getArguments().add(new MutableObject<ILogicalExpression>(cloned)); } aggOp.getVariables().add(newAggVar); aggOp.getExpressions().add(new MutableObject<ILogicalExpression>(newAggFun)); context.computeAndSetTypeEnvironmentForOperator(aggOp); break; } } } }