alter table poi_release.map_poi_hn_click_validity_problem add partition(dt = '2021-10-01');
select * from poi_release.map_poi_hn_click_validity_problem where dt = '2021-10-01'
hive> load data inpath 'hdfs:///user/hive/warehouse/poi_release.db/map_poi_hn_click_validity_problem/dt=2021-11-12/part-00100-dae5801c-df2d-400f-9eec-bdb4bc5d1bd6-c000'
overwrite into table poi_release.map_poi_hn_click_validity_problem partition(dt = '2021-10-01');
hdfs dfs -cp /user/hive/warehouse/poi_release.db/map_poi_hn_click_validity_problem/dt=2021-11-12/part-00100-a94b51a4-c7b8-4ffe-9c8e-bcf96d09850c-c000
/user/hive/warehouse/poi_release.db/map_poi_hn_click_validity_problem/dt=2021-10-01
hdfs dfs -ls /user/hive/warehouse/poi_release.db/map_poi_hn_click_validity_problem/dt=2021-10-01
show partitions poi_release.map_poi_hn_click_validity_problem;
alter table poi_release.map_poi_hn_click_validity_problem drop partition (dt = '2021-10-01');
基于Hadoop开源数据框架工具Hive,本质上是将HDFS上的数据映射成数据库、数据表等元数据,然后再对这些文件进行检索查询。
1、内部表:导入数据时,将数据移动到hive指定的目录文件中,删除表时,数据也会删除;
2、外部表:建表时添加关键字external,并指定位置,删除表时不会删除源数据。
一、数据
1,tom,music-running-code,c++:98.0-java:76.0-php:65.0
2,jerry,music-code,c++:93.0-java:70.0-php:55.0
3,john,code,go:87.0-python:93.0
二、建表语句
CREATE TABLE table1 (
id int,
name string,
interest array<string>,
score map<string,string>
)
row format delimited fields terminated by ',' --列分割
collection items terminated by '-' --array分割
map keys terminated by ':' --map分割
stored AS textfile; --保存
三、导入数据
load data local inpath '/opt/data/test' overwrite into table table1;
外部表
create external table table2(
id int,name string,interest array<string>,
score map<string,string>)
row format delimited fields terminated by ','
collection items terminated by '-'
map keys terminated by ':' location '/testtable';
desc formatted table2;
创建分区表
create external table table2(
id int,name string,interest array<string>,
score map<string,string>)
partitioned by (year int)
row format delimited fields terminated by ','
collection items terminated by '-'
map keys terminated by ':' stored as textfile;
load data local inpath 'root/testdata.txt' into table
table3 partition(year=2018);
show partitions tables;
alter table table3 add partition(year=2019)
location '/testtable';
show partitions table3;
alter table table3 drop partition(year=2019);
网友评论