1

如何使用HiveQL语句在Hive中创建临时表?

 11 months ago
source link: https://www.51cto.com/article/755881.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如何使用HiveQL语句在Hive中创建临时表?

作者:黑马程序员 2023-05-26 16:40:22
临时表是Hive数据表的一种特殊形式,临时表只对当前会话可见,数据被存储在用户的临时目录,并在会话结束时删除。
75a50a875be3b096bcf388e4e84abf2a340e28.jpg

临时表是Hive数据表的一种特殊形式,临时表只对当前会话可见,数据被存储在用户的临时目录,并在会话结束时删除。接下来,在虚拟机 Node_03中使用Hive客户端工具Beeline,远程连接虚拟机Node_02的 HiveServer2服务操作Hive,在数据库hive_database中创建临时表temporary_table,具体命令如下。

CREATE TEMPORARY TABLE
hive_database.temporary_table
く
name STRING,
age int,
gender STRING
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
STORED AS textfile
TBLPROPERTIES("comment"="This is a temporary table");

上述命令执行完成后,在Hive客户端工具Beeline中执行“DESC FORMATTED temporary_table;"命令,查看数据库 hive_database中临时表 temporary_table 的表结构信息,如图所示。

2774f455244f2910b020825f638b481b202494.jpg

临时表temporary_table的表结构信息

临时表temporary_table在HDFS的数据存储路径为/tmp_local/hive/root目录中,该路径中/tmp_local/hive为Hive配置文件中参数 hive.exec.scratchdir指定的临时目录,/root是根据当前用户名root创建的目录。在Hive客户端工具Beeline中执行“!table”命令退出当前会话,再次使用Hive客户端工具Beeline,在虚拟机Node_03中远程连接虚拟机Node_02的HiveServer2服务时,会发观数据库 hive_database中已经不存在临时表temporary_table。

(1)临时表不支持分区,不能基于CREATETABLE句式创建临时分区表。

(2)临时表不支持索引。

(3)临时表是数据表的一种展现形式,因此针对数据表的操作同样可以应用于临时表。

(4)如果同一数据库中的临时表与非临时表名称一致,那么此会话内任何操作都会被解析为临时表的操作,用户将无法访问同名的非临时表。

责任编辑:华轩 来源: 今日头条

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK