ModeShape/modeshape — pull request #957 by rhauch (2013-09-25 14:36:41+00:00)
Title: MODE-2057 Corrected behavior of UNION with dissimilar queries.

Even though ModeShape should be able to create a UNION of two queries that have the same effective result set, the fact that the internal project operation in the query plan did not reformat the tuples meant that the tuples on each side of the UNION had different structure. Thus, such queries would either fail during execution (if certain columns were used higher in the query plan), an IndexOutOfBoundsException when accessing the result set, or simply result set with values in the wrong columns.

The fix is to for the set operation (including UNION, INTERSECT and EXCEPT) to reformat the incoming tuples if the structure on each side of the operation is different or not compatible. The planning for the restructuring can be done at query planning time, but if needed the actual restructuring of the tuples can only be done at execution time. Thus, in such cases there will be additional work required.

The new tests to verify the behavior pass with these changes, and all prior query tests also pass.