use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class VariableCheckAndRewriteVisitor method visit.
@Override
public Expression visit(FieldAccessor fa, ILangExpression parent) throws CompilationException {
Expression leadingExpr = fa.getExpr();
if (leadingExpr.getKind() != Kind.VARIABLE_EXPRESSION) {
fa.setExpr(leadingExpr.accept(this, fa));
return fa;
} else {
VariableExpr varExpr = (VariableExpr) leadingExpr;
String lastIdentifier = fa.getIdent().getValue();
Expression resolvedExpr = resolve(varExpr, /** Resolves within the dataverse that has the same name as the variable name. */
SqlppVariableUtil.toUserDefinedVariableName(varExpr.getVar().getValue()).getValue(), lastIdentifier, fa, parent);
if (resolvedExpr.getKind() == Kind.CALL_EXPRESSION) {
CallExpr callExpr = (CallExpr) resolvedExpr;
if (callExpr.getFunctionSignature().equals(datasetFunction)) {
// The field access is resolved to be a dataset access in the form of "dataverse.dataset".
return resolvedExpr;
}
}
fa.setExpr(resolvedExpr);
return fa;
}
}
use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class SqlppGroupBySugarVisitor method visit.
@Override
public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
List<Expression> newExprList = new ArrayList<>();
FunctionSignature signature = callExpr.getFunctionSignature();
boolean aggregate = FunctionMapUtil.isSql92AggregateFunction(signature);
boolean rewritten = false;
for (Expression expr : callExpr.getExprList()) {
Expression newExpr = aggregate ? wrapAggregationArgument(expr) : expr;
rewritten |= newExpr != expr;
newExprList.add(newExpr.accept(this, arg));
}
if (rewritten) {
// Rewrites the SQL-92 function name to core functions,
// e.g., SUM --> coll_sum
callExpr.setFunctionSignature(FunctionMapUtil.sql92ToCoreAggregateFunction(signature));
}
callExpr.setExprList(newExprList);
return callExpr;
}
use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class DeepCopyVisitor method visit.
@Override
public ILangExpression visit(CaseExpression caseExpr, Void arg) throws CompilationException {
Expression conditionExpr = (Expression) caseExpr.getConditionExpr().accept(this, arg);
List<Expression> whenExprList = copyExprList(caseExpr.getWhenExprs(), arg);
List<Expression> thenExprList = copyExprList(caseExpr.getThenExprs(), arg);
Expression elseExpr = (Expression) caseExpr.getElseExpr().accept(this, arg);
return new CaseExpression(conditionExpr, whenExprList, thenExprList, elseExpr);
}
use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class SqlppBuiltinFunctionRewriteVisitor method visit.
@Override
public Expression visit(CaseExpression caseExpr, ILangExpression arg) throws CompilationException {
// Visits it as usual first.
Expression expr = super.visit(caseExpr, arg);
if (expr != caseExpr) {
return expr.accept(this, arg);
}
CaseExpression newCaseExpr = normalizeCaseExpr(caseExpr);
if (SqlppRewriteUtil.constainsSubquery(newCaseExpr)) {
// If the CASE expression contains a subquery, we do not rewrite it to a switch-case function call.
return newCaseExpr;
}
// If the CASE expression does not contain a subquery, we rewrite it to a switch-case function call.
FunctionSignature functionSignature = new FunctionSignature(MetadataConstants.METADATA_DATAVERSE_NAME, "switch-case", FunctionIdentifier.VARARGS);
List<Expression> whenExprList = newCaseExpr.getWhenExprs();
List<Expression> thenExprList = newCaseExpr.getThenExprs();
List<Expression> newExprList = new ArrayList<>();
newExprList.add(newCaseExpr.getConditionExpr());
for (int index = 0; index < whenExprList.size(); ++index) {
newExprList.add(whenExprList.get(index));
newExprList.add(thenExprList.get(index));
}
newExprList.add(newCaseExpr.getElseExpr());
return new CallExpr(functionSignature, newExprList);
}
use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class SqlppBuiltinFunctionRewriteVisitor method visit.
@Override
public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
//TODO(buyingyi): rewrite SQL temporal functions
FunctionSignature functionSignature = callExpr.getFunctionSignature();
callExpr.setFunctionSignature(FunctionMapUtil.normalizeBuiltinFunctionSignature(functionSignature, true));
List<Expression> newExprList = new ArrayList<>();
for (Expression expr : callExpr.getExprList()) {
newExprList.add(expr.accept(this, arg));
}
callExpr.setExprList(newExprList);
return callExpr;
}
Aggregations