@Override public UnnestingFunctionCallExpression cloneExpression() { cloneAnnotations(); List<Mutable<ILogicalExpression>> clonedArgs = cloneArguments(); UnnestingFunctionCallExpression ufce = new UnnestingFunctionCallExpression(finfo, clonedArgs); ufce.setReturnsUniqueValues(returnsUniqueValues); ufce.setOpaqueParameters(this.getOpaqueParameters()); ufce.setSourceLocation(sourceLoc); return ufce; }
@Override public ILogicalExpression visitUnnestingFunctionCallExpression(UnnestingFunctionCallExpression expr, Void arg) throws AlgebricksException { UnnestingFunctionCallExpression exprCopy = new UnnestingFunctionCallExpression(expr.getFunctionInfo(), deepCopyExpressionReferenceList(expr.getArguments())); deepCopyAnnotations(expr, exprCopy); deepCopyOpaqueParameters(expr, exprCopy); copySourceLocation(expr, exprCopy); return exprCopy; }
@Override public IUnnestingEvaluatorFactory createUnnestingFunctionFactory(UnnestingFunctionCallExpression expr, IVariableTypeEnvironment env, IOperatorSchema[] inputSchemas, JobGenContext context) throws AlgebricksException { Function fn = (Function) expr.getFunctionInfo(); IScalarEvaluatorFactory[] argFactories = createArgumentEvaluatorFactories(env, inputSchemas, context, expr.getArguments()); try { return fn.createUnnestingEvaluatorFactory(argFactories); } catch (SystemException e) { throw new AlgebricksException(e); } } }
protected ILogicalExpression makeUnnestExpression(ILogicalExpression expr) { SourceLocation sourceLoc = expr.getSourceLocation(); List<Mutable<ILogicalExpression>> argRefs = new ArrayList<>(); argRefs.add(new MutableObject<>(expr)); switch (expr.getExpressionTag()) { case CONSTANT: case VARIABLE: UnnestingFunctionCallExpression scanCollExpr1 = new UnnestingFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.SCAN_COLLECTION), argRefs); scanCollExpr1.setSourceLocation(sourceLoc); return scanCollExpr1; case FUNCTION_CALL: AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr; if (fce.getKind() == FunctionKind.UNNEST) { return expr; } else { UnnestingFunctionCallExpression scanCollExpr2 = new UnnestingFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.SCAN_COLLECTION), argRefs); scanCollExpr2.setSourceLocation(sourceLoc); return scanCollExpr2; } default: return expr; } }
new UnnestingFunctionCallExpression(secondaryIndexSearch, secondaryIndexFuncArgs); secondaryIndexSearchFunc.setSourceLocation(sourceLoc); secondaryIndexSearchFunc.setReturnsUniqueValues(true);
private static ILogicalExpression ufce(Function fn, ILogicalExpression... argExprs) { List<Mutable<ILogicalExpression>> args = new ArrayList<Mutable<ILogicalExpression>>(); for (ILogicalExpression e : argExprs) { args.add(mutable(e)); } return new UnnestingFunctionCallExpression(fn, args); }
private AbstractFunctionCallExpression lookupBuiltinFunction(String functionName, int arity, List<Mutable<ILogicalExpression>> args, SourceLocation sourceLoc) { AbstractFunctionCallExpression f; FunctionIdentifier fi = getBuiltinFunctionIdentifier(functionName, arity); if (fi == null) { return null; } if (BuiltinFunctions.isBuiltinAggregateFunction(fi)) { f = BuiltinFunctions.makeAggregateFunctionExpression(fi, args); } else if (BuiltinFunctions.isBuiltinUnnestingFunction(fi)) { UnnestingFunctionCallExpression ufce = new UnnestingFunctionCallExpression(FunctionUtil.getFunctionInfo(fi), args); ufce.setReturnsUniqueValues(BuiltinFunctions.returnsUniqueValues(fi)); f = ufce; } else if (BuiltinFunctions.isWindowFunction(fi)) { f = BuiltinFunctions.makeWindowFunctionExpression(fi, args); } else { f = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(fi), args); } f.setSourceLocation(sourceLoc); return f; }
private static boolean containsDatasetAccessInternal(ILogicalOperator op) { if (op.getOperatorTag() == LogicalOperatorTag.UNNEST) { UnnestOperator unnestOp = (UnnestOperator) op; ILogicalExpression unnestExpr = unnestOp.getExpressionRef().getValue(); UnnestingFunctionCallExpression unnestingFuncExpr = (UnnestingFunctionCallExpression) unnestExpr; return unnestingFuncExpr.getFunctionIdentifier().equals(BuiltinFunctions.DATASET); } if (op.getOperatorTag() == LogicalOperatorTag.SUBPLAN && containsDatasetAccess((SubplanOperator) op)) { return true; } for (Mutable<ILogicalOperator> childRef : op.getInputs()) { if (containsDatasetAccessInternal(childRef.getValue())) { return true; } } return false; } }
private Pair<ILogicalOperator, LogicalVariable> createUnnestForAggregatedList(LogicalVariable aggVar, SourceLocation sourceLoc) { LogicalVariable unnestVar = context.newVar(); // Creates an unnest function expression. VariableReferenceExpression aggVarRef = new VariableReferenceExpression(aggVar); aggVarRef.setSourceLocation(sourceLoc); Mutable<ILogicalExpression> unnestArg = new MutableObject<>(aggVarRef); List<Mutable<ILogicalExpression>> unnestArgList = new ArrayList<>(); unnestArgList.add(unnestArg); UnnestingFunctionCallExpression unnestExpr = new UnnestingFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.SCAN_COLLECTION), unnestArgList); unnestExpr.setSourceLocation(sourceLoc); UnnestOperator unnestOp = new UnnestOperator(unnestVar, new MutableObject<>(unnestExpr)); unnestOp.setSourceLocation(sourceLoc); return new Pair<>(unnestOp, unnestVar); }
new UnnestingFunctionCallExpression(primaryIndexSearch, primaryIndexFuncArgs); primaryIndexSearchFunc.setSourceLocation(dataSourceOp.getSourceLocation()); primaryIndexSearchFunc.setReturnsUniqueValues(true); AbstractUnnestMapOperator unnestMapOp; if (!leftOuterUnnestMapRequired) {
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); }
varRef.setSourceLocation(exprSourceLoc); args.add(new MutableObject<>(varRef)); UnnestingFunctionCallExpression scanCollExpr = new UnnestingFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.SCAN_COLLECTION), args); scanCollExpr.setSourceLocation(exprSourceLoc); UnnestOperator unnestOp = new UnnestOperator(unnestVar, new MutableObject<>(scanCollExpr)); unnestOp.getInputs().add(new MutableObject<>(opAndVar.first));
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); }
new UnnestingFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.SCAN_COLLECTION), new MutableObject<ILogicalExpression>(argExpr)); scanCollExpr.setSourceLocation(func.getSourceLocation()); @SuppressWarnings("unchecked") UnnestOperator unnest = new UnnestOperator(var, new MutableObject<ILogicalExpression>(scanCollExpr));
unnest.getInputs().addAll(assign.getInputs()); UnnestingFunctionCallExpression child = new UnnestingFunctionCallExpression(functionInfo2, functionCall2.getArguments()); unnest.getExpressionRef().setValue(child);
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (context.checkIfInDontApplySet(this, op)) { return false; } if (op.getOperatorTag() != LogicalOperatorTag.UNNEST) { context.addToDontApplySet(this, op); return false; } UnnestOperator unnest = (UnnestOperator) op; ILogicalExpression unnestExpr = unnest.getExpressionRef().getValue(); if (needsScanCollection(unnestExpr, op)) { UnnestingFunctionCallExpression newExpr = new UnnestingFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.SCAN_COLLECTION), new MutableObject<ILogicalExpression>(unnestExpr)); newExpr.setSourceLocation(unnestExpr.getSourceLocation()); unnest.getExpressionRef().setValue(newExpr); context.addToDontApplySet(this, op); return true; } context.addToDontApplySet(this, op); return false; }
new UnnestingFunctionCallExpression(functionInfo, func.getArguments()); unnestExpr.setSourceLocation(sourceLoc); UnnestOperator unnestOperator = new UnnestOperator(unnestVar, new MutableObject<>(unnestExpr)); unnestOperator.setSourceLocation(sourceLoc);
selectVarRef.setSourceLocation(caseExpression.getSourceLocation()); UnnestingFunctionCallExpression scanCollectionExpr = new UnnestingFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.SCAN_COLLECTION), Collections.singletonList(new MutableObject<>(selectVarRef))); scanCollectionExpr.setSourceLocation(caseExpression.getSourceLocation()); UnnestOperator unnestOp = new UnnestOperator(unnestVar, new MutableObject<>(scanCollectionExpr)); unnestOp.getInputs().add(new MutableObject<>(assignOp));
Mutable<ILogicalExpression> mutCExp = new MutableObject<>(cExp); IFunctionInfo scanFctInfo = BuiltinFunctions.getAsterixFunctionInfo(BuiltinFunctions.SCAN_COLLECTION); UnnestingFunctionCallExpression scanExp = new UnnestingFunctionCallExpression(scanFctInfo, mutCExp); scanExp.setSourceLocation(sourceLoc); LogicalVariable scanVar = context.newVar(); UnnestOperator unn = new UnnestOperator(scanVar, new MutableObject<>(scanExp));
selectVarRef.setSourceLocation(ifexpr.getSourceLocation()); UnnestingFunctionCallExpression scanCollExpr = new UnnestingFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.SCAN_COLLECTION), Collections.singletonList(new MutableObject<>(selectVarRef))); scanCollExpr.setSourceLocation(ifexpr.getSourceLocation()); UnnestOperator unnestOp = new UnnestOperator(unnestVar, new MutableObject<>(scanCollExpr)); unnestOp.getInputs().add(new MutableObject<>(assignOp));