Fix generation of union types

Currently generation of union types is not correctly handled and can result in nested union types in the shape of e.g. `union<string,union<int,string,union<tinyint,binary>>` depending on the input data.
This pull request fixes this issue by computing the least upper bound for the types that are part of union types.