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