sqoop blob mysql_sqoop

1、驱动

sqoop import --driver com.microsoft.jdbc.sqlserver.SQLServerDriver \ --connect ...

2、写sql语句导入的方式

sqoop import \ --query 'SELECT a.*, b.* FROM a JOIN b on (a.id == b.id) WHERE $CONDITIONS' \ --split-by a.id --target-dir /user/foo/joinresults

如果是顺序导入的话,可以只开一个线程

sqoop import \ --query 'SELECT a.*, b.* FROM a JOIN b on (a.id == b.id) WHERE $CONDITIONS' \ -m 1 --target-dir /user/foo/joinresults

如果where语句中有要用单引号的,就像这样子写就可以啦"SELECT * FROM x WHERE a='foo' AND \$CONDITIONS"

3、 1.4.3版本的sqoop不支持复杂的sql语句,不支持or语句

4、 --split-by

默认是主键,假设有100行数据,它会执行那个SELECT * FROM sometable WHERE id >= lo AND id < hi, with (lo, hi) 会分为4次导入(0,250),(250,500),(500,750),(750,1001)

如果这个字段不能达到实际的划分区域的效果,可以用别的字段。如果没有索引列或者是组合主键的表,需要手动设置一个划分列

5、--direct 是为了利用某些数据库本身提供的快速导入导出数据的工具,比如mysql的mysqldump,性能比jdbc更好,但是不知大对象的列,使用的时候,那些快速导入的工具的客户端必须的shell脚本的目录下

6、导入数据到hdfs目录,这个命令会把数据写到/shared/foo/ 目录

sqoop import --connnect --table foo --warehouse-dir /shared \

sqoop import --connnect --table foo --target-dir /dest \

7、传递参数给快速导入的工具,使用--开头,下面这句命令传递给mysql默认的字符集是latin1

sqoop import --connect jdbc:mysql://http://server.foo.com/db --table bar \ --direct -- --default-character-set=latin1

8、转换为对象

--map-column-java 转换为java数据类型

--map-column-hive 转转为hive数据类型

9、增加导入

--check-column (col) Specifies the column to be examined when determining which rows to import.

--incremental (mode) Specifies how Sqoop determines which rows are new. Legal values for mode include append and lastmodified.

--last-value (value) Specifies the maximum value of the check column from the previous import.

增加导入支持两种模式append和lastmodified,用--incremental来指定

10、在导入大对象,比如BLOB和CLOB列时需要特殊处理,小于16MB的大对象可以和别的数据一起存储,超过这个值就存储在_lobs的子目录当中,它们采用的是为大对象做过优化的存储格式,最大能存储2^63字节的数据,我们可以用--inline-lob-limit参数来指定每个lob文件最大的限制是多少。如果设置为0,则大对象使用外部存储

11、分隔符、转移字符

下面的这句话

Some string, with a comma.

Another "string with quotes"

使用这句命令导入$ sqoop import --fields-terminated-by , --escaped-by \\ --enclosed-by '\"' ...

会有下面这个结果

"Some string, with a comma.","1","2","3"...

"Another \"string with quotes\"","4","5","6"...

使用这句命令导入$ sqoop import --optionally-enclosed-by '\"' (the rest as above)...

"Some string, with a comma.",1,2,3...

"Another \"string with quotes\"",4,5,6...

12、hive导入参数

--hive-home

--hive-import 插入数据到hive当中,使用hive的默认分隔符

--hive-overwrite 重写插入

--create-hive-table 建表,如果表已经存在,该操作会报错!

--hive-table 设置到hive当中的表名

--hive-drop-import-delims 导入到hive时删除 \n, \r, and \01

--hive-delims-replacement 导入到hive时用自定义的字符替换掉 \n, \r, and \01

--hive-partition-key hive分区的key

--hive-partition-value hive分区的值

--map-column-hive 类型匹配,sql类型对应到hive类型

13、hive空值处理

sqoop会自动把NULL转换为null处理,但是hive中默认是把\N来表示null,因为预先处理不会生效的,我们需要使用 --null-string 和 --null-non-string来处理空值 把\N转为\\N

sqoop import ... --null-string '\\N' --null-non-string '\\N'

14、替换数据字段内容中含有Hive默认行分隔符(\n or \r)的字符串字段或者列分隔符(\01) 为 arg

--hive-delims-replacement

15、删除数据字段内容中含有Hive默认行分隔符(\n or \r)的字符串字段或者列分隔符(\01)

--hive-drop-import-delims

16、sqoop 推送merge功能

16.1、 merge功能是根据mysql表的主键和唯一键进行是否更新和插入。首先根据主键判断是否有相同的行存在,如果有则更新,如果没有再判断唯一键是否有相同的行,有则更新没有则插入

16.2、 抽取指定的mysql key作为分片的列,如果这个列是vachar的则通过参数

-Dorg.apache.sqoop.splitter.allow_text_splitter=true实现,否则会报错

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值