Search in sources :

Example 61 with Expression

use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.

the class CloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(ListConstructor lc, VariableSubstitutionEnvironment env) throws CompilationException {
    List<Expression> oldExprList = lc.getExprList();
    List<Expression> exprs = VariableCloneAndSubstitutionUtil.visitAndCloneExprList(oldExprList, env, this);
    ListConstructor c = new ListConstructor(lc.getType(), exprs);
    return new Pair<>(c, env);
}
Also used : ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) Expression(org.apache.asterix.lang.common.base.Expression) ListConstructor(org.apache.asterix.lang.common.expression.ListConstructor) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 62 with Expression

use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.

the class CloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(OperatorExpr op, VariableSubstitutionEnvironment env) throws CompilationException {
    List<Expression> oldExprList = op.getExprList();
    List<Expression> exprs = new ArrayList<>(oldExprList.size());
    for (Expression e : oldExprList) {
        Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = e.accept(this, env);
        exprs.add((Expression) p1.first);
    }
    OperatorExpr oe = new OperatorExpr(exprs, op.getExprBroadcastIdx(), op.getOpList(), op.isCurrentop());
    return new Pair<>(oe, env);
}
Also used : OperatorExpr(org.apache.asterix.lang.common.expression.OperatorExpr) VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) Expression(org.apache.asterix.lang.common.base.Expression) ArrayList(java.util.ArrayList) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 63 with Expression

use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.

the class FormatPrintVisitor method visit.

@Override
public Void visit(OperatorExpr operatorExpr, Integer step) throws CompilationException {
    List<Expression> exprList = operatorExpr.getExprList();
    List<OperatorType> opList = operatorExpr.getOpList();
    if (operatorExpr.isCurrentop()) {
        out.print("(");
        exprList.get(0).accept(this, step + 1);
        for (int i = 1; i < exprList.size(); i++) {
            OperatorType opType = opList.get(i - 1);
            ;
            if (i == 1) {
                printHints(operatorExpr.getHints(), step + 1);
            }
            out.print(" " + opType + " ");
            exprList.get(i).accept(this, step + 1);
        }
        out.print(")");
    } else {
        exprList.get(0).accept(this, step);
    }
    return null;
}
Also used : TypeReferenceExpression(org.apache.asterix.lang.common.expression.TypeReferenceExpression) Expression(org.apache.asterix.lang.common.base.Expression) TypeExpression(org.apache.asterix.lang.common.expression.TypeExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) OperatorType(org.apache.asterix.lang.common.struct.OperatorType)

Example 64 with Expression

use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.

the class FormatPrintVisitor method visit.

@Override
public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
    if (gc.hasHashGroupByHint()) {
        out.println(skip(step) + "/* +hash */");
    }
    out.print(skip(step) + "group by ");
    printDelimitedGbyExpressions(gc.getGbyPairList(), step + 2);
    if (gc.hasDecorList()) {
        out.print(" decor ");
        printDelimitedGbyExpressions(gc.getDecorPairList(), step + 2);
    }
    if (gc.hasWithMap()) {
        out.print(" with ");
        Map<Expression, VariableExpr> withVarMap = gc.getWithVarMap();
        int index = 0;
        int size = withVarMap.size();
        for (Entry<Expression, VariableExpr> entry : withVarMap.entrySet()) {
            Expression key = entry.getKey();
            VariableExpr value = entry.getValue();
            key.accept(this, step + 2);
            if (!key.equals(value)) {
                out.print(" as ");
                value.accept(this, step + 2);
            }
            if (++index < size) {
                out.print(COMMA);
            }
        }
    }
    out.println();
    return null;
}
Also used : TypeReferenceExpression(org.apache.asterix.lang.common.expression.TypeReferenceExpression) Expression(org.apache.asterix.lang.common.base.Expression) TypeExpression(org.apache.asterix.lang.common.expression.TypeExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr)

Example 65 with Expression

use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.

the class LangRecordParseUtil method parseList.

private static void parseList(ListConstructor valueExpr, ArrayBackedValueStorage serialized) throws HyracksDataException {
    if (valueExpr.getType() != ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR) {
        throw new HyracksDataException(ErrorCode.ASTERIX, ErrorCode.PARSE_ERROR, "JSON List can't be of type %1$s", valueExpr.getType());
    }
    ArrayBackedValueStorage serializedValue = new ArrayBackedValueStorage();
    OrderedListBuilder listBuilder = new OrderedListBuilder();
    listBuilder.reset(null);
    for (Expression expr : valueExpr.getExprList()) {
        serializedValue.reset();
        parseExpression(expr, serializedValue);
        listBuilder.addItem(serializedValue);
    }
    listBuilder.write(serialized.getDataOutput(), true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) Expression(org.apache.asterix.lang.common.base.Expression) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

Expression (org.apache.asterix.lang.common.base.Expression)105 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)75 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)52 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)41 ArrayList (java.util.ArrayList)37 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)36 Pair (org.apache.hyracks.algebricks.common.utils.Pair)35 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)32 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)32 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)22 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)19 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)19 FLWOGRExpression (org.apache.asterix.lang.aql.expression.FLWOGRExpression)17 Mutable (org.apache.commons.lang3.mutable.Mutable)17 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)17 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)16 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)16 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)16 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)16 UnnestingFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression)16