导入表的所有字段

sqoop import --connect jdbc:oracle:thin:@192.168.1.107:1521:ORCL \
--username SCOTT --password tiger \
--table EMP \
--
hive-import --create-hive-table --hive-table emp -m 1;

如果报类似的错:

ERROR tool.ImportTool: Encountered IOException running import job: org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory EMP already exists

先去HDFS系统中删除该文件: hadoop fs -rmr /user/hadoop/EMP

如果报类似的错:

FAILED: Error in metadata: AlreadyExistsException(message:Table emp already exists)

如果报类似的错:

hive.HiveImport: Exception in thread "main" java.lang.NoSuchMethodError: org.apache.thrift.EncodingUtils.setBit(BIZ)B

这是因为在同路径下安装了hive和hbase,而hbase和hive的lib目录下的thrift版本不同。
hbase下的为libthrift-0.x.0.jar,hive下的为libthrift-0.x.0.jar。将Hbase下的0.x.0版的删除,换为0.x.0的即可。
ps:不知为什么Sqoop向Hive中导入数据还有Hbase的事

说明:hive表已经存在,需要先删除

查看:

desc emp;
empno double
ename string
job string
mgr double
hiredate string
sal double
comm double
deptno double select * from emp;
7369.0 SMITH CLERK 7902.0 1980-12-17 00:00:00.0 800.0 NULL 20.0
7499.0 ALLEN SALESMAN 7698.0 1981-02-20 00:00:00.0 1600.0 300.0 30.0
7521.0 WARD SALESMAN 7698.0 1981-02-22 00:00:00.0 1250.0 500.0 30.0
7566.0 JONES MANAGER 7839.0 1981-04-02 00:00:00.0 2975.0 NULL 20.0
7654.0 MARTIN SALESMAN 7698.0 1981-09-28 00:00:00.0 1250.0 1400.0 30.0
……

注:一般情况下不使用--create-hive-table去创建表的,因为它创建的表的字段格式,不符合我们的要求。

导入表的指定字段

手工创建hive表:

create table emp_column(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
)
row format delimited fields terminated by '\t' lines terminated by '\n'
stored as textfile;
sqoop import --connect jdbc:oracle:thin:@192.168.1.107:1521:ORCL \
--username SCOTT --password tiger \
--table EMP --columns "EMPNO,ENAME,JOB,SAL,COMM" \
--fields-terminated-by '\t' --lines-terminated-by '\n' \
--hive-drop-import-delims --hive-import --hive-table emp_column \
-m 3;

说明:重新再执行,每重复导入一次,hive中的数据会重复导入。

sqoop import --connect jdbc:oracle:thin:@192.168.1.107:1521:ORCL \
--username SCOTT --password tiger \
--table EMP --columns "EMPNO,ENAME,JOB,SAL,COMM" \
--fields-terminated-by '\t' --lines-terminated-by '\n' \
--hive-drop-import-delims --hive-overwrite --hive-import --hive-table emp_column \
-m 3;

注:--hive-overwrite指定覆盖表里已经存在的记录,99%都是要使用overwrite的,避免重跑时产生重复数据。

导入表的指定字段到hive分区表

创建hive分区表:

create table emp_partition(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
)
partitioned by (pt string)
row format delimited fields terminated by '\t' lines terminated by '\n'
stored as textfile;

导入pt='2013-08-01'

sqoop import --connect jdbc:oracle:thin:@192.168.1.107:1521:ORCL \
--username SCOTT --password tiger \
--table EMP --columns "EMPNO,ENAME,JOB,SAL,COMM" \
--hive-overwrite --hive-import --hive-table emp_partition \
--fields-terminated-by '\t' --lines-terminated-by '\n' \
--hive-drop-import-delims --hive-partition-key 'pt' --hive-partition-value '2013-08-01' \
-m 3;

导入pt='2013-08-02'

sqoop import --connect jdbc:oracle:thin:@192.168.1.107:1521:ORCL \
--username SCOTT --password tiger \
--table EMP --columns "EMPNO,ENAME,JOB,SAL,COMM" \
--hive-overwrite --hive-import --hive-table emp_partition \
--fields-terminated-by '\t' --lines-terminated-by '\n' \
--hive-drop-import-delims --hive-partition-key 'pt' --hive-partition-value '2013-08-02' \
-m 3;

查询:

select * from emp_partition where pt='2013-08-01';
select * from emp_partition where pt='2013-08-02';

