1

类似于这个问题:有没有办法在 PrestoDB 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
4

1 回答 1

1

您可以使用CROSS JOIN,CASE和的组合UNION 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;
于 2017-11-18T16:32:38.340 回答