hive 行转列显示

首先查看一个sql

1、首先存在一个数据表tmp

CREATE  TABLE tmp(
  platform string,
  channel string,
  chan_value string,
  uid string,
  host int,
  logtime string,
  bd_source string,
  action string,
  refer string,
  back_url string,
  browser string,
  mobile string,
  server_ip string,
  ip string,
  url string,
  post string,
  handle_time string,
  logday string)

2、查看这个表的数据

hive> select * from tmp limit 2;
OK
adr    partner    touch.qunar.com    -    4    00:00:05    -    SgTrainStation    http://touch.qunar.com/baiduTrain.jsp?bd_source=alading_webapp        android    mozilla/5.0 (linux; android 4.4.2; hw-huawei p7-l09 build/huaweip7-l09) applewebkit/537.36 (khtml, like gecko) version/4.0 mobile safari/537.36    192.168.24.222    119.0.34.213    /SgTrainStation?keyword=上&_=1416153604205    -    1    20141117
adr    partner    touch.qunar.com    -    0    00:00:05    -    SgTrainStation    http://touch.qunar.com/baiduTrain.jsp?bd_source=alading_webapp        android    mozilla/5.0 (linux; android 4.4.2; hw-huawei p7-l09 build/huaweip7-l09) applewebkit/537.36 (khtml, like gecko) version/4.0 mobile safari/537.36    192.168.24.222    119.0.34.213    /SgTrainStation?keyword=上&_=1416153604205    -    1    20141117
Time taken: 2.549 seconds, Fetched: 2 row(s)

这个数据十分不可读,那么就希望能格式化这些数据

3、set hive.cli.print.header=true; // 打印列名

hive> select * from tmp limit 2;
OK
platform    channel    chan_value    uid    host    logtime    bd_source    action    refer    back_url    browser    mobile    server_ip    ip    url    post    handle_time    logday
adr    partner    touch.qunar.com    -    4    00:00:05    -    SgTrainStation    http://touch.qunar.com/baiduTrain.jsp?bd_source=alading_webapp        android    mozilla/5.0 (linux; android 4.4.2; hw-huawei p7-l09 build/huaweip7-l09) applewebkit/537.36 (khtml, like gecko) version/4.0 mobile safari/537.36    192.168.24.222    119.0.34.213    /SgTrainStation?keyword=上&_=1416153604205    -    1    20141117
adr    partner    touch.qunar.com    -    0    00:00:05    -    SgTrainStation    http://touch.qunar.com/baiduTrain.jsp?bd_source=alading_webapp        android    mozilla/5.0 (linux; android 4.4.2; hw-huawei p7-l09 build/huaweip7-l09) applewebkit/537.36 (khtml, like gecko) version/4.0 mobile safari/537.36    192.168.24.222    119.0.34.213    /SgTrainStation?keyword=上&_=1416153604205    -    1    20141117
Time taken: 0.218 seconds, Fetched: 2 row(s)

上面增加了列名

4、set hive.cli.print.row.to.vertical=true; // 开启行转列功能, 前提必须开启打印列名功能

5、set hive.cli.print.row.to.vertical.num=1; // 设置每行显示的列数

------------------这两步暂时没有生效,是xml文件设置的问题---------

时间: 2024-08-11 01:14:47

hive 行转列显示的相关文章

hive行转列

一.问题 hive如何将 a 1,2,3 b 4,7 c 5 转化成为: a 1 a 2 a 3 b 4 b 7 c 5 二.原始数据 cat row_column.txt a 1,2,3 b 4,7 c 5 三.解决方案 3.1 遍历每一列 3.1.1 创建表 -- 创建表 create table tmp.row_column ( col1 string, col3 string ) row format delimited fields terminated by '\t' stored

hive 行转列 并添加虚列

select regexp_extract(a.col2,'(phonenum=\")(.*?)\"',2) user_device, regexp_extract(a.col13,'(imsicode=\")(.*?)\"',2) imsi, regexp_extract(a.col12,'(imeicode=\")(.*?)\"',2) imei, call_log from (select * from ods_sso_dislocatio

Mysql或者Hive数据行变成列

对于mysql /  hive 再进行统计的时候如果需要行变成列,可以使用函数 CASE 字段a WHEN 值b THEN c [WHEN d THEN e]* [ELSE f] END 当字段a=值b时,返回c(如果是字段的话则代表该字段的值,也可以是一个固定值 加单引号就可以):当a=d时,返回e,否则返回f. 如: 数据表结构:(举例说明,id有重复的) select id ,sum(CASE action when 'article' then count else 0 end) as

Easyui Datagrid 修改显示行号列宽度

EasyUI中Datagrid的第一列显示行号,可是如果数据量大的的时候,显示行号的那一列数据会显示不完全的. 可以通过修改Datagrid的样式来解决这个问题,在样式中加入下面这个样式,就可以自己修改显示行号列的宽度了 .datagrid-header-rownumber,.datagrid-cell-rownumber{ width:40px; }

hive行转多列LATERAL VIEW explode

源表(table1)数据{A:string B:array<BIGINT> C:string} A                         B                                C 190     [1030,1031,1032,1033,1190]      select id191     [1030,1031,1032,1033,1190]      select id 希望的结果是: 190    1030  select id 190    103

SQL查询语句行转列横向显示

SQL查询语句行转列横向显示 2011-03-15 10:00:14|  分类: sql |  标签:resource   |举报 |字号大中小 订阅 在SQL查询语句行转列横向显示中access中没有CASE,要用IIF代替 select  iif(sex= '1 ', '男 ', '女 ')  from  tablename 示例1: select country, sum(case when type='A' then money end) as A, sum(case when type

hive udtf 输入一列返回多行多列

之前说到了hive udf,见https://blog.csdn.net/liu82327114/article/details/80670415 UDTF(User-Defined Table-Generating Functions) 用来解决 输入一行输出多行(On-to-many maping) 的需求. 继承org.apache.hadoop.hive.ql.udf.generic.GenericUDTF,实现initialize, process, close三个方法. UDTF首先

datatbles修改显示样式(修改行、列背景色,字体,隔行换色)

这里主要介绍两个函数:aoColumnDefs和createdRow datatables的使用方式非常简单,自行查阅资料,直接上代码: var t;t = $("#accountTbl").DataTable({ searching: true, processing: true, dom: "<'row'<'col-sm-12'tr>>\n\t\t\t<'row'<'col-sm-12 col-md-5'i><'col-sm

Hive之列转行,行转列

测试数据 hive> select * from col_lie limit 10; OK col_lie.user_id col_lie.order_id 104399 1715131 104399 2105395 104399 1758844 104399 981085 104399 2444143 104399 1458638 104399 968412 104400 1609001 104400 2986088 104400 1795054 把相同user_id的order_id按照逗号