Search in sources :

Example 6 with OperatorExpr

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());
}
Also used : OperatorExpr(org.apache.asterix.lang.common.expression.OperatorExpr) Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) ArrayList(java.util.ArrayList) LiteralExpr(org.apache.asterix.lang.common.expression.LiteralExpr) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression)

Aggregations

OperatorExpr (org.apache.asterix.lang.common.expression.OperatorExpr)6 Expression (org.apache.asterix.lang.common.base.Expression)5 ArrayList (java.util.ArrayList)4 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)4 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)3 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)2 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)1 DistinctClause (org.apache.asterix.lang.aql.clause.DistinctClause)1 ForClause (org.apache.asterix.lang.aql.clause.ForClause)1 FLWOGRExpression (org.apache.asterix.lang.aql.expression.FLWOGRExpression)1 Clause (org.apache.asterix.lang.common.base.Clause)1 GroupbyClause (org.apache.asterix.lang.common.clause.GroupbyClause)1 LetClause (org.apache.asterix.lang.common.clause.LetClause)1 WhereClause (org.apache.asterix.lang.common.clause.WhereClause)1 CallExpr (org.apache.asterix.lang.common.expression.CallExpr)1 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)1 LiteralExpr (org.apache.asterix.lang.common.expression.LiteralExpr)1 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)1 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)1 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)1