Search in sources :

Example 1 with SetOperationRight

use of org.apache.asterix.lang.sqlpp.struct.SetOperationRight in project asterixdb by apache.

the class SqlppCloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(SelectSetOperation selectSetOperation, VariableSubstitutionEnvironment env) throws CompilationException {
    SetOperationInput leftInput = selectSetOperation.getLeftInput();
    SetOperationInput newLeftInput;
    Pair<ILangExpression, VariableSubstitutionEnvironment> leftResult;
    // Sets the left input.
    if (leftInput.selectBlock()) {
        leftResult = leftInput.getSelectBlock().accept(this, env);
        newLeftInput = new SetOperationInput((SelectBlock) leftResult.first, null);
    } else {
        leftResult = leftInput.getSubquery().accept(this, env);
        newLeftInput = new SetOperationInput(null, (SelectExpression) leftResult.first);
    }
    // Sets the right input
    List<SetOperationRight> newRightInputs = new ArrayList<>();
    if (selectSetOperation.hasRightInputs()) {
        for (SetOperationRight right : selectSetOperation.getRightInputs()) {
            SetOperationInput newRightInput;
            SetOperationInput rightInput = right.getSetOperationRightInput();
            if (rightInput.selectBlock()) {
                Pair<ILangExpression, VariableSubstitutionEnvironment> rightResult = rightInput.getSelectBlock().accept(this, env);
                newRightInput = new SetOperationInput((SelectBlock) rightResult.first, null);
            } else {
                Pair<ILangExpression, VariableSubstitutionEnvironment> rightResult = rightInput.getSubquery().accept(this, env);
                newRightInput = new SetOperationInput(null, (SelectExpression) rightResult.first);
            }
            newRightInputs.add(new SetOperationRight(right.getSetOpType(), right.isSetSemantics(), newRightInput));
        }
    }
    SelectSetOperation newSelectSetOperation = new SelectSetOperation(newLeftInput, newRightInputs);
    return new Pair<>(newSelectSetOperation, selectSetOperation.hasRightInputs() ? env : leftResult.second);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) SelectBlock(org.apache.asterix.lang.sqlpp.clause.SelectBlock) SetOperationInput(org.apache.asterix.lang.sqlpp.struct.SetOperationInput) SelectSetOperation(org.apache.asterix.lang.sqlpp.clause.SelectSetOperation) 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) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 2 with SetOperationRight

use of org.apache.asterix.lang.sqlpp.struct.SetOperationRight in project asterixdb by apache.

the class DeepCopyVisitor method visit.

@Override
public SelectSetOperation visit(SelectSetOperation selectSetOperation, Void arg) throws CompilationException {
    SetOperationInput leftInput = selectSetOperation.getLeftInput();
    SetOperationInput newLeftInput;
    if (leftInput.selectBlock()) {
        newLeftInput = new SetOperationInput((SelectBlock) leftInput.accept(this, arg), null);
    } else {
        newLeftInput = new SetOperationInput(null, (SelectExpression) leftInput.accept(this, arg));
    }
    List<SetOperationRight> rightInputs = new ArrayList<>();
    for (SetOperationRight right : selectSetOperation.getRightInputs()) {
        SetOperationInput newRightInput;
        SetOperationInput setOpRightInput = right.getSetOperationRightInput();
        if (setOpRightInput.selectBlock()) {
            newRightInput = new SetOperationInput((SelectBlock) setOpRightInput.accept(this, arg), null);
        } else {
            newRightInput = new SetOperationInput(null, (SelectExpression) setOpRightInput.accept(this, arg));
        }
        rightInputs.add(new SetOperationRight(right.getSetOpType(), right.isSetSemantics(), newRightInput));
    }
    return new SelectSetOperation(newLeftInput, rightInputs);
}
Also used : SelectBlock(org.apache.asterix.lang.sqlpp.clause.SelectBlock) SetOperationInput(org.apache.asterix.lang.sqlpp.struct.SetOperationInput) SelectSetOperation(org.apache.asterix.lang.sqlpp.clause.SelectSetOperation) ArrayList(java.util.ArrayList) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) SetOperationRight(org.apache.asterix.lang.sqlpp.struct.SetOperationRight)

Example 3 with SetOperationRight

use of org.apache.asterix.lang.sqlpp.struct.SetOperationRight in project asterixdb by apache.

the class AbstractSqlppExpressionScopingVisitor method visit.

@Override
public Expression visit(SelectSetOperation selectSetOperation, ILangExpression arg) throws CompilationException {
    Scope scopeBeforeCurrentBranch = scopeChecker.getCurrentScope();
    scopeChecker.createNewScope();
    selectSetOperation.getLeftInput().accept(this, arg);
    if (selectSetOperation.hasRightInputs()) {
        for (SetOperationRight right : selectSetOperation.getRightInputs()) {
            // Exit scopes that were entered within a previous select expression
            while (scopeChecker.getCurrentScope() != scopeBeforeCurrentBranch) {
                scopeChecker.removeCurrentScope();
            }
            scopeChecker.createNewScope();
            right.getSetOperationRightInput().accept(this, arg);
        }
        // Exit scopes that were entered within the last branch of the set operation.
        while (scopeChecker.getCurrentScope() != scopeBeforeCurrentBranch) {
            scopeChecker.removeCurrentScope();
        }
    }
    return null;
}
Also used : Scope(org.apache.asterix.lang.common.context.Scope) SetOperationRight(org.apache.asterix.lang.sqlpp.struct.SetOperationRight)

Example 4 with SetOperationRight

use of org.apache.asterix.lang.sqlpp.struct.SetOperationRight in project asterixdb by apache.

the class SelectSetOperation method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append(leftInput);
    for (SetOperationRight right : rightInputs) {
        sb.append(" " + right);
    }
    return sb.toString();
}
Also used : SetOperationRight(org.apache.asterix.lang.sqlpp.struct.SetOperationRight)

Example 5 with SetOperationRight

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

Aggregations

SetOperationRight (org.apache.asterix.lang.sqlpp.struct.SetOperationRight)8 ArrayList (java.util.ArrayList)3 SelectSetOperation (org.apache.asterix.lang.sqlpp.clause.SelectSetOperation)3 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)3 SetOperationInput (org.apache.asterix.lang.sqlpp.struct.SetOperationInput)3 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)2 SelectBlock (org.apache.asterix.lang.sqlpp.clause.SelectBlock)2 CompilationException (org.apache.asterix.common.exceptions.CompilationException)1 Scope (org.apache.asterix.lang.common.context.Scope)1 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)1 SetOpType (org.apache.asterix.lang.sqlpp.optype.SetOpType)1 Pair (org.apache.hyracks.algebricks.common.utils.Pair)1