@Override public Void visit(GroupbyClause gc, Integer step) throws CompilationException { if (gc.hasHashGroupByHint()) { out.println(skip(step) + "/* +hash */"); } out.print(skip(step) + "group by "); printDelimitedGbyExpressions(gc.getGbyPairList(), step + 2); out.println(); return null; }
@Override public Void visit(GroupbyClause gc, Integer step) throws CompilationException { if (gc.hasHashGroupByHint()) { out.println(skip(step) + "/* +hash */"); } out.print(skip(step) + "group by "); printDelimitedGbyExpressions(gc.getGbyPairList(), step + 2); out.println(); return null; }
private List<VariableExpr> collectProducedVariablesFromGroupby(GroupbyClause gbyClause) { List<VariableExpr> producedVars = new ArrayList<VariableExpr>(); for (GbyVariableExpressionPair keyPair : gbyClause.getGbyPairList()) { producedVars.add(keyPair.getVar()); } if (gbyClause.hasDecorList()) { for (GbyVariableExpressionPair keyPair : gbyClause.getDecorPairList()) { producedVars.add(keyPair.getVar()); } } if (gbyClause.hasWithMap()) { producedVars.addAll(gbyClause.getWithVarMap().values()); } return producedVars; }
@Override public Expression visit(GroupbyClause gc, ILangExpression arg) throws CompilationException { for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) { gbyVarExpr.setExpr(visit(gbyVarExpr.getExpr(), gc)); } return null; }
public static List<VariableExpr> getBindingVariables(GroupbyClause gbyClause) { List<VariableExpr> bindingVars = new ArrayList<>(); if (gbyClause == null) { return bindingVars; } for (GbyVariableExpressionPair gbyKey : gbyClause.getGbyPairList()) { VariableExpr var = gbyKey.getVar(); if (var != null) { bindingVars.add(var); } } if (gbyClause.hasDecorList()) { for (GbyVariableExpressionPair gbyKey : gbyClause.getDecorPairList()) { VariableExpr var = gbyKey.getVar(); if (var != null) { bindingVars.add(var); } } } if (gbyClause.hasWithMap()) { bindingVars.addAll(gbyClause.getWithVarMap().values()); } bindingVars.add(gbyClause.getGroupVar()); return bindingVars; }
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()); } }
printDelimitedGbyExpressions(gc.getGbyPairList(), step + 2); if (gc.hasDecorList()) { out.print(" decor ");
@Override public Void visit(GroupbyClause gc, Integer step) throws CompilationException { out.println(skip(step) + "Groupby"); for (GbyVariableExpressionPair pair : gc.getGbyPairList()) { if (pair.getVar() != null) { pair.getVar().accept(this, step + 1);
@Override public Expression visit(GroupbyClause groupbyClause, ILangExpression arg) throws CompilationException { for (GbyVariableExpressionPair gbyKeyPair : groupbyClause.getGbyPairList()) { if (gbyKeyPair.getVar() == null) { VariableExpr varExpr = new VariableExpr(context.newVariable()); varExpr.setSourceLocation(gbyKeyPair.getExpr().getSourceLocation()); gbyKeyPair.setVar(varExpr); } } return super.visit(groupbyClause, arg); }
@Override public Void visit(GroupbyClause gc, Void arg) throws CompilationException { for (GbyVariableExpressionPair p : gc.getGbyPairList()) { p.getExpr().accept(this, arg); } if (gc.hasDecorList()) { for (GbyVariableExpressionPair p : gc.getDecorPairList()) { p.getExpr().accept(this, arg); } } if (gc.hasGroupFieldList()) { for (Pair<Expression, Identifier> p : gc.getGroupFieldList()) { p.first.accept(this, arg); } } if (gc.hasWithMap()) { for (Map.Entry<Expression, VariableExpr> me : gc.getWithVarMap().entrySet()) { me.getKey().accept(this, arg); } } return null; }
@Override public Expression visit(GroupbyClause gc, ILangExpression arg) throws CompilationException { for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) { gbyVarExpr.setExpr(visit(gbyVarExpr.getExpr(), gc)); } if (gc.hasDecorList()) { for (GbyVariableExpressionPair decVarExpr : gc.getDecorPairList()) { decVarExpr.setExpr(visit(decVarExpr.getExpr(), gc)); } } return null; }
@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); }
@Override public Void visit(GroupbyClause gc, Void arg) throws CompilationException { for (GbyVariableExpressionPair p : gc.getGbyPairList()) { p.getExpr().accept(this, arg); } if (gc.hasDecorList()) { for (GbyVariableExpressionPair p : gc.getDecorPairList()) { p.getExpr().accept(this, arg); } } if (gc.hasGroupFieldList()) { for (Pair<Expression, Identifier> p : gc.getGroupFieldList()) { p.first.accept(this, arg); } } if (gc.hasWithMap()) { for (Map.Entry<Expression, VariableExpr> me : gc.getWithVarMap().entrySet()) { me.getKey().accept(this, arg); } } return null; }
} else { out.println(skip(step) + "Groupby"); for (GbyVariableExpressionPair pair : gc.getGbyPairList()) { if (pair.getVar() != null) { pair.getVar().accept(this, step + 1);
@Override public GroupbyClause visit(GroupbyClause gc, Void arg) throws CompilationException { List<GbyVariableExpressionPair> gbyPairList = new ArrayList<>(); for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) { VariableExpr var = gbyVarExpr.getVar(); gbyPairList.add(new GbyVariableExpressionPair(var == null ? null : (VariableExpr) var.accept(this, arg),
@Override public Boolean visit(GroupbyClause gc, ILangExpression arg) throws CompilationException { for (GbyVariableExpressionPair key : gc.getGbyPairList()) { if (visit(key.getExpr(), arg)) { return true; } } if (gc.hasDecorList()) { for (GbyVariableExpressionPair key : gc.getDecorPairList()) { if (visit(key.getExpr(), arg)) { return true; } } } if (gc.hasGroupFieldList() && visitFieldList(gc.getGroupFieldList(), arg)) { return true; } if (gc.hasWithMap() && visitExprList(gc.getWithVarMap().keySet(), arg)) { return true; } return false; }
@Override public Void visit(GroupbyClause gc, Collection<VariableExpr> freeVars) throws CompilationException { // Puts all group-by variables into the symbol set of the new scope. for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) { gbyVarExpr.getExpr().accept(this, freeVars); } if (gc.hasDecorList()) { for (GbyVariableExpressionPair decorVarExpr : gc.getDecorPairList()) { decorVarExpr.getExpr().accept(this, freeVars); } } if (gc.hasGroupFieldList()) { for (Pair<Expression, Identifier> groupField : gc.getGroupFieldList()) { groupField.first.accept(this, freeVars); } } if (gc.hasWithMap()) { for (Expression expr : gc.getWithVarMap().keySet()) { expr.accept(this, freeVars); } } return null; }
if (selectBlock.hasGroupbyClause()) { Map<Expression, Expression> map = new HashMap<>(); for (GbyVariableExpressionPair gbyKeyPair : selectBlock.getGroupbyClause().getGbyPairList()) { Expression gbyKeyExpr = gbyKeyPair.getExpr(); if (gbyKeyExpr.getKind() != Kind.VARIABLE_EXPRESSION) {
for (GbyVariableExpressionPair gbyKeyVarExpr : gc.getGbyPairList()) { gbyKeyVarExpr.setExpr(visit(gbyKeyVarExpr.getExpr(), gc)); VariableExpr gbyKeyVar = gbyKeyVarExpr.getVar();
@Override public Boolean visit(GroupbyClause gc, List<FunctionDecl> arg) throws CompilationException { Pair<Boolean, List<GbyVariableExpressionPair>> p1 = inlineUdfsInGbyPairList(gc.getGbyPairList(), arg); gc.setGbyPairList(p1.second); boolean changed = p1.first; if (gc.hasDecorList()) { Pair<Boolean, List<GbyVariableExpressionPair>> p2 = inlineUdfsInGbyPairList(gc.getDecorPairList(), arg); gc.setDecorPairList(p2.second); changed |= p2.first; } if (gc.hasGroupFieldList()) { Pair<Boolean, List<Pair<Expression, Identifier>>> p3 = inlineUdfsInFieldList(gc.getGroupFieldList(), arg); gc.setGroupFieldList(p3.second); changed |= p3.first; } if (gc.hasWithMap()) { Pair<Boolean, Map<Expression, VariableExpr>> p4 = inlineUdfsInVarMap(gc.getWithVarMap(), arg); gc.setWithVarMap(p4.second); changed |= p4.first; } return changed; }