use of org.apache.asterix.lang.common.expression.OperatorExpr in project asterixdb by apache.
the class OperatorExpressionVisitor method createLessThanExpression.
private Expression createLessThanExpression(Expression lhs, Expression rhs, List<IExpressionAnnotation> hints) throws CompilationException {
OperatorExpr comparison = new OperatorExpr();
comparison.addOperand(lhs);
comparison.addOperand(rhs);
comparison.addOperator("<=");
if (hints != null) {
for (IExpressionAnnotation hint : hints) {
comparison.addHint(hint);
}
}
return comparison;
}
use of org.apache.asterix.lang.common.expression.OperatorExpr 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.expression.OperatorExpr 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.expression.OperatorExpr in project asterixdb by apache.
the class SqlppBuiltinFunctionRewriteVisitor method normalizeCaseExpr.
// Normalizes WHEN expressions so that it can have correct NULL/MISSING semantics as well
// as type promotion semantics.
private CaseExpression normalizeCaseExpr(CaseExpression caseExpr) throws CompilationException {
LiteralExpr trueLiteral = new LiteralExpr(TrueLiteral.INSTANCE);
Expression conditionExpr = caseExpr.getConditionExpr();
if (trueLiteral.equals(conditionExpr)) {
return caseExpr;
}
List<Expression> normalizedWhenExprs = new ArrayList<>();
for (Expression expr : caseExpr.getWhenExprs()) {
OperatorExpr operatorExpr = new OperatorExpr();
operatorExpr.addOperand((Expression) SqlppRewriteUtil.deepCopy(expr));
operatorExpr.addOperand(caseExpr.getConditionExpr());
operatorExpr.addOperator("=");
normalizedWhenExprs.add(operatorExpr);
}
return new CaseExpression(trueLiteral, normalizedWhenExprs, caseExpr.getThenExprs(), caseExpr.getElseExpr());
}
use of org.apache.asterix.lang.common.expression.OperatorExpr in project asterixdb by apache.
the class CloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(OperatorExpr op, VariableSubstitutionEnvironment env) throws CompilationException {
List<Expression> oldExprList = op.getExprList();
List<Expression> exprs = new ArrayList<>(oldExprList.size());
for (Expression e : oldExprList) {
Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = e.accept(this, env);
exprs.add((Expression) p1.first);
}
OperatorExpr oe = new OperatorExpr(exprs, op.getExprBroadcastIdx(), op.getOpList(), op.isCurrentop());
return new Pair<>(oe, env);
}
Aggregations