2017-11-17 161 views
0

與此問題類似:Is there a way to toggle expanded table formatting mode in PrestoDB cli?在HIVE CLI中啓用擴展表格格式?

有沒有辦法在HIVE中啓用擴展表格格式化模式?在開始一個大型查詢工作之前,我想在寬表中檢查幾條記錄。

複製從另一個問題的例子:

擴展表格格式之前:

select * from sometable; 

id | time |  humanize_time    | value 
----+-------+---------------------------------+------- 
    1 | 09:30 | Early Morning - (9.30 am)  | 570 
    2 | 11:30 | Late Morning - (11.30 am)  | 690 
    3 | 13:30 | Early Afternoon - (1.30pm)  | 810 
    4 | 15:30 | Late Afternoon - (3.30 pm)  | 930 
(4 rows) 

後:

select * from sometable; 

-[ RECORD 1 ]-+--------------------------- 
id   | 1 
time   | 09:30 
humanize_time | Early Morning - (9.30 am) 
value   | 570 
-[ RECORD 2 ]-+--------------------------- 
id   | 2 
time   | 11:30 
humanize_time | Late Morning - (11.30 am) 
value   | 690 
-[ RECORD 3 ]-+--------------------------- 
id   | 3 
time   | 13:30 
humanize_time | Early Afternoon - (1.30pm) 
value   | 810 
-[ RECORD 4 ]-+--------------------------- 
id   | 4 
time   | 15:30 
humanize_time | Late Afternoon - (3.30 pm) 
value   | 930 

回答

1

您可以使用CROSS JOINCASEUNION ALL的組合。

select 
    c.col, 
    case c.col 
    when 'id' then id 
    when 'time' then time 
    when 'humanize_time' then humanize_time 
    when 'value' then value 
    end as data 
from sometable t 
cross join 
(
    select 'id' as col 
    union all select 'time' as col 
    union all select 'humanize_time' as col 
    union all select 'value' as col 
) c ORDER BY id; 
+0

謝謝,但這並不完全符合我的要求。我有一張非常寬的桌子,所以根據我的需要調整您的查詢會非常麻煩。在postgresql中,您可以鍵入'\ x'來打開擴展顯示。我希望有類似的方法,但目前HIVE似乎並不存在這樣的特徵。 – pault