Hive Union Group By Error

In the following query, I am trying to count up the distinct, and total occurences of the column "primary" and and summarise this for each column. I have two source tables, which contain similar