Search in sources :

Example 6 with CallExpr

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);
}
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 7 with CallExpr

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);
}
Also used : 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) CallExpr(org.apache.asterix.lang.common.expression.CallExpr) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression)

Example 8 with CallExpr

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);
}
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 9 with CallExpr

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;
}
Also used : Query(org.apache.asterix.lang.common.statement.Query) ArrayList(java.util.ArrayList) WhereClause(org.apache.asterix.lang.common.clause.WhereClause) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) ForClause(org.apache.asterix.lang.aql.clause.ForClause) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature) Identifier(org.apache.asterix.lang.common.struct.Identifier) StringLiteral(org.apache.asterix.lang.common.literal.StringLiteral) Expression(org.apache.asterix.lang.common.base.Expression) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) LiteralExpr(org.apache.asterix.lang.common.expression.LiteralExpr) CallExpr(org.apache.asterix.lang.common.expression.CallExpr) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) ForClause(org.apache.asterix.lang.aql.clause.ForClause) Clause(org.apache.asterix.lang.common.base.Clause) WhereClause(org.apache.asterix.lang.common.clause.WhereClause)

Aggregations

Expression (org.apache.asterix.lang.common.base.Expression)9 CallExpr (org.apache.asterix.lang.common.expression.CallExpr)9 ArrayList (java.util.ArrayList)7 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)7 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)4 LiteralExpr (org.apache.asterix.lang.common.expression.LiteralExpr)4 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)4 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)4 StringLiteral (org.apache.asterix.lang.common.literal.StringLiteral)4 WhereClause (org.apache.asterix.lang.common.clause.WhereClause)2 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)2 Query (org.apache.asterix.lang.common.statement.Query)2 Identifier (org.apache.asterix.lang.common.struct.Identifier)2 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)2 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)2 Pair (org.apache.hyracks.algebricks.common.utils.Pair)2 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 LetClause (org.apache.asterix.lang.common.clause.LetClause)1