标签:alt 清空 转换 换工作 文件 clerk 不包含 ice 员工
Hive Load语句不会在加载数据的时候做任何转换工作,而是纯粹的把数据文件复制/移动到Hive表对应的地址。语法格式如下:
LOAD DATA [LOCAL] INPATH ‘filepath‘ [OVERWRITE] INTO TABLE tablename [PARTITION (partcol1=val1, partcol2=val2 ...)] LOAD DATA [LOCAL] INPATH ‘filepath‘ [OVERWRITE] INTO TABLE tablename [PARTITION (partcol1=val1, partcol2=val2 ...)] [INPUTFORMAT ‘inputformat‘ SERDE ‘serde‘] (3.0 or later)
几点说明:
create table emp (empno int, ename string, job string, mgr int, hiredate string, sal int, comm int, deptno int) row format delimited fields terminated by ‘,‘;
7369,SMITH,CLERK,7902,1980/12/17,800,0,20 7499,ALLEN,SALESMAN,7698,1981/2/20,1600,300,30 7521,WARD,SALESMAN,7698,1981/2/22,1250,500,30 7566,JONES,MANAGER,7839,1981/4/2,2975,0,20 7654,MARTIN,SALESMAN,7698,1981/9/28,1250,1400,30 7698,BLAKE,MANAGER,7839,1981/5/1,2850,0,30 7782,CLARK,MANAGER,7839,1981/6/9,2450,0,10 7788,SCOTT,ANALYST,7566,1987/4/19,3000,0,20 7839,KING,PRESIDENT,-1,1981/11/17,5000,0,10 7844,TURNER,SALESMAN,7698,1981/9/8,1500,0,30 7876,ADAMS,CLERK,7788,1987/5/23,1100,0,20 7900,JAMES,CLERK,7698,1981/12/3,950,0,30 7902,FORD,ANALYST,7566,1981/12/3,3000,0,20 7934,MILLER,CLERK,7782,1982/1/23,1300,0,10
load data inpath ‘/scott/emp.csv‘ into table emp;
load data local inpath ‘/root/temp/emp.csv‘ into table emp;
当然我们也可以使用insert语句加载数据。例如,我们创建如下的分区表:
create table emp_part_1 (empno int, ename string, job string, mgr int, hiredate string, sal int, comm int) partitioned by (deptno int) row format delimited fields terminated by ‘,‘;
使用insert语句将数据插入到对应的分区上。
插入10号部门的员工数据 insert into table emp_part_1 partition(deptno=10) select empno,ename,job,mgr,hiredate,sal,comm from emp where deptno=10; 插入20号部门的员工数据 insert into table emp_part_1 partition(deptno=20) select empno,ename,job,mgr,hiredate,sal,comm from emp where deptno=20; 插入30号部门的员工数据 insert into table emp_part_1 partition(deptno=30) select empno,ename,job,mgr,hiredate,sal,comm from emp where deptno=30;
这里我们使用了一个子查询查询出了对应部门的员工数据,再使用insert语句插入到对应的分区上。
标签:alt 清空 转换 换工作 文件 clerk 不包含 ice 员工
原文地址:https://www.cnblogs.com/collen7788/p/12936239.html