4.1 常规导入以追加方式导入数据,指定map并行度是1,字段分隔符为'001'。
[AppleScript] 纯文本查看 复制代码
sqoop import
--append
--connect $CONNECTURL
--username $ORACLENAME
--password $ORACLEPASSWORD
--target-dir $hdfsPath
--num-mappers 1 #使用1个mapper
--table $oralceTableName
--columns $columns
--fields-terminated-by '\001'
4.2 并行导入如果指定--m为1的话,使用的是1个map进行导入,不能发挥集群的并行计算能力。可以通过增加数量达到同时启动多个mapper个数实现并行导入的目的。
[AppleScript] 纯文本查看 复制代码
sqoop import
--append
--connect $CONNECTURL
--username $ORACLENAME
--password $ORACLEPASSWORD
--target-dir $hdfsPath
--num-mappers 4 #使用4个mapper
--table $oralceTableName
--columns $columns
--fields-terminated-by '\001'
--where "data_desc='2011-02-26'"
注意,并行导入时sqoop会先在主键字段上执行max和min的操作,将所有记录切割成指定的份数,然后再按照每个切片的数据范围进行同时导入。过程大致如下:
[AppleScript] 纯文本查看 复制代码
--查询主键的极值
select max(id) as max, select min(id) as min from table [where 如果指定了where子句];
--按照极值确定各自的处理范围
select * from table where 0 <= id < 250;
select * from table where 250 <= id < 500;
select * from table where 500 <= id < 750;
select * from table where 750 <= id < 1000;
如果数据库没有主键,则需要指定一个能够切割的字段进行处理,并且该字段值具有比较明显的切割线,即极值不能相等,否则无法进行切割。如下所示:
[AppleScript] 纯文本查看 复制代码
sqoop import [/size][/font][/color][/align][/color][/size][/font][/b] --append
--connect $CONNECTURL
--username $ORACLENAME
--password $ORACLEPASSWORD
--target-dir $hdfsPath
--num-mappers 4 #使用4个mapper
--table $oralceTableName
--columns $columns
--fields-terminated-by '\001'
--split-by clientip
--where "data_desc='2011-02-26'"
4.3 增量导入增量导入有两种方式,按照指定的值和时间戳。本质上就是按照字段类型是整型还是时间戳类型进行导入。只导入比指定的值还大的记录数。增量导入使用于字段值是自增类型或是时间戳自增类型。
[AppleScript] 纯文本查看 复制代码
sqoop import
--append
--connect $CONNECTURL
--username $ORACLENAME
--password $ORACLEPASSWORD
--target-dir $hdfsPath
--num-mappers 4 #使用4个mapper
--table $oralceTableName
--columns $columns
--fields-terminated-by '\001'
--incremental append #增量数据
--check-column num_iid #检查列
--last-value 0 #最后的值
按时间戳导入:
[AppleScript] 纯文本查看 复制代码
sqoop import
--append
--connect $CONNECTURL
--username $ORACLENAME
--password $ORACLEPASSWORD
--target-dir $hdfsPath
--num-mappers 4 #使用4个mapper
--table $oralceTableName
--columns $columns
--fields-terminated-by '\001'
--incremental lastmodified #
--check-column created #
--last-value '2012-02-01 11:0:00'