some refactor for outputSchema wrapping

This refactor is useful for other udfs that need to use similar wrapping.