Search in sources :

Example 11 with LiteralExpr

use of org.apache.asterix.lang.common.expression.LiteralExpr in project asterixdb by apache.

the class AbstractSqlppExpressionScopingVisitor method wrapWithResolveFunction.

// Rewrites for an undefined variable reference, which potentially could be a syntatic sugar.
protected Expression wrapWithResolveFunction(VariableExpr expr, Set<VariableExpr> liveVars) throws CompilationException {
    List<Expression> argList = new ArrayList<>();
    //Ignore the parser-generated prefix "$" for a dataset.
    String varName = SqlppVariableUtil.toUserDefinedVariableName(expr.getVar().getValue()).getValue();
    argList.add(new LiteralExpr(new StringLiteral(varName)));
    argList.addAll(liveVars);
    return new CallExpr(resolveFunction, argList);
}
Also used : StringLiteral(org.apache.asterix.lang.common.literal.StringLiteral) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) ArrayList(java.util.ArrayList) LiteralExpr(org.apache.asterix.lang.common.expression.LiteralExpr) CallExpr(org.apache.asterix.lang.common.expression.CallExpr)

Example 12 with LiteralExpr

use of org.apache.asterix.lang.common.expression.LiteralExpr in project asterixdb by apache.

the class VariableCheckAndRewriteVisitor method wrapWithDatasetFunction.

private Expression wrapWithDatasetFunction(String dataverseName, String datasetName) throws CompilationException {
    String fullyQualifiedName = dataverseName == null ? datasetName : dataverseName + "." + datasetName;
    List<Expression> argList = new ArrayList<>();
    argList.add(new LiteralExpr(new StringLiteral(fullyQualifiedName)));
    return new CallExpr(datasetFunction, argList);
}
Also used : StringLiteral(org.apache.asterix.lang.common.literal.StringLiteral) Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) ArrayList(java.util.ArrayList) LiteralExpr(org.apache.asterix.lang.common.expression.LiteralExpr) CallExpr(org.apache.asterix.lang.common.expression.CallExpr)

Example 13 with LiteralExpr

use of org.apache.asterix.lang.common.expression.LiteralExpr 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

LiteralExpr (org.apache.asterix.lang.common.expression.LiteralExpr)13 ArrayList (java.util.ArrayList)8 Expression (org.apache.asterix.lang.common.base.Expression)8 StringLiteral (org.apache.asterix.lang.common.literal.StringLiteral)7 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)6 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)5 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)4 CallExpr (org.apache.asterix.lang.common.expression.CallExpr)4 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)3 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)3 Identifier (org.apache.asterix.lang.common.struct.Identifier)3 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)3 Pair (org.apache.hyracks.algebricks.common.utils.Pair)3 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)3 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)3 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)3 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)3 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)3 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)3 CompilationException (org.apache.asterix.common.exceptions.CompilationException)2