Rebased HIVE-2416, Multiple distinct function to support hive.groupby.skewindata optimization