在 Hive table 上创建视图:每个变量的注释都丢失了
create view on Hive table: comment for each variable are lost
我创建了一个 Hive table,我们在 "comment" 字段中为每个变量添加了一些描述,如下所示:
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 comment"
现在,当我在此 table 上创建视图时,"comment" 字段不会传播到视图并且 "comment" 列为空:
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|
+--------+---------+-------+
有没有办法在创建视图时保留评论字段的值?这个"feature"是什么原因?
我正在使用:
Hadoop 2.6.0-cdh5.8.0
配置单元 1.1.0-cdh5.8.0
Spark 2.1.0.cloudera1
我观察到的是,即使在从另一个 table 创建 table 时,注释也不会被继承。看起来这是默认行为。
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 |
+-----------+------------+------------+--+
我创建了一个 Hive table,我们在 "comment" 字段中为每个变量添加了一些描述,如下所示:
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 comment"现在,当我在此 table 上创建视图时,"comment" 字段不会传播到视图并且 "comment" 列为空:
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|
+--------+---------+-------+
有没有办法在创建视图时保留评论字段的值?这个"feature"是什么原因?
我正在使用:
Hadoop 2.6.0-cdh5.8.0
配置单元 1.1.0-cdh5.8.0
Spark 2.1.0.cloudera1
我观察到的是,即使在从另一个 table 创建 table 时,注释也不会被继承。看起来这是默认行为。
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 |
+-----------+------------+------------+--+