<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def OrderFields(fields):
 """ Transformation factory to reorder fields in a data stream. :param fields: :return: callable """

    fields = list(fields)

    @use_context
    @use_raw_input
    def _OrderFields(context, row):
        nonlocal fields
        context.setdefault("remaining", None)
        if not context.output_type:
            context.remaining = list(sorted(set(context.get_input_fields()) - set(fields)))
            context.set_output_fields(fields + context.remaining)

        yield tuple(row.get(field) for field in context.get_output_fields())

    return _OrderFields