Hive控制台、交互命令的使用、shell执行hql脚本、定时任务设定

本文详细介绍了如何使用Hive进行数据操作,包括创建表、DQL查询、通过shell执行HQL脚本以及设置定时任务。重点讲解了Hive的交互命令如`hive -e`和`hive -f`,并提供了shell脚本执行HQL的实例,同时讨论了Hive的本地模式和JOIN操作优化。最后,探讨了使用at和crontab进行Hive任务的定时调度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、准备案例数据

二、hive控制台执行创建表

2.1、创建hive的两个外部表

2.2、创建一个emp_ptn动态分区表

三、Hive的DQL数据查询(使用交互命令)

3.1、注意:hive的select ...不支持以下类型

3.2、hive -e :不进入hive的交互窗口执行sql语句

3.3、hive -f :不进入hive的交互窗口执行保存了sql语句的文件

四、shell执行hql脚本

五、定时执行hql的shell脚本


一、准备案例数据

1.1、数据

[hdp@hdp02 demo]$ vi emp.txt
7369	SMITH	CLERK	7902	1980-12-17 00:00:00	800.00		20
7499	ALLEN	SALESMAN	7698	1981-02-20 00:00:00	1600.00	300.00	30
7521	WARD	SALESMAN	7698	1981-02-22 00:00:00	1250.00	500.00	30
7566	JONES	MANAGER	7839	1981-04-02 00:00:00	2975.00		20
7654	MARTIN	SALESMAN	7698	1981-09-28 00:00:00	1250.00	1400.00	30
7698	BLAKE	MANAGER	7839	1981-05-01 00:00:00	2850.00		30
7782	CLARK	MANAGER	7839	1981-06-09 00:00:00	2450.00		10
7788	SCOTT	ANALYST	7566	1987-04-19 00:00:00	1500.00		20
7839	KING	PRESIDENT		1981-11-17 00:00:00	5000.00		10
7844	TURNER	SALESMAN	7698	1981-09-08 00:00:00	1500.00	0.00	30
7876	ADAMS	CLERK	7788	1987-05-23 00:00:00	1100.00		20
7900	JAMES	CLERK	7698	1981-12-03 00:00:00	950.00		30
7902	FORD	ANALYST	7566	1981-12-03 00:00:00	3000.00		20
7934	MILLER	CLERK	7782	1982-01-23 00:00:00	1300.00		10
[hdp@hdp02 demo]$ vi dept.txt
10	ACCOUNTING	NEW YORK
20	RESEARCH	DALLAS
30	SALES	CHICAGO
40	OPERATIONS	BOSTON

1.2、上传数据到hdfs上的emp_dept目录下

[hdp@hdp02 ~]$ hdfs dfs -mkdir /emp
[hdp@hdp02 ~]$ hdfs dfs -mkdir /dept
[hdp@hdp02 ~]$ hdfs dfs -put /home/hdp/demo/dept.txt /dept/dept.txt                  
[hdp@hdp02 ~]$ hdfs dfs -put /home/hdp/demo/emp.txt /emp/emp.txt 
[hdp@hdp02 demo]$ hdfs dfs -cat /dept/dept.txt
[hdp@hdp02 demo]$ hdfs dfs -cat /emp/emp.txt

二、hive控制台执行创建表

2.1、创建hive的两个外部表

hive (hive01)> create external table emp
(empno INT comment "-员工表编号",  
 ename STRING comment '员工姓名', 
 job STRING comment '职位类型', 
 mgr INT comment '领导编号' ,  
 hiredate TIMESTAMP comment '雇佣日期',   
 sal DECIMAL(7,2) comment '工资',    
 comm DECIMAL(7,2) comment '奖金',    
 deptno INT comment '部门编号' ) 
 row format delimited fields terminated by "\t" 
 lines terminated by "\n"
 location "/emp";
hive (hive01)> create external table dept
(deptno INT comment '部门编号',
 dname STRING comment '部门名称',
 loc STRING comment '部门所在的城市' ) 
 row format delimited fields terminated by "\t" 
 lines terminated by "\n"
 location "/dept";
hive (hive01)> select * from dept;
hive (hive01)> select * from emp;

2.2、创建一个emp_ptn动态分区表

-- 动态分区表
      -- 开启动态分区
hive (hive01)> set hive.exec.dynamic.partition = true;
hive (hive01)> set hive.exec.dynamic.partition.mode = nonstrict;
      -- 创建分区表
hi
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值