DRILL-7502: Invalid codegen for typeof() with UNION
Also fixes DRILL-6362: typeof() reports NULL for primitive
columns with a NULL value.
typeof() is meant to return "NULL" if a UNION has a NULL
value, but the column type when known, such as for non-UNION
columns.
Also fixes DRILL-7499: sqltypeof() function with an array returns
"ARRAY", not type. This was due to treating REPEATED like LIST.
Handling of the Union vector in code gen is problematic
with about three special cases. Existing code handled two
of the cases. This change handles the third case.
Figuring out the change required poking around quite a bit
of unclear code. Added comments and restructuring to make
that code a bit more clear.
The fix modified code gen for the Union Holder. It can now
"go back in time" to add the union reader at the point we
need it.
closes #1945