Search in sources :

Example 6 with SelectClause

use of org.apache.asterix.lang.sqlpp.clause.SelectClause in project asterixdb by apache.

the class DeepCopyVisitor method visit.

@Override
public SelectClause visit(SelectClause selectClause, Void arg) throws CompilationException {
    SelectElement selectElement = null;
    SelectRegular selectRegular = null;
    if (selectClause.selectElement()) {
        selectElement = (SelectElement) selectClause.getSelectElement().accept(this, arg);
    }
    if (selectClause.selectRegular()) {
        selectRegular = (SelectRegular) selectClause.getSelectRegular().accept(this, arg);
    }
    return new SelectClause(selectElement, selectRegular, selectClause.distinct());
}
Also used : SelectRegular(org.apache.asterix.lang.sqlpp.clause.SelectRegular) SelectElement(org.apache.asterix.lang.sqlpp.clause.SelectElement) SelectClause(org.apache.asterix.lang.sqlpp.clause.SelectClause)

Example 7 with SelectClause

use of org.apache.asterix.lang.sqlpp.clause.SelectClause in project asterixdb by apache.

the class DeepCopyVisitor method visit.

@Override
public SelectBlock visit(SelectBlock selectBlock, Void arg) throws CompilationException {
    FromClause fromClause = null;
    List<LetClause> letClauses = new ArrayList<>();
    WhereClause whereClause = null;
    GroupbyClause gbyClause = null;
    List<LetClause> gbyLetClauses = new ArrayList<>();
    HavingClause havingClause = null;
    SelectClause selectCluase;
    // "group by", "let"s, "having" and "select".
    if (selectBlock.hasFromClause()) {
        fromClause = (FromClause) selectBlock.getFromClause().accept(this, arg);
    }
    if (selectBlock.hasLetClauses()) {
        List<LetClause> letList = selectBlock.getLetList();
        for (LetClause letClause : letList) {
            letClauses.add((LetClause) letClause.accept(this, arg));
        }
    }
    if (selectBlock.hasWhereClause()) {
        whereClause = (WhereClause) selectBlock.getWhereClause().accept(this, arg);
    }
    if (selectBlock.hasGroupbyClause()) {
        gbyClause = (GroupbyClause) selectBlock.getGroupbyClause().accept(this, arg);
    }
    if (selectBlock.hasLetClausesAfterGroupby()) {
        List<LetClause> letListAfterGby = selectBlock.getLetListAfterGroupby();
        for (LetClause letClauseAfterGby : letListAfterGby) {
            gbyLetClauses.add((LetClause) letClauseAfterGby.accept(this, arg));
        }
    }
    if (selectBlock.hasHavingClause()) {
        havingClause = (HavingClause) selectBlock.getHavingClause().accept(this, arg);
    }
    selectCluase = (SelectClause) selectBlock.getSelectClause().accept(this, arg);
    return new SelectBlock(selectCluase, fromClause, letClauses, whereClause, gbyClause, gbyLetClauses, havingClause);
}
Also used : SelectClause(org.apache.asterix.lang.sqlpp.clause.SelectClause) GroupbyClause(org.apache.asterix.lang.common.clause.GroupbyClause) LetClause(org.apache.asterix.lang.common.clause.LetClause) SelectBlock(org.apache.asterix.lang.sqlpp.clause.SelectBlock) FromClause(org.apache.asterix.lang.sqlpp.clause.FromClause) HavingClause(org.apache.asterix.lang.sqlpp.clause.HavingClause) ArrayList(java.util.ArrayList) WhereClause(org.apache.asterix.lang.common.clause.WhereClause)

Example 8 with SelectClause

use of org.apache.asterix.lang.sqlpp.clause.SelectClause 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)

Example 9 with SelectClause

use of org.apache.asterix.lang.sqlpp.clause.SelectClause in project asterixdb by apache.

