Source:
<code>private PlannerResult planWithBindableConvention( final SqlExplain explain, final RelRoot root, final HttpServletRequest request, final AuthenticationResult authenticationResult ) throws RelConversionException { BindableRel bindableRel = (BindableRel) planner.transform( Rules.BINDABLE_CONVENTION_RULES, planner.getEmptyTraitSet() .replace(BindableConvention.INSTANCE) .plus(root.collation), root.rel ); if (!root.isRefTrivial()) { final List<RexNode> projects = new ArrayList<>(); final RexBuilder rexBuilder = bindableRel.getCluster().getRexBuilder(); for (int field : Pair.left(root.fields)) { projects.add(rexBuilder.makeInputRef(bindableRel, field)); } bindableRel = new Bindables.BindableProject( bindableRel.getCluster(), bindableRel.getTraitSet(), bindableRel, projects, root.validatedRowType ); } Access accessResult = authorizeBindableRel(bindableRel, plannerContext, request, authenticationResult); if (!accessResult.isAllowed()) { throw new ForbiddenException(accessResult.toString()); } if (explain != null) { return planExplanation(bindableRel, explain); } else { final BindableRel theRel = bindableRel; final DataContext dataContext = plannerContext.createDataContext((JavaTypeFactory) planner.getTypeFactory()); final Supplier<Sequence<Object[]>> resultsSupplier = () -> new BaseSequence<>( new BaseSequence.IteratorMaker<Object[], CloseableEnumerableIterator>() { @Override public CloseableEnumerableIterator make() { final Enumerable enumerable = theRel.bind(dataContext); final Enumerator enumerator = enumerable.enumerator(); <START> return new CloseableEnumerableIterator(new Iterator<Object[]>() <END> { @Override public boolean hasNext() { return enumerator.moveNext(); } @Override public Object[] next() { return (Object[]) enumerator.current(); } }, () -> enumerator.close()); } @Override public void cleanup(CloseableEnumerableIterator iterFromMake) { iterFromMake.close(); } } ); return new PlannerResult(resultsSupplier, root.validatedRowType); } }</code><technical_language>CloseableEnumerableIterator is needed. Please Sequences.withBaggage()</technical_language>

Target:
private PlannerResult planWithBindableConvention( final SqlExplain explain, final RelRoot root, final HttpServletRequest request, final AuthenticationResult authenticationResult ) throws RelConversionException { BindableRel bindableRel = (BindableRel) planner.transform( Rules.BINDABLE_CONVENTION_RULES, planner.getEmptyTraitSet() .replace(BindableConvention.INSTANCE) .plus(root.collation), root.rel ); if (!root.isRefTrivial()) { final List<RexNode> projects = new ArrayList<>(); final RexBuilder rexBuilder = bindableRel.getCluster().getRexBuilder(); for (int field : Pair.left(root.fields)) { projects.add(rexBuilder.makeInputRef(bindableRel, field)); } bindableRel = new Bindables.BindableProject( bindableRel.getCluster(), bindableRel.getTraitSet(), bindableRel, projects, root.validatedRowType ); } Access accessResult = authorizeBindableRel(bindableRel, plannerContext, request, authenticationResult); if (!accessResult.isAllowed()) { throw new ForbiddenException(accessResult.toString()); } if (explain != null) { return planExplanation(bindableRel, explain); } else { final BindableRel theRel = bindableRel; final DataContext dataContext = plannerContext.createDataContext((JavaTypeFactory) planner.getTypeFactory()); final Supplier<Sequence<Object[]>> resultsSupplier = () -> { final Enumerable enumerable = theRel.bind(dataContext); final Enumerator enumerator = enumerable.enumerator(); return Sequences.withBaggage(new BaseSequence<>( new BaseSequence.IteratorMaker<Object[], EnumeratorIterator<Object[]>>() { @Override public EnumeratorIterator make() { return new EnumeratorIterator(new Iterator<Object[]>() { @Override public boolean hasNext() { return enumerator.moveNext(); } @Override public Object[] next() { return (Object[]) enumerator.current(); } }); } @Override public void cleanup(EnumeratorIterator iterFromMake) { } } ), () -> enumerator.close()); }; return new PlannerResult(resultsSupplier, root.validatedRowType); } }