1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Batch下,强制改写 第一层求distinct值和非distinct agg function的值 第二层求distinct agg function的值 示例: select color,count(distinct id),count(*) from t group by color 改写 select color,count(id),min(cnt) from ( select color,id,count(*) filter (where $e = 2) as cnt from ( select color,id,1 as $e from t -- for distinct id union all select color,null as id, 2 as $e from t -- for count(*) ) group by color,id,$e ) group by color Stream下,必要条件 必须是支持的agg function avg/count/min/max/sum/first_value/last_value/concat_agg/single_value table.optimizer.distinct-agg.split.enabled开启(默认关闭) 示例: select color,count(distinct id),count(*) from t group by color 改写 select color,sum(dcnt),sum(cnt) from ( select color,count(distinct id) as dcnt,count(*) as cnt from t group by color,mod(hash_code(id),1024) ) group by color
|