我创建了一个Hive表,我们在每个变量的“注释”字段中添加了一些描述,如下所示:
spark.sql("create table test_comment (col string comment 'col comment') comment 'hello world table comment ' ")
spark.sql("describe test_comment").show()
+--------+---------+-----------+
|col_name|data_type| comment|
+--------+---------+-----------+
| col| string|col comment|
+--------+---------+-----------+
一切都很好,我们在变量"col“的逗号字段中看到了注释”col注释“。
现在,当我在这个表上创建一个视图时,“注释”字段不会传播到视图中,“注释”列是空的:
spark.sql("""create view test_comment_view as select * from test_comment""")
spark.sql("describe test_comment_view")
+--------+---------+-------+
|col_name|data_type|comment|
+--------+---------+-------+
| col| string| null|
+--------+---------+-------+
在创建视图时,是否存在保留注释字段值的方法?这种“特色”的原因是什么?
我正在使用:
Hadoop 2.6.0-cdh5.8.0
蜂箱1.1.0-cdh5.8.0
火花2.1.0.云量1
发布于 2018-03-07 05:54:34
我观察到的是,即使在从另一个表创建表时,注释也不会被继承。看来这是默认行为。
create table t1 like another_table
desc t1 //includes comments
+-----------+------------+------------------+--+
| col_name | data_type | comment |
+-----------+------------+------------------+--+
| id | int | new employee id |
| name | string | employee name |
+-----------+------------+------------------+--+
create table t1 as select * from another_table
desc t1 //excludes comments
+-----------+------------+----------+--+
| col_name | data_type | comment |
+-----------+------------+----------+--+
| id | int | |
| name | string | |
+-----------+------------+----------+--+
但有个解决办法。在创建视图时,可以使用注释指定单独的列。
create view v2(id2 comment 'vemp id', name2 comment 'vemp name') as select * from another_table;
+-----------+------------+------------+--+
| col_name | data_type | comment |
+-----------+------------+------------+--+
| id2 | int | vemp id |
| name2 | string | vemp name |
+-----------+------------+------------+--+
https://stackoverflow.com/questions/49152806
复制