The issue exists in Hive-2.1. In Hive-1.2 the query works fine with cbo enabled:
STEPS TO REPRODUCE:
The issue seems to be because of the incorrect query plan. In the plan we can see:
predicate:(a1 is not null and b1 is not null)
which does not look correct. As a result, it is filtering out all the rows is any column mentioned in the COALESCE has null value.
Please find the query plan below:
This happens only if join is inner type, otherwise HiveJoinAddNotRule which creates this problem is skipped.