Search in sources :

Example 6 with SelectSetOperation

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

the class SqlppExpressionToPlanTranslator method visit.

@Override
public Pair<ILogicalOperator, LogicalVariable> visit(SelectSetOperation selectSetOperation, Mutable<ILogicalOperator> tupSource) throws CompilationException {
    SetOperationInput leftInput = selectSetOperation.getLeftInput();
    if (!selectSetOperation.hasRightInputs()) {
        return leftInput.accept(this, tupSource);
    }
    List<ILangExpression> inputExprs = new ArrayList<>();
    inputExprs.add(leftInput.selectBlock() ? new SelectExpression(null, new SelectSetOperation(leftInput, null), null, null, true) : leftInput.getSubquery());
    for (SetOperationRight setOperationRight : selectSetOperation.getRightInputs()) {
        SetOpType setOpType = setOperationRight.getSetOpType();
        if (setOpType != SetOpType.UNION || setOperationRight.isSetSemantics()) {
            throw new CompilationException("Operation " + setOpType + (setOperationRight.isSetSemantics() ? " with set semantics" : "ALL") + " is not supported.");
        }
        SetOperationInput rightInput = setOperationRight.getSetOperationRightInput();
        inputExprs.add(rightInput.selectBlock() ? new SelectExpression(null, new SelectSetOperation(rightInput, null), null, null, true) : rightInput.getSubquery());
    }
    return translateUnionAllFromInputExprs(inputExprs, tupSource);
}
Also used : CompilationException(org.apache.asterix.common.exceptions.CompilationException) SetOperationInput(org.apache.asterix.lang.sqlpp.struct.SetOperationInput) SelectSetOperation(org.apache.asterix.lang.sqlpp.clause.SelectSetOperation) SetOpType(org.apache.asterix.lang.sqlpp.optype.SetOpType) ArrayList(java.util.ArrayList) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) SetOperationRight(org.apache.asterix.lang.sqlpp.struct.SetOperationRight)

Example 7 with SelectSetOperation

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

the class DeepCopyVisitor method visit.

@Override
public SelectExpression visit(SelectExpression selectExpression, Void arg) throws CompilationException {
    List<LetClause> lets = new ArrayList<>();
    SelectSetOperation select;
    OrderbyClause orderby = null;
    LimitClause limit = null;
    // visit let list
    if (selectExpression.hasLetClauses()) {
        for (LetClause letClause : selectExpression.getLetList()) {
            lets.add((LetClause) letClause.accept(this, arg));
        }
    }
    // visit the main select.
    select = (SelectSetOperation) selectExpression.getSelectSetOperation().accept(this, arg);
    // visit order by
    if (selectExpression.hasOrderby()) {
        List<Expression> orderExprs = new ArrayList<>();
        for (Expression orderExpr : selectExpression.getOrderbyClause().getOrderbyList()) {
            orderExprs.add((Expression) orderExpr.accept(this, arg));
        }
        orderby = new OrderbyClause(orderExprs, selectExpression.getOrderbyClause().getModifierList());
    }
    // visit limit
    if (selectExpression.hasLimit()) {
        limit = (LimitClause) selectExpression.getLimitClause().accept(this, arg);
    }
    return new SelectExpression(lets, select, orderby, limit, selectExpression.isSubquery());
}
Also used : LimitClause(org.apache.asterix.lang.common.clause.LimitClause) LetClause(org.apache.asterix.lang.common.clause.LetClause) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) SelectSetOperation(org.apache.asterix.lang.sqlpp.clause.SelectSetOperation) ArrayList(java.util.ArrayList) OrderbyClause(org.apache.asterix.lang.common.clause.OrderbyClause) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression)

Example 8 with SelectSetOperation

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

the class SqlppCloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(SelectExpression selectExpression, VariableSubstitutionEnvironment env) throws CompilationException {
    boolean subquery = selectExpression.isSubquery();
    List<LetClause> newLetList = new ArrayList<>();
    SelectSetOperation newSelectSetOperation;
    OrderbyClause newOrderbyClause = null;
    LimitClause newLimitClause = null;
    VariableSubstitutionEnvironment currentEnv = env;
    Pair<ILangExpression, VariableSubstitutionEnvironment> p;
    if (selectExpression.hasLetClauses()) {
        for (LetClause letClause : selectExpression.getLetList()) {
            p = letClause.accept(this, currentEnv);
            newLetList.add(letClause);
            currentEnv = p.second;
        }
    }
    p = selectExpression.getSelectSetOperation().accept(this, env);
    newSelectSetOperation = (SelectSetOperation) p.first;
    currentEnv = p.second;
    if (selectExpression.hasOrderby()) {
        p = selectExpression.getOrderbyClause().accept(this, currentEnv);
        newOrderbyClause = (OrderbyClause) p.first;
        currentEnv = p.second;
    }
    if (selectExpression.hasLimit()) {
        p = selectExpression.getLimitClause().accept(this, currentEnv);
        newLimitClause = (LimitClause) p.first;
        currentEnv = p.second;
    }
    return new Pair<>(new SelectExpression(newLetList, newSelectSetOperation, newOrderbyClause, newLimitClause, subquery), currentEnv);
}
Also used : LimitClause(org.apache.asterix.lang.common.clause.LimitClause) VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) LetClause(org.apache.asterix.lang.common.clause.LetClause) SelectSetOperation(org.apache.asterix.lang.sqlpp.clause.SelectSetOperation) ArrayList(java.util.ArrayList) OrderbyClause(org.apache.asterix.lang.common.clause.OrderbyClause) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Aggregations

SelectSetOperation (org.apache.asterix.lang.sqlpp.clause.SelectSetOperation)8 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)8 ArrayList (java.util.ArrayList)6 SetOperationInput (org.apache.asterix.lang.sqlpp.struct.SetOperationInput)6 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)5 SelectBlock (org.apache.asterix.lang.sqlpp.clause.SelectBlock)5 Expression (org.apache.asterix.lang.common.base.Expression)3 LimitClause (org.apache.asterix.lang.common.clause.LimitClause)3 OrderbyClause (org.apache.asterix.lang.common.clause.OrderbyClause)3 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)3 FromClause (org.apache.asterix.lang.sqlpp.clause.FromClause)3 FromTerm (org.apache.asterix.lang.sqlpp.clause.FromTerm)3 SelectClause (org.apache.asterix.lang.sqlpp.clause.SelectClause)3 SelectElement (org.apache.asterix.lang.sqlpp.clause.SelectElement)3 SetOperationRight (org.apache.asterix.lang.sqlpp.struct.SetOperationRight)3 LetClause (org.apache.asterix.lang.common.clause.LetClause)2 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)2 Pair (org.apache.hyracks.algebricks.common.utils.Pair)2 HashMap (java.util.HashMap)1 CompilationException (org.apache.asterix.common.exceptions.CompilationException)1