【问题标题】:Multi line column comment in Hive using HueHive 中使用 Hue 的多行列注释
【发布时间】:2017-06-30 10:24:47
【问题描述】:

我知道如何使用 Hue 在 Hive 中添加列 cmets。我特别希望评论在Hue中的几行上显示,因为它太长而无法在一行上阅读。

我创建了一个我在以前的 stackoverflow 帖子中找到的表作为示例:

 CREATE TABLE test_table(
   col1 INT COMMENT 'col1 one line comment',
   col2 STRING COMMENT 'col2 two lines comment',
   col3 STRING COMMENT 'col3 three lines comment',
   col4 STRING COMMENT 'col4 very long comment that is greater than 80 chars and is likely to spill into multiple lines',
   col5 STRING COMMENT 'col5 very long multi-line comment where each line is very long by itself and is likely to spill into multiple lines. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin in dolor nisl, sodales adipiscing tortor. Integer venenatis',
   col6 STRING COMMENT 'This comment has a very long single word ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvzxyz123 which will not fit in a line by itself for small column widths.',
   col7_NoComment STRING)
 COMMENT 'table comment two lines';

这是 Hue 中的表格视图:

如您所见,cmets 没有换行符。注释不管多长,还是加在一行里。

为了在 Hue 中将其分成多行,我考虑使用“\n”字符。这是修改第 6 列注释时关联查询的结果:

ALTER TABLE test_table CHANGE COLUMN col6 col6 STRING COMMENT 'This comment has a very long single word ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvzxyz123 \n Line break here because it will not fit in a single line.'

尝试编写多行注释时在 Hue 中查看“table_test”的元数据:

如果您查看第 6 行,您可以看到应该是注释的内容被 Hue(或 Hive)解释为新列。所以现在我有 8 列,而不是 7 列。

您知道是否可以为 Hue 中显示的列添加多行注释?

【问题讨论】:

标签: hadoop hive hue


【解决方案1】:

定义多行cmets没有问题。
这只是客户端工具(Hue、Hive CLI、Beeline 等)的显示问题。

演示

create table mytable 
(
    mycol int comment 'Hello!
My name is Inigo Montoya!
You killed my father, prepare to die!'
)

show create table 看起来不错

show create table mytable 
;

+----------------------------------------------------------------+
|                         createtab_stmt                         |
+----------------------------------------------------------------+
| CREATE TABLE `mytable`(                                        |
|   `mycol` int COMMENT 'Hello!                                  |
| My name is Inigo Montoya!                                      |
| You killed my father, prepare to die!')                        |
| ROW FORMAT SERDE                                               |
|   'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'         |
| STORED AS INPUTFORMAT                                          |
|   'org.apache.hadoop.mapred.TextInputFormat'                   |
| OUTPUTFORMAT                                                   |
|   'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' |
| LOCATION                                                       |
|   'file:/home/cloudera/local_db/mytable'                       |
| TBLPROPERTIES (                                                |
|   'COLUMN_STATS_ACCURATE'='{\"BASIC_STATS\":\"true\"}',        |
|   'numFiles'='0',                                              |
|   'numRows'='0',                                               |
|   'rawDataSize'='0',                                           |
|   'totalSize'='0',                                             |
|   'transient_lastDdlTime'='1498824282')                        |
+----------------------------------------------------------------+
  

元存储看起来不错

select  c.*

from            metastore.DBS           d

        join    metastore.TBLS          t
        
        on      t.db_id = d.db_id
        
        join    metastore.SDS           s
        
        on      s.sd_id = t.sd_id
        
        join    metastore.COLUMNS_V2    c
        
        on      c.cd_id = s.cd_id
        
where   d.name     = 'local_db'
    and t.tbl_name = 'mytable'         
;

【讨论】:

  • 感谢 Dudu Markovitz 的快速回复。但是,问题仍然存在:当我创建表 mytable 并在几行上发表您的评论时,Hive Metastore 通过 Hue 将其显示为“我的名字是 Inigo Montoya!” “你杀了我父亲,准备去死吧!”是列,而这些只是评论的一部分。
  • 这正是我所说的。这是客户端工具的显示问题。基础数据存储正确。
  • 是的,我意识到了这一点并试图改变我的答案,但我无法修改我的评论。很抱歉 :) 你知道如何解决这个问题吗?
  • 我怀疑有没有
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多