Search in sources :

Example 16 with GbyVariableExpressionPair

use of org.apache.asterix.lang.common.expression.GbyVariableExpressionPair in project asterixdb by apache.

the class SqlppGlobalAggregationSugarVisitor method visit.

@Override
public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws CompilationException {
    SelectClause selectClause = selectBlock.getSelectClause();
    if (!selectBlock.hasGroupbyClause() && selectBlock.hasFromClause()) {
        boolean addImplicitGby;
        if (selectClause.selectRegular()) {
            addImplicitGby = isSql92Aggregate(selectClause.getSelectRegular(), selectBlock);
        } else {
            addImplicitGby = isSql92Aggregate(selectClause.getSelectElement(), selectBlock);
        }
        if (addImplicitGby) {
            // Adds an implicit group-by clause for SQL-92 global aggregate.
            List<GbyVariableExpressionPair> gbyPairList = new ArrayList<>();
            List<GbyVariableExpressionPair> decorPairList = new ArrayList<>();
            GroupbyClause gbyClause = new GroupbyClause(gbyPairList, decorPairList, new HashMap<>(), null, null, false, true);
            selectBlock.setGroupbyClause(gbyClause);
        }
    }
    return super.visit(selectBlock, arg);
}
Also used : SelectClause(org.apache.asterix.lang.sqlpp.clause.SelectClause) GroupbyClause(org.apache.asterix.lang.common.clause.GroupbyClause) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) ArrayList(java.util.ArrayList)

Aggregations

GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)16 Expression (org.apache.asterix.lang.common.base.Expression)9 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)9 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)8 ArrayList (java.util.ArrayList)7 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)6 Identifier (org.apache.asterix.lang.common.struct.Identifier)5 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)5 HashMap (java.util.HashMap)4 GroupbyClause (org.apache.asterix.lang.common.clause.GroupbyClause)4 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)3 VarIdentifier (org.apache.asterix.lang.common.struct.VarIdentifier)3 Pair (org.apache.hyracks.algebricks.common.utils.Pair)3 LetClause (org.apache.asterix.lang.common.clause.LetClause)2 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)2 SelectClause (org.apache.asterix.lang.sqlpp.clause.SelectClause)2 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)2 FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1