Hive的分区表

1、创建分区表:分区表的分区是虚拟的

create table if not exists emp_part(
empno int,
enname string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
)
partitioned by (date string)
row format delimited fields terminated by '\t';

 

2、用原来普通表的方式加载数据,发现报错:

hive (db_emp)> load data local inpath '/opt/data/emp' into table emp_part;
FAILED: SemanticException [Error 10062]: Need to specify partition columns because the destination table is partitioned

正确的命令如下:

hive (db_emp)> load data local inpath '/opt/data/emp' into table emp_part partition (date='201807');
Loading data to table db_emp.emp_part partition (date=201807)
Partition db_emp.emp_part{date=201807} stats: [numFiles=1, numRows=0, totalSize=728, rawDataSize=0]
OK
Time taken: 0.831 seconds

查看hdfs:

 查询某个分区:

hive (db_emp)> select * from emp_part where date='201805';
OK
emp_part.empno	emp_part.enname	emp_part.job	emp_part.mgr	emp_part.hiredate	emp_part.sal	emp_part.comm	emp_part.deptno	emp_part.date
7499	ALLEN 	SALESMAN 	7698	1981-02-20	1600.0	300.0	30	201805
7521	WARD  	SALESMAN 	7698	1981-02-22	1250.0	500.0	30	201805
7566	JONES 	MANAGER  	7839	1981-04-02	2975.0	0.0	20	201805
7654	MARTIN	SALESMAN 	7698	1981-09-28	1250.0	1400.0	30	201805
7698	BLAKE 	MANAGER  	7839	1981-05-01	2850.0	0.0	30	201805
7782	CLARK 	MANAGER  	7839	1981-06-09	2450.0	0.0	10	201805
7788	SCOTT 	ANALYST  	7566	1987-07-13	3000.0	0.0	20	201805
7839	KING  	PRESIDENT	NULL	1981-11-07	5000.0	0.0	10	201805
7844	TURNER	SALESMAN 	7698	1981-09-08	1500.0	0.0	30	201805
7876	ADAMS 	CLERK    	7788	1987-07-13	1100.0	0.0	20	201805
7900	JAMES 	CLERK    	7698	1981-12-03	950.0	0.0	30	201805
7902	FORD  	ANALYST  	7566	1981-12-03	3000.0	0.0	20	201805
7934	MILLER	CLERK    	7782	1982-01-23	1300.0	0.0	10	201805
Time taken: 0.351 seconds, Fetched: 13 row(s)

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值