Source:
<code>protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) throws AlgebricksException { final SequencePointable sp = (SequencePointable) SequencePointable.FACTORY.createPointable(); final ArrayPointable ap = (ArrayPointable) ArrayPointable.FACTORY.createPointable(); final ArrayPointable ap1 = (ArrayPointable) ArrayPointable.FACTORY.createPointable(); final SequenceBuilder sb = new SequenceBuilder(); final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage(); return new AbstractTaggedValueArgumentScalarEvaluator(args) { @Override protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException { TaggedValuePointable tvp = args[0]; TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class); tvp.getValue(sp); abvs.reset(); sb.reset(abvs); int size = sp.getEntryCount(); <START> for (int i = 0; i < size; i++) { <END> sp.getEntry(i, tempTvp); if (tempTvp.getTag() == ValueTag.ARRAY_TAG) { flatten(tempTvp, ap); } else { try { sb.addItem(tempTvp); } catch (IOException e) { throw new SystemException(ErrorCode.SYSE0001, e); } } } try { sb.finish(); result.set(abvs); } catch (IOException e) { throw new SystemException(ErrorCode.SYSE0001, e); } } public void flatten(TaggedValuePointable tvp, ArrayPointable ap) throws SystemException { TaggedValuePointable tvp1 = ppool.takeOne(TaggedValuePointable.class); tvp.getValue(ap); int size = ap.getEntryCount(); for (int i = 0; i < size; i++) { ap.getEntry(i, tvp1); if (tvp1.getTag() == ValueTag.ARRAY_TAG) { flatten(tvp1, ap1); } else { try { sb.addItem(tvp1); } catch (IOException e) { throw new SystemException(ErrorCode.SYSE0001, e); } } } } }; }</code><technical_language>call flatten initial argument instead of looping sequence</technical_language>

Target:
protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) throws AlgebricksException { final SequencePointable sp = (SequencePointable) SequencePointable.FACTORY.createPointable(); final SequenceBuilder sb = new SequenceBuilder(); final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage(); return new AbstractTaggedValueArgumentScalarEvaluator(args) { @Override protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException { abvs.reset(); sb.reset(abvs); TaggedValuePointable tvp = args[0]; if (tvp.getTag() == ValueTag.SEQUENCE_TAG) { TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class); tvp.getValue(sp); int size = sp.getEntryCount(); for (int i = 0; i < size; i++) { sp.getEntry(i, tempTvp); flatten(tempTvp); } ppool.giveBack(tempTvp); } else { flatten(tvp); } try { sb.finish(); result.set(abvs); } catch (IOException e) { throw new SystemException(ErrorCode.SYSE0001, e); } } public void loopInsideArray(TaggedValuePointable tvp) throws SystemException { TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class); ArrayPointable ap = ppool.takeOne(ArrayPointable.class); tvp.getValue(ap); int size = ap.getEntryCount(); for (int i = 0; i < size; i++) { ap.getEntry(i, tempTvp); flatten(tempTvp); } ppool.giveBack(tempTvp); ppool.giveBack(ap); } public void flatten(TaggedValuePointable tvp) throws SystemException { if (tvp.getTag() == ValueTag.ARRAY_TAG) { loopInsideArray(tvp); } else { try { sb.addItem(tvp); } catch (IOException e) { throw new SystemException(ErrorCode.SYSE0001, e); } } } }; }