I need to be able to use union/union all/except from NHibernate and I've been trying to see what it would take to support this in NHibernate.
So far I've made a proof-of-concept (at
https://github.com/dmitryvk/nhibernate-core/commit/869443d861232b8c15f150c7e597e5bcc7ca7863) which seems to support some basic trivial cases (which are added to tests).
Basically, what I do is the following:
1) HQL parser allows UNION at the top-level, yielding AST such as the following (using s-expression notation):
(UNION
(QUERY ...)
(QUERY ...))
2) HqlSqlWalker and SqlGenerator also allow UNION at the top-level
3) New HQL AST node is added for UNION
I'd like to have this code reviewed and receive some feedback about this proof-of-concept implementation. What's missing in it? Am I in the right direction? Is there a documentation for how NHibernate generates SQL query (I'm having trouble navigating around HqlSqlWalker.ProcessQuery(), FormClauses, FormElements and so on)?