HiveSQL DML 内外表

2.8关于外表的说明和使用

内外表的唯一区分标识,即为 external 关键字。创建表时候有,则为外表,没有则默认均为内表。
内表和外表的 hdfs 目录,均可以自由指定 location,如不指定,则数据存储在 hive 的默认 hdfs 目录中,且后续均可以自由改变,但改变的场景不多,一般为了省事都不会轻易改变存储目录。
示例
创建外表

CREATE external TABLE student_external( 
id string comment 'stdno',
username string comment 'name', 
classid int comment 'class id',
classname string comment 'class name')comment '学生信息主表' 
partitioned by(come_date string comment 'come to school date') 
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t' 
LINES TERMINATED BY '\n'

从本地装载数据【就是copyFromLocal】

LOAD DATA LOCAL INPATH './student.txt' 
OVERWRITE INTO TABLE student_external PARTITION (come_date=20171120);

从hdfs装在数据
【就是将指定hdfs目录下的数据移动到表的数据存储目录move】

LOAD DATA INPATH '/tmp/input/student.txt' 
OVERWRITE INTO TABLE student_external PARTITION (come_date=20171120);

删除数据(删除数据后,hdfs 文件依然存在)

猜你喜欢

转载自blog.csdn.net/weixin_43400357/article/details/85160030
DML