HIVEQL:查询仅列出视图



是否有蜂巢查询仅列出特定数据库中可用的视图。

在mysql中,我认为的查询如下:

SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_TYPE LIKE 'VIEW' AND TABLE_SCHEMA LIKE 'database_name';

我想要hiveql的东西。

目前没有INFORMATION_SCHEMA实现。

有一个开放的jira,您可以在以下链接上查看:

https://issues.apache.org/jira/browse/hive-1010

但是,如果使用Derby MySQL Server配置了Hive Metastore,则可以访问所需的信息。

可以在:

上找到配置Hive Metastore的不同方法

http://www.thecloudavenue.com/2013/11/differentwaysofconfiguringhivemetastore.html

这是Metastore的详细E/R图:

https://issues.apache.org/jira/secure/attachment/12471108/hivemetastore.pdf

配置此Metastore后,您可以通过以下查询获得所需的信息:

SELECT * from TBLS where TBLS_TYPE = "VIEW"

如果您像我一样被hive的hive像我一样,无法使用SHOW VIEWS,然后使用以下脚本

export db=$1
tables=`hive -e "use $db; show tables;"`
show_table_command=''
for table in $tables; do
  show_table_command="$show_table_command SHOW CREATE TABLE ${db}.${table};"
done
hive -e "$show_table_command" > show_table
sed_command="s/$db.//g"
cat show_table | grep "CREATE VIEW" | cut -d" " -f3 | sed 's/`//g' | sed ${sed_command} > all_views

从AS sh find_views.sh dbname运行此代码。现在表all_views具有视图列表。

您还可以使用相同的技术来通过更换"创建视图"为"创建表"或"创建外部表"并相应地调整sedcut语句。

SHOW VIEWS [in/from <dbName>] [<pattern>]

(非常喜欢show table命令)可以通过https://issues.apache.org/jira/browse/browse/hive-14558补丁程序进行跟踪,并且有可能会降落在Hive 2.0中。

最新更新