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);
}
Aggregations