Search in sources :

Example 1 with ListConstructor

use of org.apache.asterix.lang.common.expression.ListConstructor in project asterixdb by apache.

the class FunctionMapUtil method normalizedListInputFunctions.

/**
     * Rewrites a variable-arg, user-surface function call into an internal, list-arg function.
     *
     * @param callExpr
     *            The input call expression.
     * @return a new call expression that calls the corresponding AsterixDB internal function.
     */
public static CallExpr normalizedListInputFunctions(CallExpr callExpr) {
    FunctionSignature fs = callExpr.getFunctionSignature();
    String internalFuncName = LIST_INPUT_FUNCTION_MAP.get(fs.getName().toLowerCase());
    if (internalFuncName == null) {
        return callExpr;
    }
    callExpr.setFunctionSignature(new FunctionSignature(FunctionConstants.ASTERIX_NS, internalFuncName, 1));
    callExpr.setExprList(new ArrayList<>(Collections.singletonList(new ListConstructor(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR, callExpr.getExprList()))));
    return callExpr;
}
Also used : FunctionSignature(org.apache.asterix.common.functions.FunctionSignature) ListConstructor(org.apache.asterix.lang.common.expression.ListConstructor)

Example 2 with ListConstructor

use of org.apache.asterix.lang.common.expression.ListConstructor 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 3 with ListConstructor

use of org.apache.asterix.lang.common.expression.ListConstructor in project asterixdb by apache.

the class RangeMapBuilder method parseHint.

public static IRangeMap parseHint(Object hint) throws CompilationException {
    ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
    DataOutput out = abvs.getDataOutput();
    ;
    abvs.reset();
    IParser parser = parserFactory.createParser((String) hint);
    List<Statement> hintStatements = parser.parse();
    if (hintStatements.size() != 1) {
        throw new CompilationException("Only one range statement is allowed for the range hint.");
    }
    // Translate the query into a Range Map
    if (hintStatements.get(0).getKind() != Statement.Kind.QUERY) {
        throw new CompilationException("Not a proper query for the range hint.");
    }
    Query q = (Query) hintStatements.get(0);
    if (q.getBody().getKind() != Kind.LIST_CONSTRUCTOR_EXPRESSION) {
        throw new CompilationException("The range hint must be a list.");
    }
    List<Expression> el = ((ListConstructor) q.getBody()).getExprList();
    int[] offsets = new int[el.size()];
    // Loop over list of literals
    for (int i = 0; i < el.size(); ++i) {
        Expression item = el.get(i);
        if (item.getKind() == Kind.LITERAL_EXPRESSION) {
            parseLiteralToBytes(item, out);
            offsets[i] = abvs.getLength();
        }
    // TODO Add support for composite fields.
    }
    return new RangeMap(1, abvs.getByteArray(), offsets);
}
Also used : DataOutput(java.io.DataOutput) CompilationException(org.apache.asterix.common.exceptions.CompilationException) Query(org.apache.asterix.lang.common.statement.Query) Statement(org.apache.asterix.lang.common.base.Statement) ListConstructor(org.apache.asterix.lang.common.expression.ListConstructor) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IRangeMap(org.apache.hyracks.dataflow.common.data.partition.range.IRangeMap) RangeMap(org.apache.hyracks.dataflow.common.data.partition.range.RangeMap) Expression(org.apache.asterix.lang.common.base.Expression) IParser(org.apache.asterix.lang.common.base.IParser)

Aggregations

ListConstructor (org.apache.asterix.lang.common.expression.ListConstructor)3 Expression (org.apache.asterix.lang.common.base.Expression)2 DataOutput (java.io.DataOutput)1 CompilationException (org.apache.asterix.common.exceptions.CompilationException)1 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)1 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)1 IParser (org.apache.asterix.lang.common.base.IParser)1 Statement (org.apache.asterix.lang.common.base.Statement)1 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)1 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)1 Query (org.apache.asterix.lang.common.statement.Query)1 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)1 Pair (org.apache.hyracks.algebricks.common.utils.Pair)1 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)1 IRangeMap (org.apache.hyracks.dataflow.common.data.partition.range.IRangeMap)1 RangeMap (org.apache.hyracks.dataflow.common.data.partition.range.RangeMap)1