List<String> names = union.getSelectVarNames();
List<ColumnVar> vars = union.appendVars(new ArrayList<ColumnVar>());
SqlQueryBuilder subquery = query.subquery();
for (FromItem item : union.getUnion()) {
for (int i = 0, n = names.size(); i < n; i++) {
ColumnVar var = item.getVar(names.get(i));
SqlExprBuilder select = subquery.select();
if (var == null) {
select.appendNull();
}
else if (var.isImplied()) {
select.appendNumeric(vf.getInternalId(var.getValue()));
}
else {
select.column(var.getAlias(), var.getColumn());
}
select.as(vars.get(i).getColumn());
}
from(subquery, item);
subquery = subquery.union();