use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class InlineWithExpressionVisitor method visit.
@Override
public Expression visit(SelectExpression selectExpression, ILangExpression arg) throws CompilationException {
if (selectExpression.hasLetClauses()) {
// Inlines the leading WITH list.
Map<Expression, Expression> varExprMap = new HashMap<>();
List<LetClause> withs = selectExpression.getLetList();
Iterator<LetClause> with = withs.iterator();
while (with.hasNext()) {
LetClause letClause = with.next();
// Replaces the let binding Expr.
Expression expr = letClause.getBindingExpr();
Expression newBindingExpr = SqlppRewriteUtil.substituteExpression(expr, varExprMap, context);
letClause.setBindingExpr(newBindingExpr);
// Performs the rewriting recursively in the newBindingExpr itself.
super.visit(newBindingExpr, arg);
// Removes the WITH entry and adds variable-expr mapping into the varExprMap.
with.remove();
Expression bindingExpr = letClause.getBindingExpr();
// Wraps the binding expression with IndependentSubquery, so that free identifier references
// in the binding expression will not be resolved use outer-scope variables.
varExprMap.put(letClause.getVarExpr(), bindingExpr);
}
// Inlines WITH expressions into the select expression.
SelectExpression newSelectExpression = (SelectExpression) substituteExpression(selectExpression, varExprMap, context);
// Continues to visit the rewritten select expression.
return super.visit(newSelectExpression, arg);
} else {
// Continues to visit inside the select expression.
return super.visit(selectExpression, arg);
}
}
use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class OperatorExpressionVisitor method processBetweenOperator.
private Expression processBetweenOperator(OperatorExpr operatorExpr, OperatorType opType) throws CompilationException {
// The grammar guarantees that the BETWEEN operator gets exactly three expressions.
Expression target = operatorExpr.getExprList().get(0);
Expression left = operatorExpr.getExprList().get(1);
Expression right = operatorExpr.getExprList().get(2);
// Creates the expression left <= target.
Expression leftComparison = createLessThanExpression(left, target, operatorExpr.getHints());
// Creates the expression target <= right.
Expression rightComparison = createLessThanExpression(target, right, operatorExpr.getHints());
OperatorExpr andExpr = new OperatorExpr();
andExpr.addOperand(leftComparison);
andExpr.addOperand(rightComparison);
andExpr.addOperator("and");
return opType == OperatorType.BETWEEN ? andExpr : new CallExpr(new FunctionSignature(null, "not", 1), new ArrayList<>(Collections.singletonList(andExpr)));
}
use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class OperatorExpressionVisitor method processInOperator.
private Expression processInOperator(OperatorExpr operatorExpr, OperatorType opType) throws CompilationException {
VariableExpr bindingVar = new VariableExpr(context.newVariable());
Expression itemExpr = operatorExpr.getExprList().get(0);
Expression collectionExpr = operatorExpr.getExprList().get(1);
OperatorExpr comparison = new OperatorExpr();
comparison.addOperand(itemExpr);
comparison.addOperand(bindingVar);
comparison.setCurrentop(true);
if (opType == OperatorType.IN) {
comparison.addOperator("=");
return new QuantifiedExpression(Quantifier.SOME, new ArrayList<>(Collections.singletonList(new QuantifiedPair(bindingVar, collectionExpr))), comparison);
} else {
comparison.addOperator("!=");
return new QuantifiedExpression(Quantifier.EVERY, new ArrayList<>(Collections.singletonList(new QuantifiedPair(bindingVar, collectionExpr))), comparison);
}
}
use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class DeepCopyVisitor method visit.
@Override
public NestClause visit(NestClause nestClause, Void arg) throws CompilationException {
Expression rightExpression = (Expression) nestClause.getRightExpression().accept(this, arg);
VariableExpr rightVar = (VariableExpr) nestClause.getRightVariable().accept(this, arg);
VariableExpr rightPositionVar = nestClause.getPositionalVariable() == null ? null : (VariableExpr) nestClause.getPositionalVariable().accept(this, arg);
Expression conditionExpresion = (Expression) nestClause.getConditionExpression().accept(this, arg);
return new NestClause(nestClause.getJoinType(), rightExpression, rightVar, rightPositionVar, conditionExpresion);
}
use of org.apache.asterix.lang.common.base.Expression 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());
}
Aggregations