SpagoBI不支持動態指定指標的緣由分析

第一步:使用SQL查詢,某日期區間,某幾個頻道的接觸度數組

select  函數

    count(userid) as ooc,test

    channelname as channelname,select

    dt as dtchannel

from tvlog_test.tvlog_tcl數據

where dt between '2015-09-01' and '2015-09-05'查詢

and instr('["CCTV-5體育", "CCTV-6電影", "CCTV-10科教"]', channelname) <> 0存儲過程

group by dt, channelname;co


Result:cas

91885   CCTV-5體育      2015-09-01

155304  CCTV-6電影      2015-09-01

72961   CCTV-10科教     2015-09-02

82379   CCTV-5體育      2015-09-03

22599   CCTV-6電影      2015-09-03

74714   CCTV-10科教     2015-09-04

129171  CCTV-5體育      2015-09-05

191576  CCTV-6電影      2015-09-05

68713   CCTV-10科教     2015-09-01

85925   CCTV-5體育      2015-09-02

166430  CCTV-6電影      2015-09-02

195039  CCTV-10科教     2015-09-03

107881  CCTV-5體育      2015-09-04

163962  CCTV-6電影      2015-09-04

71486   CCTV-10科教     2015-09-05


第二步:將數據按日期進行合併

注意, collect_set這個UDAF的參數不支持count

select 

    collect_set(t1.ooc),

    collect_set(t1.channelname),

    t1.dt

from

(select  

    count(userid) as ooc,

    channelname as channelname,

    dt as dt

from tvlog_test.tvlog_tcl

where dt between '2015-09-01' and '2015-09-05'

and instr('["CCTV-5體育", "CCTV-6電影", "CCTV-10科教"]', channelname) <> 0

group by dt, channelname) t1

group by t1.dt;


Result:

[68713,91885,155304]    ["CCTV-10科教","CCTV-5體育","CCTV-6電影"]       2015-09-01

[195039,82379,22599]    ["CCTV-10科教","CCTV-5體育","CCTV-6電影"]       2015-09-03

[71486,129171,191576]   ["CCTV-10科教","CCTV-5體育","CCTV-6電影"]       2015-09-05

[72961,85925,166430]    ["CCTV-10科教","CCTV-5體育","CCTV-6電影"]       2015-09-02

[74714,107881,163962]   ["CCTV-10科教","CCTV-5體育","CCTV-6電影"]       2015-09-04


結論:

一、Hive沒辦法將數組轉成多列(列數不固定),使用UDTF不行,而且Hive也不支持存儲過程。

二、即便能夠轉成多列,也沒辦法定義別名,也就是不知道該列是對應哪一個列名

三、列數固定的話,能夠使用case when 語句行轉列或者編寫一個固定列的UDTF(第二種很差,若是2,3,4,5都有需求,那要編寫4個函數)

相關文章
相關標籤/搜索