https://cwiki.apache.org/confluence/display/Hive/LanguageManual+ImportExport
一、Export、Import
Export 导出,将Hive表中的数据,导出到外部 Import 导入,将外部数据导入Hive表中
二、Export
1、语法
EXPORT TABLE tablename TO ‘export_target_path‘;
2、用法
#把emp表导出到hdfs上 hive (default)> EXPORT TABLE default.emp TO ‘/user/root/hive/export/emp_exp‘; hive (default)> dfs -ls -R /user/root/hive/export; drwxr-xr-x - root supergroup 0 2019-04-24 10:06 /user/root/hive/export/emp_exp -rw-r--r-- 1 root supergroup 1588 2019-04-24 10:06 /user/root/hive/export/emp_exp/_metadata drwxr-xr-x - root supergroup 0 2019-04-24 10:06 /user/root/hive/export/emp_exp/data -rw-r--r-- 1 root supergroup 659 2019-04-24 10:06 /user/root/hive/export/emp_exp/data/emp.txt
三、Import
1、语法
IMPORT TABLE tablename FROM ‘source_path‘;
2、用法
#先在db_hive库下创建一个emp表 hive (default)> use db_hive; OK Time taken: 0.012 seconds hive (db_hive)> show tables; OK tab_name student Time taken: 0.014 seconds, Fetched: 1 row(s) hive (db_hive)> create table db_hive.emp like default.emp; OK Time taken: 0.087 seconds hive (db_hive)> show tables; OK tab_name emp student Time taken: 0.011 seconds, Fetched: 2 row(s) #导入 hive (db_hive)> import table db_hive.emp from ‘/user/root/hive/export/emp_exp‘; hive (db_hive)> select * from db_hive.emp; OK emp.empno emp.ename emp.job emp.mgr emp.hiredate emp.sal emp.comm emp.deptno 7369 SMITH CLERK 7902 1980-12-17 800.0 NULL 20 7499 ALLEN SALESMAN 7698 1981-2-20 1600.0 300.0 30 7521 WARD SALESMAN 7698 1981-2-22 1250.0 500.0 30 7566 JONES MANAGER 7839 1981-4-2 2975.0 NULL 20 7654 MARTIN SALESMAN 7698 1981-9-28 1250.0 1400.0 30 7698 BLAKE MANAGER 7839 1981-5-1 2850.0 NULL 30 7782 CLARK MANAGER 7839 1981-6-9 2450.0 NULL 10 7788 SCOTT ANALYST 7566 1987-4-19 3000.0 NULL 20 7839 KING PRESIDENT NULL 1981-11-17 5000.0 NULL 10 7844 TURNER SALESMAN 7698 1981-9-8 1500.0 0.0 30 7876 ADAMS CLERK 7788 1987-5-23 1100.0 NULL 20 7900 JAMES CLERK 7698 1981-12-3 950.0 NULL 30 7902 FORD ANALYST 7566 1981-12-3 3000.0 NULL 20 7934 MILLER CLERK 7782 1982-1-23 1300.0 NULL 10 Time taken: 0.029 seconds, Fetched: 14 row(s) hive (db_hive)> dfs -ls -R /user/hive/warehouse/db_hive.db/emp; -rw-r--r-- 1 root supergroup 659 2019-04-24 10:15 /user/hive/warehouse/db_hive.db/emp/emp.txt
四、Export、Import的其他高级用法
Export、Import还可以用在外部表、分区表上面等,这个可以等用到的时候再看;
原文地址:https://www.cnblogs.com/weiyiming007/p/10760936.html
时间: 2024-11-05 13:39:22