@Override public ILogicalOperator visitUnnestOperator(UnnestOperator op, Void arg) throws AlgebricksException { return new UnnestOperator(op.getVariable(), deepCopyExpressionRef(op.getExpressionRef()), op.getPositionalVariable(), op.getPositionalVariableType(), op.getPositionWriter()); }
AbstractLogicalOperator op2 = (AbstractLogicalOperator) unnest.getInputs().get(0).getValue(); if (op2.getOperatorTag() != LogicalOperatorTag.DATASOURCESCAN) { return false; if (!updateDataSource(ds, unnest.getExpressionRef())) { return false; Mutable<ILogicalExpression> varExp = ExpressionToolbox.findVariableExpression(unnest.getExpressionRef(), datascan.getVariables().get(0)); AssignOperator noOp = new AssignOperator(unnest.getVariable(), varExp); noOp.getInputs().addAll(unnest.getInputs()); opRef.setValue(noOp); return true;
@Override public Boolean visitUnnestOperator(UnnestOperator op, ILogicalOperator arg) throws AlgebricksException { AbstractLogicalOperator aop = (AbstractLogicalOperator) arg; if (aop.getOperatorTag() != LogicalOperatorTag.UNNEST) { return Boolean.FALSE; } UnnestOperator unnestOpArg = (UnnestOperator) copyAndSubstituteVar(op, arg); boolean isomorphic = VariableUtilities.varListEqualUnordered(op.getVariables(), unnestOpArg.getVariables()) && variableEqual(op.getPositionalVariable(), unnestOpArg.getPositionalVariable()); if (!isomorphic) { return Boolean.FALSE; } isomorphic = op.getExpressionRef().getValue().equals(unnestOpArg.getExpressionRef().getValue()); return isomorphic; }
@Override public Void visitUnnestOperator(UnnestOperator op, Integer indent) throws AlgebricksException { addIndent(indent).append("unnest " + op.getVariable()); if (op.getPositionalVariable() != null) { buffer.append(" at " + op.getPositionalVariable()); } buffer.append(" <- " + op.getExpressionRef().getValue().accept(exprVisitor, indent)); return null; }
AbstractFunctionCallExpression f = UnnestToDataScanRule.getFunctionCall(opRef); UnnestOperator unnest = (UnnestOperator) opRef.getValue(); if (unnest.getPositionalVariable() != null) { throw new CompilationException(ErrorCode.COMPILATION_ERROR, unnest.getSourceLocation(), "No positional variables are allowed over feeds."); policy = BuiltinFeedPolicies.getFeedPolicy(policyName); if (policy == null) { throw new CompilationException(ErrorCode.COMPILATION_ERROR, unnest.getSourceLocation(), "Unknown feed policy:" + policyName); List<LogicalVariable> pkVars = new ArrayList<>(); FeedDataSource ds = createFeedDataSource(asid, targetDataset, sourceFeedName, subscriptionLocation, metadataProvider, policy, outputType, csLocations, unnest.getVariable(), context, pkVars); feedDataScanOutputVariables.add(unnest.getVariable()); scan.setSourceLocation(unnest.getSourceLocation()); List<Mutable<ILogicalOperator>> scanInpList = scan.getInputs(); scanInpList.addAll(unnest.getInputs()); opRef.setValue(scan); context.computeAndSetTypeEnvironmentForOperator(scan);
if (unnest.getPositionalVariable() != null) { return false; if (!unnest.getVariable().equals(aggInputVar)) { return false; ILogicalExpression unnestArg = unnest.getExpressionRef().getValue(); if (unnestArg.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return false; AssignOperator assign = new AssignOperator(assgnVars, scanFunc.getArguments()); assign.setSourceLocation(agg.getSourceLocation()); assign.getInputs().add(unnest.getInputs().get(0)); context.computeAndSetTypeEnvironmentForOperator(assign); opRef.setValue(assign);
FunctionUtil.getFunctionInfo(BuiltinFunctions.SCAN_COLLECTION), args); scanCollExpr.setSourceLocation(exprSourceLoc); UnnestOperator unnestOp = new UnnestOperator(unnestVar, new MutableObject<>(scanCollExpr)); unnestOp.getInputs().add(new MutableObject<>(opAndVar.first)); unnestOp.setSourceLocation(exprSourceLoc); inputOpRefsToUnion.add(new MutableObject<>(unnestOp)); vars.add(unnestVar);
UnnestOperator unnest1 = new UnnestOperator(unnestVar1, new MutableObject<ILogicalExpression>(unnestOpRef.getExpressionRef().getValue().cloneExpression())); LogicalVariable unnestVar2 = context.newVar(); UnnestOperator unnest2 = new UnnestOperator(unnestVar2, new MutableObject<ILogicalExpression>(unnestOpRef.getExpressionRef().getValue().cloneExpression())); unnest1.getExpressionRef().getValue().getUsedVariables(var_unnest_1); unnest1.getExpressionRef().getValue().substituteVar(var_unnest_1.get(0), agg1_var.get(0)); unnest2.getExpressionRef().getValue().getUsedVariables(var_unnest2); unnest2.getExpressionRef().getValue().substituteVar(var_unnest2.get(0), agg2_var.get(0)); unnest1.getInputs().add(branch1); unnest2.getInputs().add(branch2); context.computeAndSetTypeEnvironmentForOperator(unnest1); context.computeAndSetTypeEnvironmentForOperator(unnest2); Triple<LogicalVariable, LogicalVariable, LogicalVariable> union_triple_vars = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(unnestVar1, unnestVar2, unnestOpRef.getVariables().get(0)); varMap.add(union_triple_vars); UnionAllOperator unionOpFinal = new UnionAllOperator(varMap);
ILogicalExpression expr = unnest1.getExpressionRef().getValue(); LogicalVariable unnestedVar; switch (expr.getExpressionTag()) { assgnVars.add(unnest1.getVariable()); ArrayList<Mutable<ILogicalExpression>> assgnExprs = new ArrayList<Mutable<ILogicalExpression>>(1); VariableReferenceExpression paramRef = new VariableReferenceExpression(paramVar); assign.setSourceLocation(arg0.getSourceLocation()); LogicalVariable posVar = unnest1.getPositionalVariable(); if (posVar == null) { nestedAssignVars.add(unnest1.getVariable()); nestedAssignExprs.add(new MutableObject<ILogicalExpression>(arg0)); AssignOperator nestedAssign = new AssignOperator(nestedAssignVars, nestedAssignExprs); SourceLocation sourceLoc = unnest1.getSourceLocation(); nestedAssign.setSourceLocation(sourceLoc); nestedAssign.getInputs().add(opRef2); RunningAggregateOperator raggOp = new RunningAggregateOperator(raggVars, raggExprs); raggOp.setSourceLocation(sourceLoc); raggOp.setExecutionMode(unnest1.getExecutionMode()); RunningAggregatePOperator raggPOp = new RunningAggregatePOperator(); raggOp.setPhysicalOperator(raggPOp);
/** * This method is to inline one variable * * @param usedVar * A variable that is used by the scan-collection function in the unnest operator * @param unnestOp * The unnest operator. * @throws AlgebricksException */ private void inlineVariable(LogicalVariable usedVar, UnnestOperator unnestOp) throws AlgebricksException { AbstractFunctionCallExpression expr = (AbstractFunctionCallExpression) unnestOp.getExpressionRef().getValue(); List<Pair<AbstractFunctionCallExpression, Integer>> parentAndIndexList = new ArrayList<Pair<AbstractFunctionCallExpression, Integer>>(); getParentFunctionExpression(usedVar, expr, parentAndIndexList); ILogicalExpression usedVarOrginExpr = findUsedVarOrigin(usedVar, unnestOp, (AbstractLogicalOperator) unnestOp.getInputs().get(0).getValue()); if (usedVarOrginExpr != null) { for (Pair<AbstractFunctionCallExpression, Integer> parentAndIndex : parentAndIndexList) { //we only rewrite the top scan-collection function if (parentAndIndex.first.getFunctionIdentifier() == BuiltinFunctions.SCAN_COLLECTION && parentAndIndex.first == expr) { unnestOp.getExpressionRef().setValue(usedVarOrginExpr); } } } }
} else { UnnestOperator unnestOp = (UnnestOperator) op; expr = (AbstractLogicalExpression) unnestOp.getExpressionRef().getValue(); if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return Collections.emptyList(); } else if (subOp.getOperatorTag() == LogicalOperatorTag.UNNEST) { varList = ((UnnestOperator) subOp).getVariables(); } else { break; LogicalVariable var = unnestOp.getVariable(); if (var.equals(curVar)) { getFieldNameFromSubTree(optFuncExpr, subTree, assignOrUnnestIndex, 0, recordType, funcVarIndex,
private ILogicalPlan translateMainModule(MainModuleNode moduleNode) throws SystemException { QueryBodyNode qbn = moduleNode.getQueryBody(); ASTNode queryBody = qbn.getExpression(); TranslationContext tCtx = new TranslationContext(null, new EmptyTupleSourceOperator()); LogicalVariable lVar = translateExpression(queryBody, tCtx); LogicalVariable iLVar = newLogicalVariable(); UnnestOperator unnest = new UnnestOperator(iLVar, mutable(ufce(BuiltinOperators.ITERATE, vre(lVar)))); unnest.getInputs().add(mutable(tCtx.op)); List<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>(); exprs.add(mutable(vre(iLVar))); QueryResultSetDataSink sink = new QueryResultSetDataSink(ccb.getResultSetId(), null); DistributeResultOperator op = new DistributeResultOperator(exprs, sink); op.getInputs().add(mutable(unnest)); ALogicalPlanImpl lp = new ALogicalPlanImpl(mutable(op)); return lp; }
LogicalVariable var = unnest.getVariable(); if (var == varRefExpr.getVariableReference()) { ILogicalExpression matchedExpr = unnest.getExpressionRef().getValue(); if (matchedExpr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return false;
LogicalVariable p = unnest.getPositionalVariable(); if (p == null) { return false; rOpExprList.add(new MutableObject<ILogicalExpression>(fce)); RunningAggregateOperator rOp = new RunningAggregateOperator(rOpVars, rOpExprList); rOp.setSourceLocation(unnest.getSourceLocation()); rOp.setExecutionMode(unnest.getExecutionMode()); RunningAggregatePOperator rPop = new RunningAggregatePOperator(); rOp.setPhysicalOperator(rPop); rOp.getInputs().add(new MutableObject<ILogicalOperator>(unnest)); opRef.setValue(rOp); unnest.setPositionalVariable(null); context.computeAndSetTypeEnvironmentForOperator(rOp); context.computeAndSetTypeEnvironmentForOperator(unnest);
@Override public Void visitUnnestOperator(UnnestOperator op, Void arg) { op.getExpressionRef().getValue().getUsedVariables(usedVariables); return null; }
case UNNEST: UnnestOperator uOp = (UnnestOperator) op; LogicalVariable pVar = uOp.getPositionalVariable(); if (pVar != null && toRemove != null && toRemove.contains(pVar)) { uOp.setPositionalVariable(null); assignedVarSet.remove(pVar); isTransformed = true;
LogicalVariable var = unnestOp.getVariable(); List<String> fieldName = null; if (subTree.getDataSourceType() != DataSourceType.COLLECTION_SCAN) {
IOptimizationContext context, List<Index> datasetIndexes, int optFuncExprIndex, AccessMethodAnalysisContext analysisCtx) throws AlgebricksException { LogicalVariable var = unnestOp.getVariable(); int funcVarIndex = optFuncExpr.findLogicalVar(var); if (subTree.getDataSourceType() == DataSourceType.COLLECTION_SCAN) { VariableReferenceExpression varRef = new VariableReferenceExpression(var); varRef.setSourceLocation(unnestOp.getSourceLocation()); optFuncExpr.setLogicalExpr(funcVarIndex, varRef); } else {
private UnnestOperator getUnnestOperator(LogicalVariable inputVariable, LogicalVariable unnestVariable) { VariableReferenceExpression inputVre = new VariableReferenceExpression(inputVariable); List<Mutable<ILogicalExpression>> iterateArgs = new ArrayList<Mutable<ILogicalExpression>>(); iterateArgs.add(new MutableObject<ILogicalExpression>(inputVre)); ILogicalExpression unnestExp = new UnnestingFunctionCallExpression(BuiltinOperators.ITERATE, iterateArgs); Mutable<ILogicalExpression> unnestExpRef = new MutableObject<ILogicalExpression>(unnestExp); return new UnnestOperator(unnestVariable, unnestExpRef); }
AbstractLogicalOperator op2 = (AbstractLogicalOperator) unnest.getInputs().get(0).getValue(); if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return null;