当前位置:   article > 正文

Hive基本使用_hg路hive

hg路hive

启动Hadoop

${HADOOP_HOME}/sbin/start-all.sh

启动Hive:

${HIVE_HOME}/bin/hive

创建表:

  1. CREATE TABLE table_name
  2. [(col_name data_type [COMMENT col_comment])]
  3. create table hive_wordcount(context string);
加载数据到hive表

  1. LOAD DATA LOCAL INPATH 'filepath' INTO TABLE tablename
  2. load data local inpath '/home/hadoop/data/hello.txt' into table hive_wordcount;

查询:

  1. select word, count(1) from hive_wordcount lateral view explode(split(context,'\t')) wc as word group by word;
  2. lateral view explode(): 是把每行记录按照指定分隔符进行拆解

hive ql提交执行以后会生成mr作业,并在yarn上运行

删除表:

drop table hive_wordcount;


完整例子:

  1. create table emp(
  2. empno int,
  3. ename string,
  4. job string,
  5. mgr int,
  6. hiredate string,
  7. sal double,
  8. comm double,
  9. deptno int
  10. ) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
  11. create table dept(
  12. deptno int,
  13. dname string,
  14. location string
  15. ) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
  16. load data local inpath '/home/hadoop/data/emp.txt' into table emp;
  17. load data local inpath '/home/hadoop/data/dept.txt' into table dept;
  18. 求每个部门的人数
  19. select deptno, count(1) from emp group by deptno;





声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/711208
推荐阅读
相关标签
  

闽ICP备14008679号