HIVE 查询显示列名 及 行转列显示

hive默认查询不会显示列名, 当一个表字段比较多的时候,往往看不出值与列之间的对应关系,对日常查错及定位问题带来不便,应同事要求,看了HIVE CLI源码,做了下些许调整, 加入列头打印及行转列显示功能

未开启行转列功能之前:

  1. hive>
  2. >
  3. > select * from example_table where dt='2012-03-31-02' limit 2;
  4. OK
  5. 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
  6. 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
  7. Time taken: 0.62 seconds

开启行转列功能之后:

  1. set hive.cli.print.header=true; // 打印列名
  2. set hive.cli.print.row.to.vertical=true; // 开启行转列功能, 前提必须开启打印列名功能
  3. set hive.cli.print.row.to.vertical.num=1; // 设置每行显示的列数
  4. > select * from example_table where pt='2012-03-31-02' limit 2;
  5. OK
  6. datetime col_1 col_2 channel version pcs cookie trac new time ip
  7. datetime=1333133185
  8. col_1=0cf49387a23d9cec25da3d76d6988546
  9. clo_2=3CD5E9A1721861AE6688260ED26206C2
  10. channel=test_name1
  11. version=1.1
  12. pcs=3d3b0a5eca816ba47fc270967953f881
  13. cookie=192.168.1.2.13331317500.0
  14. trac=NA
  15. new=0
  16. time=31/Mar/2012:02:46:44 +080
  17. ip=222.71.121.111
  18. -------------------------Gorgeous-split-line-----------------------
  19. datetime=1333133632
  20. col_1=0cf49387a23d9cec25da3d76d6988546
  21. col_2=3CD5E9A1721861AE6688260ED26206C2
  22. channel=test_name2
  23. version=1.1
  24. pcs=e4eec776b973366be21518b709486f3c
  25. cookie=110.6.100.57.1332909301867.6
  26. trac=NA
  27. new=0
  28. time=31/Mar/2012:02:54:16 +080
  29. ip=110.6.74.219
  30. --------------------------Gorgeous-split-line-----------------------
  31. Time taken: 0.799 seconds

开启行转列功能后, 每一行都已列显示, 值前面都加上列名, 方便问题查找!

你可能感兴趣的:(Hive)