-
Notifications
You must be signed in to change notification settings - Fork 65
odps sqoop
ouyangzhe edited this page Mar 7, 2017
·
7 revisions
odps-sqoop是基于社区sqoop 1.4.6版本开发的,增加了对MaxCompute的支持,可以支持将数据从Mysql等关系数据库和MaxCompute的导入和导出,也支持从Hdfs/Hive导入数据到MaxCompute的表中。
下面以几个基本的例子展示odps-sqoop工具的一些基本功能:
###(1)mysql数据导入到MaxCompute
- 将mysql数据库corp的表EMPLOYEES导入MaxCompute
$ bin/sqoop import --connect jdbc:mysql://db.foo.com/corp --table EMPLOYEES \
--odps-table corp_odps --odps-project project_name --odps-accessid xxxx \
--odps-accesskey xxxx --odps-endpoint your_odps_endpoint_url \
--odps-tunnel-endpoint your_odps_tunnel_endpoint_url
- 需要用户名/密码登录
$ bin/sqoop import --connect jdbc:mysql://db.foo.com/corp --table EMPLOYEES \
--username SomeUser -P \
--odps-table corp_odps --odps-project project_name --odps-accessid xxxx \
--odps-accesskey xxxx --odps-endpoint your_odps_endpoint_url \
--odps-tunnel-endpoint your_odps_tunnel_endpoint_url
###(2)MaxCompute数据导出到mysql
$ sqoop export --connect jdbc:mysql://db.example.com/foo --table bar \
--odps-table odps_bar --odps-project project_name --odps-accessid xxxx \
--odps-accesskey xxxx --odps-endpoint your_odps_endpoint_url
###(3)hdfs数据导入到MaxCompute
$ sqoop import --hdfs-to-odps --export-dir /user/hive/warehouse/hive_table -m 1 \
--odps-table hive_odps --columns id,city,name --odps-project odpstest \
--odps-accessid xxxx --odps-accesskey xxxx \
--odps-endpoint your_odps_endpoint_url \
--odps-tunnel-endpoint your_odps_tunnel_endpoint_url \
--create-odps-table --fields-terminated-by '\001' \
--odps-partition-keys=dt,pt --odps-partition-values=20151031,p1
注意:如果MaxCompute中表已经事先创建好,可以省略--columns这个配置项。
###(4)覆盖模式导入到MaxCompute
增加参数--odps-overwrite,会以覆盖的模式导入到MaxCompute的表或者分区当中。
###(5)设置日期的格式
增加参数--odps-input-dateformat yyyy-MM-dd\ HH:mm:ss
###(6)忽略导入过程的错误
增加参数--skip-failed 会自动过滤一些数据源中的脏数据,继续完成数据的导入。