>create table bigdata.eimrs(id string,name string,worker string,happies string,age int); >insert into table bigdata.eimrs values("0","张三","程序员","踢足球",30); >insert into table bigdata.eimrs values("1","李四","艺术家","打篮球",28); >insert into table bigdata.eimrs values("2","王五","程序员","乒乓球",32); >insert into table bigdata.eimrs values("3","成哥","程序员","铅球",32);
2· 创建外部表
1 2 3 4 5
>create external table student (s_id string,s_name string) row format delimited fields terminated by '\t'; >create external table bigdata.eimrs0(id string comment "id",name string comment "名称",teacher string comment "授课老师信息") comment "测试JSON格式外部表" row format serde 'org.apache.hive.hcatalog.data.JsonSerDe' stored as textfile;
3· 创建分区表
1 2
>create table score2 (s_id string, s_score int) partitioned by (year string,month string,day string); >insert into table score2 partition(year='2021',month='01',day='01') values("1",20);
4· 创建表指定obs 路径 以华为云为例 阿里云类似
1 2
>create database if not exists $database_name location "obs://桶/目录/"; >create table test(name string) location "obs://桶/user/hive/warehouse/test";
5. load本地数据
追加操作
1 2 3
>load data local inpath '/export/servers/hivedatas/student.csv' into table student;
>load data local inpath '/export/servers/hivedatas/student.csv' overwrite into table student;
6. loadHDFS数据
1 2
>load data inpath '/hivedatas/techer.csv' into table techer; >load data inpath '/hivedatas/techer.csv' into table techer partition(cur_date=20201210); (load到指定分区)
7. 修改hive表的ower
1
>ALTER TABLE $table_name SET OWNER user $username;