赞
踩
启动Hadoop:
启动Hive:${HADOOP_HOME}/sbin/start-all.sh
创建表:${HIVE_HOME}/bin/hive
- CREATE TABLE table_name
- [(col_name data_type [COMMENT col_comment])]
-
- create table hive_wordcount(context string);
加载数据到hive表
- LOAD DATA LOCAL INPATH 'filepath' INTO TABLE tablename
-
- load data local inpath '/home/hadoop/data/hello.txt' into table hive_wordcount;
- select word, count(1) from hive_wordcount lateral view explode(split(context,'\t')) wc as word group by word;
-
- lateral view explode(): 是把每行记录按照指定分隔符进行拆解
hive ql提交执行以后会生成mr作业,并在yarn上运行
删除表:
drop table hive_wordcount;
完整例子:
- create table emp(
- empno int,
- ename string,
- job string,
- mgr int,
- hiredate string,
- sal double,
- comm double,
- deptno int
- ) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
-
- create table dept(
- deptno int,
- dname string,
- location string
- ) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
-
- load data local inpath '/home/hadoop/data/emp.txt' into table emp;
- load data local inpath '/home/hadoop/data/dept.txt' into table dept;
-
- 求每个部门的人数
- select deptno, count(1) from emp group by deptno;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。