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);
}
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);
}
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;
}
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();
}
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);
}
Aggregations