use of org.apache.asterix.lang.common.expression.CallExpr 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.CallExpr 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.expression.CallExpr 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.CallExpr in project asterixdb by apache.
the class AqlDeleteRewriteVisitor method visit.
@Override
public Void visit(DeleteStatement deleteStmt, Void visitArg) {
List<Expression> arguments = new ArrayList<>();
Identifier dataverseName = deleteStmt.getDataverseName();
Identifier datasetName = deleteStmt.getDatasetName();
String arg = dataverseName == null ? datasetName.getValue() : dataverseName.getValue() + "." + datasetName.getValue();
LiteralExpr argumentLiteral = new LiteralExpr(new StringLiteral(arg));
arguments.add(argumentLiteral);
CallExpr callExpression = new CallExpr(new FunctionSignature(FunctionConstants.ASTERIX_NS, "dataset", 1), arguments);
List<Clause> clauseList = new ArrayList<>();
VariableExpr var = deleteStmt.getVariableExpr();
Clause forClause = new ForClause(var, callExpression);
clauseList.add(forClause);
Clause whereClause = null;
Expression condition = deleteStmt.getCondition();
if (condition != null) {
whereClause = new WhereClause(condition);
clauseList.add(whereClause);
}
VariableExpr returnExpr = new VariableExpr(var.getVar());
returnExpr.setIsNewVar(false);
FLWOGRExpression flowgr = new FLWOGRExpression(clauseList, returnExpr);
Query query = new Query(false);
query.setBody(flowgr);
deleteStmt.setQuery(query);
return null;
}
Aggregations