@Override public Expression visit(WindowExpression winExpr, ILangExpression arg) throws CompilationException { // skip variables inside list arguments of window functions (will be resolved by SqlppWindowExpressionVisitor) FunctionSignature fs = winExpr.getFunctionSignature(); FunctionIdentifier winfi = FunctionMapUtil.getInternalWindowFunction(fs); if (winfi != null) { if (BuiltinFunctions.windowFunctionHasProperty(winfi, BuiltinFunctions.WindowFunctionProperty.HAS_LIST_ARG)) { visitWindowExpressionExcludingExprList(winExpr, arg); List<Expression> exprList = winExpr.getExprList(); List<Expression> newExprList = new ArrayList<>(exprList.size()); Iterator<Expression> i = exprList.iterator(); newExprList.add(i.next()); // don't visit the list arg while (i.hasNext()) { newExprList.add(visit(i.next(), arg)); } winExpr.setExprList(newExprList); return winExpr; } } else if (FunctionMapUtil.isSql92AggregateFunction(fs)) { visitWindowExpressionExcludingExprList(winExpr, arg); return winExpr; } return super.visit(winExpr, arg); } }
private WindowOperator createHelperWindowOperator(List<Mutable<ILogicalExpression>> partExprList, List<Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>>> orderExprList, LogicalVariable rowNumVar, LogicalVariable denseRankVar, ListSet<LogicalVariable> usedVars, SourceLocation sourceLoc) throws CompilationException { WindowOperator winOp = new WindowOperator(partExprList, orderExprList); winOp.setSourceLocation(sourceLoc); for (LogicalVariable usedVar : usedVars) { FunctionIdentifier fid; if (usedVar.equals(rowNumVar)) { fid = BuiltinFunctions.ROW_NUMBER_IMPL; } else if (usedVar.equals(denseRankVar)) { fid = BuiltinFunctions.DENSE_RANK_IMPL; } else { throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, sourceLoc, usedVar.toString()); } AbstractFunctionCallExpression valueExpr = BuiltinFunctions.makeWindowFunctionExpression(fid, new ArrayList<>()); if (BuiltinFunctions.windowFunctionHasProperty(valueExpr.getFunctionIdentifier(), BuiltinFunctions.WindowFunctionProperty.INJECT_ORDER_ARGS)) { for (Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>> p : orderExprList) { valueExpr.getArguments().add(new MutableObject<>(p.second.getValue().cloneExpression())); } } valueExpr.setSourceLocation(winOp.getSourceLocation()); winOp.getVariables().add(usedVar); winOp.getExpressions().add(new MutableObject<>(valueExpr)); } return winOp; } }
@Override public Expression visit(WindowExpression winExpr, ILangExpression arg) throws CompilationException { if (!winExpr.hasWindowFieldList()) { SelectBlock selectBlock = stack.peek(); List<Pair<Expression, Identifier>> winFieldList = createWindowFieldList(selectBlock); winExpr.setWindowFieldList(winFieldList); } FunctionSignature signature = winExpr.getFunctionSignature(); FunctionIdentifier winfi = FunctionMapUtil.getInternalWindowFunction(signature); if (winfi != null) { winExpr.setFunctionSignature(new FunctionSignature(winfi)); rewriteSpecificWindowFunctions(winfi, winExpr); if (BuiltinFunctions.windowFunctionHasProperty(winfi, BuiltinFunctions.WindowFunctionProperty.HAS_LIST_ARG)) { wrapAggregationArguments(winExpr, 1); } } else if (FunctionMapUtil.isSql92AggregateFunction(signature)) { winExpr.setFunctionSignature(FunctionMapUtil.sql92ToCoreAggregateFunction(signature)); wrapAggregationArguments(winExpr, winExpr.getExprList().size()); } return super.visit(winExpr, arg); }
if (BuiltinFunctions.windowFunctionHasProperty(callExpr.getFunctionIdentifier(), BuiltinFunctions.WindowFunctionProperty.MATERIALIZE_PARTITION)) { partitionMaterialization = true;
@Override public Expression visit(WindowExpression winExpr, ILangExpression arg) throws CompilationException { super.visit(winExpr, arg); if (!winExpr.hasWindowVar()) { VariableExpr winVar = new VariableExpr(context.newVariable()); winVar.setSourceLocation(winExpr.getSourceLocation()); winExpr.setWindowVar(winVar); } FunctionSignature signature = winExpr.getFunctionSignature(); FunctionIdentifier winfi = FunctionMapUtil.getInternalWindowFunction(signature); if (winfi != null) { if (BuiltinFunctions.windowFunctionHasProperty(winfi, BuiltinFunctions.WindowFunctionProperty.HAS_LIST_ARG)) { List<Expression> newExprList = extractExpressions(winExpr.getExprList(), 1); if (newExprList == null) { throw new CompilationException(ErrorCode.COMPILATION_ERROR, winExpr.getSourceLocation(), ""); } winExpr.setExprList(newExprList); } } else if (FunctionMapUtil.isSql92AggregateFunction(signature)) { List<Expression> newExprList = extractExpressions(winExpr.getExprList(), winExpr.getExprList().size()); if (newExprList == null) { throw new CompilationException(ErrorCode.COMPILATION_ERROR, winExpr.getSourceLocation(), ""); } winExpr.setExprList(newExprList); } return winExpr; }
&& BuiltinFunctions.windowFunctionHasProperty(fi, BuiltinFunctions.WindowFunctionProperty.HAS_LIST_ARG); boolean prohibitOrderClause = isWin && BuiltinFunctions.windowFunctionHasProperty(fi, BuiltinFunctions.WindowFunctionProperty.NO_ORDER_CLAUSE); boolean prohibitFrameClause = isWin && BuiltinFunctions.windowFunctionHasProperty(fi, BuiltinFunctions.WindowFunctionProperty.NO_FRAME_CLAUSE); throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, sourceLoc, fcallExpr.getKind()); if (BuiltinFunctions.windowFunctionHasProperty(fi, BuiltinFunctions.WindowFunctionProperty.INJECT_ORDER_ARGS)) { for (Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>> p : orderExprListOut) {