sqoop操作之ORACLE导入到HIVE的更多相关文章

  1. sqoop操作之Oracle导入到HDFS

    导入表的所有字段 sqoop import --connect jdbc:oracle:thin:@192.168.1.100:1521:ORCL \ --username SCOTT --passw ...

  2. sqoop工具从oracle导入数据2

    sqoop工具从oracle导入数据 sqoop工具是hadoop下连接关系型数据库和Hadoop的桥梁,支持关系型数据库和hive.hdfs,hbase之间数据的相互导入,可以使用全表导入和增量导入 ...

  3. 使用 sqoop 将mysql数据导入到hive表(import)

    Sqoop将mysql数据导入到hive表中 先在mysql创建表 CREATE TABLE `sqoop_test` ( `id` ) DEFAULT NULL, `name` varchar() ...

  4. 使用sqoop将mysql数据导入到hive中

    首先准备工具环境:hadoop2.7+mysql5.7+sqoop1.4+hive3.1 准备一张数据库表: 接下来就可以操作了... 一.将MySQL数据导入到hdfs 首先我测试将zhaopin表 ...

  5. 使用Talend Open Studio将数据分步从oracle导入到hive中

    先使用Tos建立模型,将Oracle中的数据导入到本地: build job后,形成独立可以运行的程序: 将生成的zip文件,上传到hadoop集群上,有hive环境的机器上: [hive@h1 wo ...

  6. 使用sqoop工具从oracle导入数据

    sqoop工具是hadoop下连接关系型数据库和Hadoop的桥梁,支持关系型数据库和hive.hdfs,hbase之间数据的相互导入,可以使用全表导入和增量导入 从RDBMS中抽取出的数据可以被Ma ...

  7. sqoop 操作从hdfs 导入到mysql中语句

    将hdfs下/dw/dms/usr_trgt下的文件导入到mysql中test数据库下usr_trgt表中 sqoop-export   --connect jdbc:mysql://mysqlDB: ...

  8. sqoop导oracle数据到hive中并动态分区

    静态分区: 在hive中创建表可以使用hql脚本: test.hql USE TEST; CREATE TABLE page_view(viewTime INT, userid BIGINT, pag ...

  9. 使用Sqoop从mysql向hdfs或者hive导入数据时出现的一些错误

    1.原表没有设置主键,出现错误提示: ERROR tool.ImportTool: Error during import: No primary key could be found for tab ...

随机推荐

  1. screen 命令 http://man.linuxde.net/screen

    http://man.linuxde.net/screen -A 将所有的视窗都调整为目前终端机的大小. -d <作业名称> 将指定的screen作业离线. -h <行数> 指 ...

  2. CentOS 下安装和使用 Docker

    引言: 在服务器开发过程中,环境部署无疑是及其繁琐的事情,特别是当项目数量和规模达到一定级别之后,在一台新的机器上部署项目环境无疑是极其漫长而痛苦的,那么什么办法能够实现我们的目标:在开发环境的一次配 ...

  3. leetcode-3-LongestSubstringWithoutRepeatingCharacters

    problem:Longest Substring Without Repeating Characters to be continue

  4. C++ 备忘录 (1)

    取模: 1. 转载自:http://ceeji.net/blog/mod-in-real/ 背景 最近在一道 Java 习题中,看到这样的一道题: What is the output when th ...

  5. Dubbo 版 Helloworld

    使用工具:MAVEN.IDEA.Spring.Dubbo.Zookeeper 直接上代码 项目结构: 步骤如下: 搭建MAVEN项目,添加相关依赖 pom.xml <!--Zookeeper-- ...

  6. 使用webpack搭建vue项目中遇到的问题

    1:data数据文件经试验,需要放在生成的build文件夹中才能生效,但是应该把data文件夹先放在src中,然后如何定义config文件,让其复制过去? new CopyWebpackPlugin( ...

  7. Git冲突和解决冲突

    1.产生冲突原因 产生:多个开发者同时使用或者操作git中的同一个文件,最后在依次提交和push的时候,第一个操作的是可以正常提交的,而之后的开发者想要执行pull(拉)和pull(push)操作的时 ...

  8. ubuntu 安装php 报错解决

    安装php时候遇到的问题: dpkg: 处理软件包 php7.1-opcache (--configure)时出错: 依赖关系问题 - 仍未被配置dpkg: 依赖关系问题使得 php7.1-readl ...

  9. leetcode:Longest Common Prefix【Python版】

    1.当strs为空,直接输出“” 2.当strs中含有“”,直接输出“” 3.strs[0]的最长长度由最短公共长度l决定(code line:15) class Solution: # @retur ...

  10. Angular 4 路由介绍

    Angular 4 路由 1. 创建工程 ng new router --routing 2. 创建home和product组件 ng g component home ng g component ...