the class SqlppCloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(SelectBlock selectBlock, VariableSubstitutionEnvironment env) throws CompilationException {
    Pair<ILangExpression, VariableSubstitutionEnvironment> newFrom = null;
    Pair<ILangExpression, VariableSubstitutionEnvironment> newLet;
    Pair<ILangExpression, VariableSubstitutionEnvironment> newWhere = null;
    Pair<ILangExpression, VariableSubstitutionEnvironment> newGroupby = null;
    Pair<ILangExpression, VariableSubstitutionEnvironment> newHaving = null;
    Pair<ILangExpression, VariableSubstitutionEnvironment> newSelect;
    List<LetClause> newLetClauses = new ArrayList<>();
    List<LetClause> newLetClausesAfterGby = new ArrayList<>();
    VariableSubstitutionEnvironment currentEnv = new VariableSubstitutionEnvironment(env);
    if (selectBlock.hasFromClause()) {
        newFrom = selectBlock.getFromClause().accept(this, currentEnv);
        currentEnv = newFrom.second;
    }
    if (selectBlock.hasLetClauses()) {
        for (LetClause letClause : selectBlock.getLetList()) {
            newLet = letClause.accept(this, currentEnv);
            currentEnv = newLet.second;
            newLetClauses.add(letClause);
        }
    }
    if (selectBlock.hasWhereClause()) {
        newWhere = selectBlock.getWhereClause().accept(this, currentEnv);
        currentEnv = newWhere.second;
    }
    if (selectBlock.hasGroupbyClause()) {
        newGroupby = selectBlock.getGroupbyClause().accept(this, currentEnv);
        currentEnv = newGroupby.second;
        if (selectBlock.hasLetClausesAfterGroupby()) {
            for (LetClause letClauseAfterGby : selectBlock.getLetListAfterGroupby()) {
                newLet = letClauseAfterGby.accept(this, currentEnv);
                currentEnv = newLet.second;
                newLetClausesAfterGby.add(letClauseAfterGby);
            }
        }
    }
    if (selectBlock.hasHavingClause()) {
        newHaving = selectBlock.getHavingClause().accept(this, currentEnv);
        currentEnv = newHaving.second;
    }
    newSelect = selectBlock.getSelectClause().accept(this, currentEnv);
    currentEnv = newSelect.second;
    FromClause fromClause = newFrom == null ? null : (FromClause) newFrom.first;
    WhereClause whereClause = newWhere == null ? null : (WhereClause) newWhere.first;
    GroupbyClause groupbyClause = newGroupby == null ? null : (GroupbyClause) newGroupby.first;
    HavingClause havingClause = newHaving == null ? null : (HavingClause) newHaving.first;
    return new Pair<>(new SelectBlock((SelectClause) newSelect.first, fromClause, newLetClauses, whereClause, groupbyClause, newLetClausesAfterGby, havingClause), currentEnv);
}
Also used : SelectClause(org.apache.asterix.lang.sqlpp.clause.SelectClause) LetClause(org.apache.asterix.lang.common.clause.LetClause) ArrayList(java.util.ArrayList) WhereClause(org.apache.asterix.lang.common.clause.WhereClause) VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) GroupbyClause(org.apache.asterix.lang.common.clause.GroupbyClause) SelectBlock(org.apache.asterix.lang.sqlpp.clause.SelectBlock) FromClause(org.apache.asterix.lang.sqlpp.clause.FromClause) HavingClause(org.apache.asterix.lang.sqlpp.clause.HavingClause) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Aggregations

SelectClause (org.apache.asterix.lang.sqlpp.clause.SelectClause)9 FromClause (org.apache.asterix.lang.sqlpp.clause.FromClause)6 ArrayList (java.util.ArrayList)5 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)5 SelectBlock (org.apache.asterix.lang.sqlpp.clause.SelectBlock)5 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)5 Expression (org.apache.asterix.lang.common.base.Expression)4 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)4 GroupbyClause (org.apache.asterix.lang.common.clause.GroupbyClause)4 SelectElement (org.apache.asterix.lang.sqlpp.clause.SelectElement)4 LetClause (org.apache.asterix.lang.common.clause.LetClause)3 WhereClause (org.apache.asterix.lang.common.clause.WhereClause)3 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)3 FromTerm (org.apache.asterix.lang.sqlpp.clause.FromTerm)3 HavingClause (org.apache.asterix.lang.sqlpp.clause.HavingClause)3 SelectSetOperation (org.apache.asterix.lang.sqlpp.clause.SelectSetOperation)3 SetOperationInput (org.apache.asterix.lang.sqlpp.struct.SetOperationInput)3 LimitClause (org.apache.asterix.lang.common.clause.LimitClause)2 OrderbyClause (org.apache.asterix.lang.common.clause.OrderbyClause)2 Pair (org.apache.hyracks.algebricks.common.utils.Pair)2