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