Hive.GROUPING SETS有BUG?

       隨着Hive 0.10版的發佈,GROUPING SETS出現了,並提供了ROLL UP和CUBE這兩個特殊場景的子句,真是喜聞樂見的特性啊。
       不過最近在寫兩個HQL查詢腳本的時候,我發現,對表達式進行GROUP BY並用GROUPING SETS自定義這些表達式的分組方式時,GROUPING SETS好像會出現解析異常:
FAILED: ParseException line 66:14 missing ) at ',' near ')' in subquery source
line 66:80 mismatched input ',' expecting ) near ')' in subquery source

       以下是GROUP子句的片段:
group by t1.my_month, t1.product, t1.usr_type, if(t3.earliest_logtime_monthly = '20140101', 'new_usr', 'old_usr'), if(t2.CTClass = 105, t1.ipcountry, t1.ipprovince), t1.ChannelID

grouping sets  ((t1.my_month, t1.usr_type, t1.ChannelID), (t1.my_month, t1.product, t1.usr_type, t1.ChannelID), (t1.my_month, if(t3.earliest_logtime_monthly = '20140101', 'new_usr', 'old_usr'), t1.ChannelID), (t1.my_month, t1.product, if(t3.earliest_logtime_monthly = '20140101', 'new_usr', 'old_usr'), t1.ChannelID), (t1.my_month, if(t2.Dim_CityClass = 105, t1.ipcountry, t1.ipprovince), t1.ChannelID), (t1.my_month, t1.product, if(t2.CTClass = 105, t1.ipcountry, t1.ipprovince), t1.ChannelID))

       去掉GROUPING SETS子句後腳本就正常,而且看了半天也沒看出來GROUPING SETS子句裏這樣的組合方式有什麼邏輯錯誤。
       理論上,表達式和字段應該一樣,可以出現在GROUPING SETS子句裏並進行任意組合,對一些表達式的實測結果也表明GROUPING SETS裏確實是支持表達式的。

       這樣的情況,使我懷疑GROUPING SETS子句的括號匹配邏輯沒做得很完善,導致了括號配對拋出異常。不過,具體的問題,還是需要通過研究一下Hive實現源碼來進一步確定這到底是不是一個BUG。


--------------------------------------------------------------------------------------------------------------------

2014-04-28

       今天發現,好像是限定性名稱的原因呢!就和Java的switch...case的case子句一樣,case子句裏的枚舉值不能用限定性名稱(EnumType.EnumValue1),只能用非限定性名稱(EnumValue1)!難道grouping sets的Java實現涉及到switch...case子句?有待研究。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章