HIVE 查詢顯示列名 及 行轉列顯示
阿新 • • 發佈:2019-01-01
hive預設查詢不會顯示列名, 當一個表字段比較多的時候,往往看不出值與列之間的對應關係,對日常查錯及定位問題帶來不便,應同事要求,看了HIVE CLI原始碼,做了下些許調整, 加入列頭列印及行轉列顯示功能
未開啟行轉列功能之前:
- hive>
- >
- > select * from example_table where dt='2012-03-31-02' limit 2;
- OK
- 1333133185 0cf49387a23d9cec25da3d76d6988546 3CD5E9A1721861AE6688260ED26206C2 guanwang 1.1 3d3b0a5eca816ba47fc270967953f881 192.168.1.2.13331317500.0 NA 031/Mar/2012:02:46:44 +080 222.71.121.111 2012-03-31-02
- 1333133632 0cf49387a23d9cec25da3d76d6988546 3CD5E9A1721861AE6688260ED26206C2 10002 1.1 e4eec776b973366be21518b709486f3c 110.6.100.57.1332909301867.6 NA 0 31/Mar/2012:02:54:16 +080 110.6.74.219 2012-03-31-02
- Time taken: 0.62 seconds
開啟行轉列功能之後:
- set hive.cli.print.header=true; // 列印列名
- set hive.cli.print.row.to.vertical=true; // 開啟行轉列功能, 前提必須開啟列印列名功能
- set hive.cli.print.row.to.vertical.num=1; // 設定每行顯示的列數
- > select * from example_table where pt='2012-03-31-02' limit 2;
- OK
- datetime col_1 col_2 channel version pcs cookie trac new time ip
- datetime=1333133185
- col_1=0cf49387a23d9cec25da3d76d6988546
- clo_2=3CD5E9A1721861AE6688260ED26206C2
- channel=test_name1
- version=1.1
- pcs=3d3b0a5eca816ba47fc270967953f881
- cookie=192.168.1.2.13331317500.0
- trac=NA
- new=0
- time=31/Mar/2012:02:46:44 +080
- ip=222.71.121.111
- -------------------------Gorgeous-split-line-----------------------
- datetime=1333133632
- col_1=0cf49387a23d9cec25da3d76d6988546
- col_2=3CD5E9A1721861AE6688260ED26206C2
- channel=test_name2
- version=1.1
- pcs=e4eec776b973366be21518b709486f3c
- cookie=110.6.100.57.1332909301867.6
- trac=NA
- new=0
- time=31/Mar/2012:02:54:16 +080
- ip=110.6.74.219
- --------------------------Gorgeous-split-line-----------------------
- Time taken: 0.799 seconds
開啟行轉列功能後, 每一行都已列顯示, 值前面都加上列名, 方便問題查詢!