class RowsTransformer {

    public static Iterable<Row> toRowsIterable(TransactionContext txnCtx,
                                               InputFactory inputFactory,
                                               ReferenceResolver<?> referenceResolver,
                                               RoutedCollectPhase collectPhase,
                                               Iterable<?> iterable) {
        return toRowsIterable(txnCtx, inputFactory, referenceResolver, collectPhase, iterable, true);
    }

    @SuppressWarnings({"unchecked", "rawtypes"})
    public static Iterable<Row> toRowsIterable(TransactionContext txnCtx,
                                               InputFactory inputFactory,
                                               ReferenceResolver<?> referenceResolver,
                                               RoutedCollectPhase collectPhase,
                                               Iterable<?> iterable,
                                               boolean sort) {<FILL_FUNCTION_BODY>}

    public static Iterable<Row> sortRows(Iterable<Object[]> rows, RoutedCollectPhase collectPhase) {
        List<Object[]> objects = Lists.of(rows);
        Comparator<Object[]> ordering = OrderingByPosition.arrayOrdering(collectPhase);
        objects.sort(ordering);
        return Lists.mapLazy(objects, Buckets.arrayToSharedRow());
    }
}

        if (!WhereClause.canMatch(collectPhase.where())) {
            return Collections.emptyList();
        }
        InputFactory.Context ctx = inputFactory.ctxForRefs(txnCtx, referenceResolver);
        ctx.add(collectPhase.toCollect());
        OrderBy orderBy = collectPhase.orderBy();
        if (orderBy != null) {
            for (Symbol symbol : orderBy.orderBySymbols()) {
                ctx.add(symbol);
            }
        }

        ValueAndInputRow<Object> inputRow = new ValueAndInputRow<>(ctx.topLevelInputs(), ctx.expressions());
        assert DataTypes.BOOLEAN.equals(collectPhase.where().valueType()) :
            "whereClause.query() must be of type " + DataTypes.BOOLEAN;

        Predicate<Row> predicate = InputCondition.asPredicate(ctx.add(collectPhase.where()));

        if (sort == false || orderBy == null) {
            return () -> StreamSupport.stream((Spliterator<Object>) iterable.spliterator(), false)
                .map(inputRow)
                .filter(predicate)
                .iterator();
        }
        ArrayList<Object[]> items = new ArrayList<>();
        for (var item : iterable) {
            var row = inputRow.apply(item);
            if (predicate.test(row)) {
                items.add(row.materialize());
            }
        }
        items.sort(OrderingByPosition.arrayOrdering(collectPhase));
        return Lists.mapLazy(items, Buckets.arrayToSharedRow());
    
<no_super_class>