@Override
protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
throws AlgebricksException {
final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
final SequenceBuilder sb = new SequenceBuilder();
final SequencePointable seq = (SequencePointable) SequencePointable.FACTORY.createPointable();
final VoidPointable p = (VoidPointable) VoidPointable.FACTORY.createPointable();
final DoublePointable doublep = (DoublePointable) DoublePointable.FACTORY.createPointable();
final LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
final XSDecimalPointable decp = (XSDecimalPointable) XSDecimalPointable.FACTORY.createPointable();
final ArrayBackedValueStorage abvsRound = new ArrayBackedValueStorage();
final FnRoundOperation round = new FnRoundOperation();
return new AbstractTaggedValueArgumentScalarEvaluator(args) {
@Override
protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
try {
long startingLoc;
TaggedValuePointable tvp2 = args[1];
startingLoc = getLongFromArgument(tvp2);
if (startingLoc < 1) {
startingLoc = 1;
}
// Get length.
long endingLoc = Long.MAX_VALUE;
if (args.length > 2) {
TaggedValuePointable tvp3 = args[2];
endingLoc = getLongFromArgument(tvp3) + startingLoc;
}
abvs.reset();
sb.reset(abvs);
TaggedValuePointable tvp1 = args[0];
if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
tvp1.getValue(seq);
int seqLen = seq.getEntryCount();
if (endingLoc < startingLoc) {
// Empty sequence.
} else if (startingLoc == 1 && endingLoc > seqLen) {
// Includes whole sequence.
result.set(tvp1);
return;
} else {
for (int j = 0; j < seqLen; ++j) {
if (startingLoc <= j + 1 && j + 1 < endingLoc) {
seq.getEntry(j, p);
sb.addItem(p);
}
}
}
} else if (startingLoc == 1 && endingLoc > 1) {