private void getGroupBindings(GroupbyClause groupbyClause, List<FieldBinding> outFieldBindings, Set<String> outFieldNames) throws CompilationException { for (GbyVariableExpressionPair pair : groupbyClause.getGbyPairList()) { outFieldBindings.add(getFieldBinding(pair.getVar(), outFieldNames)); } if (groupbyClause.hasGroupVar()) { outFieldBindings.add(getFieldBinding(groupbyClause.getGroupVar(), outFieldNames)); } if (groupbyClause.hasWithMap()) { // no WITH in SQLPP throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, groupbyClause.getSourceLocation(), groupbyClause.getWithVarMap().values().toString()); } }
@Override public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(GroupbyClause gc, VariableSubstitutionEnvironment env) throws CompilationException { VariableSubstitutionEnvironment newSubs = env; List<GbyVariableExpressionPair> newGbyList = VariableCloneAndSubstitutionUtil.substInVarExprPair(context, gc.getGbyPairList(), newSubs, this); List<GbyVariableExpressionPair> newDecorList = gc.hasDecorList() ? VariableCloneAndSubstitutionUtil.substInVarExprPair(context, gc.getDecorPairList(), newSubs, this) : new ArrayList<>(); VariableExpr newGroupVar = null; if (gc.hasGroupVar()) { newGroupVar = generateNewVariable(context, gc.getGroupVar()); } Map<Expression, VariableExpr> newWithMap = new HashMap<>(); if (gc.hasWithMap()) { for (Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) { Expression newKeyVar = (Expression) entry.getKey().accept(this, env).first; VariableExpr newValueVar = generateNewVariable(context, entry.getValue()); newWithMap.put(newKeyVar, newValueVar); } } List<Pair<Expression, Identifier>> newGroupFieldList = gc.hasGroupFieldList() ? VariableCloneAndSubstitutionUtil.substInFieldList(gc.getGroupFieldList(), env, this) : null; GroupbyClause newGroup = new GroupbyClause(newGbyList, newDecorList, newWithMap, newGroupVar, newGroupFieldList, gc.hasHashGroupByHint(), gc.isGroupAll()); newGroup.setSourceLocation(gc.getSourceLocation()); return new Pair<>(newGroup, newSubs); }
private void rewriteSelectWithGroupBy(SelectBlock selectBlock, ILangExpression arg) throws CompilationException { GroupbyClause gbyClause = selectBlock.getGroupbyClause(); // Sets the group variable. if (!gbyClause.hasGroupVar()) { VariableExpr groupVar = new VariableExpr(context.newVariable()); groupVar.setSourceLocation(gbyClause.getSourceLocation()); gbyClause.setGroupVar(groupVar); } // Sets the field list for the group variable. List<Pair<Expression, Identifier>> groupFieldList; if (gbyClause.hasGroupFieldList()) { groupFieldList = new ArrayList<>(); for (Pair<Expression, Identifier> groupField : gbyClause.getGroupFieldList()) { Expression newFieldExpr = groupField.first.accept(this, arg); groupFieldList.add(new Pair<>(newFieldExpr, groupField.second)); } } else { groupFieldList = createGroupFieldList(selectBlock); } gbyClause.setGroupFieldList(groupFieldList); }
if (gc.hasGroupVar()) { groupVarExpr = (VariableExpr) gc.getGroupVar().accept(this, arg);
if (gc.hasGroupVar()) { out.print(skip(step + 1) + "GROUP AS "); gc.getGroupVar().accept(this, 0);
if (gc.hasGroupVar()) { VariableExpr groupVar = gc.getGroupVar(); addNewVarSymbolToScope(newScope, groupVar.getVar(), groupVar.getSourceLocation());
Mutable<ILogicalOperator> topOp = tupSource; LogicalVariable groupRecordVar = null; if (gc.hasGroupVar()) { groupRecordVar = context.newVar(); AbstractFunctionCallExpression groupRecordConstr = if (gc.hasGroupVar()) { VariableExpr groupVar = gc.getGroupVar(); LogicalVariable groupLogicalVar = context.newVar();