目录
3.2、hive -e :不进入hive的交互窗口执行sql语句
3.3、hive -f :不进入hive的交互窗口执行保存了sql语句的文件
一、准备案例数据
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