使用Hue在Hive中进行多行列注释

时间:2017-06-30 10:24:47

标签: hadoop hive hue

我知道如何使用Hue在Hive中添加列注释。我特别希望评论显示在 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中表格的视图:

View of the metadata of "table_test" in Hue

如您所见,评论没有换行符。无论评论多长时间,它仍然会添加在一行中。

要在 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.'

" table_test"的元数据视图在Hue尝试撰写多行评论时:

如果您查看第6行,您可以看到 Hue (或Hive)将其作为评论解释为新列。所以现在我没有7列,而是有8列。

您知道是否可以对 Hue 中显示的列进行多行注释?

1 个答案:

答案 0 :(得分:1)

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

演示

android:Theme.Material.Light.NoActionBar

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 
;

Metastore看起来不错

+----------------------------------------------------------------+
|                         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')                        |
+----------------------------------------------------------------+

enter image description here