use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class SubstituteGroupbyExpressionVisitor method visit.
@Override
public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws CompilationException {
if (selectBlock.hasGroupbyClause()) {
Map<Expression, Expression> map = new HashMap<>();
for (GbyVariableExpressionPair gbyKeyPair : selectBlock.getGroupbyClause().getGbyPairList()) {
Expression gbyKeyExpr = gbyKeyPair.getExpr();
if (gbyKeyExpr.getKind() != Kind.VARIABLE_EXPRESSION) {
map.put(gbyKeyExpr, gbyKeyPair.getVar());
}
}
// Creates a substitution visitor.
SubstituteGroupbyExpressionVisitor visitor = new SubstituteGroupbyExpressionVisitor(context, map);
// Rewrites LET/HAVING/SELECT clauses.
if (selectBlock.hasLetClausesAfterGroupby()) {
for (LetClause letClause : selectBlock.getLetListAfterGroupby()) {
letClause.accept(this, arg);
}
}
if (selectBlock.hasHavingClause()) {
selectBlock.getHavingClause().accept(visitor, arg);
}
selectBlock.getSelectClause().accept(visitor, arg);
SelectExpression selectExpression = (SelectExpression) arg;
// For SET operation queries, the GROUP BY key variables will not substitute ORDER BY nor LIMIT expressions.
if (!selectExpression.getSelectSetOperation().hasRightInputs()) {
if (selectExpression.hasOrderby()) {
selectExpression.getOrderbyClause().accept(visitor, arg);
}
if (selectExpression.hasLimit()) {
selectExpression.getLimitClause().accept(visitor, arg);
}
}
}
return super.visit(selectBlock, arg);
}
use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class SqlppAstPrintUtil method toString.
/**
* @param exprs
* a list of language expression.
* @return an AST of the input language expressions.
* @throws CompilationException
*/
public static String toString(List<ILangExpression> exprs) throws CompilationException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrintWriter output = new PrintWriter(bos);
QueryPrintVisitor visitor = astPrintVisitorFactory.createLangVisitor(output);
for (ILangExpression expr : exprs) {
expr.accept(visitor, 0);
}
output.close();
return bos.toString();
}
use of org.apache.asterix.lang.common.base.ILangExpression 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);
}
use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class CloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(LetClause lc, VariableSubstitutionEnvironment env) throws CompilationException {
Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = lc.getBindingExpr().accept(this, env);
VariableExpr varExpr = lc.getVarExpr();
VariableExpr newVe = generateNewVariable(context, varExpr);
LetClause newLet = new LetClause(newVe, (Expression) p1.first);
return new Pair<>(newLet, VariableCloneAndSubstitutionUtil.eliminateSubstFromList(lc.getVarExpr(), env));
}
use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class CloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(LimitClause lc, VariableSubstitutionEnvironment env) throws CompilationException {
Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = lc.getLimitExpr().accept(this, env);
Pair<ILangExpression, VariableSubstitutionEnvironment> p2;
Expression lcOffsetExpr = lc.getOffset();
if (lcOffsetExpr != null) {
p2 = lcOffsetExpr.accept(this, env);
} else {
p2 = new Pair<>(null, null);
}
LimitClause c = new LimitClause((Expression) p1.first, (Expression) p2.first);
return new Pair<>(c, env);
}
Aggregations