HIVE 查询显示列名 及 行转列显示
2013-06-05 23:44 java20130722 阅读(740) 评论(0) 编辑 收藏 举报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
开启行转列功能后, 每一行都已列显示, 值前面都加上列名, 方便问题查找!