Search in sources :

Example 1 with RangeMap

use of org.apache.hyracks.dataflow.common.data.partition.range.RangeMap 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

DataOutput (java.io.DataOutput)1 CompilationException (org.apache.asterix.common.exceptions.CompilationException)1 Expression (org.apache.asterix.lang.common.base.Expression)1 IParser (org.apache.asterix.lang.common.base.IParser)1 Statement (org.apache.asterix.lang.common.base.Statement)1 ListConstructor (org.apache.asterix.lang.common.expression.ListConstructor)1 Query (org.apache.asterix.lang.common.statement.Query)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