partition 相当于索引,避免全表扫描
使用外部表不会清除HDFS文件系统的数据
#使用hive -e 可以执行多条语句
hive -e 'sentence1; sentence2;'
#进入hive 后查看当前路径
!pwd;
#hive 界面使用命令查看hdfs路径
dfs -ls / ;
#使用desc可以查看表的信息
desc <table.name>
#查看分区表的分区信息
show partitions <table.name>
通过文件存储的位置来看分区:
一般分区信息不存在于load的表中
create database if not exists bikepatition
comment 'test database';
create table if not exists bikepatition.bike(
tripduration string,
starttime string,
stoptime string,
start_station_id string,
start_station_name string,
start_station_latitude string,
start_station_longitude string,
end_station_id string,
end_station_name string,
end_station_latitude string,
end_station_longitude string,
bikeid string,
usertype string,
birth_year string,
gender string
)
partitioned by (time_month string,creator string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS TEXTFILE;
载入数据
load data local inpath '<绝对路径>' into table <table_name> partition(time_month = <分区标签>,creator = 'eric');
alter table <table_name> add partition(time_month=<标签>,creator='eric') location '<本地文件路径>';
alter table <table_name> drop partition(time_month=<标签> ,creator='eric');