MODE-1809 Corrected the processing of set queries, including unions

The code was sorting and then removing duplicates in the tuples, but during pre-processing and planning, the internal structure of the tuples changed for certain kinds of queries (like unions with join) to add in node location information as additional columns. The removal of duplicates, however, was still incorrectly basing its access of the tuple values upon the smaller/earlier tuple structure. This cause various kinds of ClassCastExceptions.

Added a test case that replicated the originally reported problem, which after the fix now passes.