-
Notifications
You must be signed in to change notification settings - Fork 64
odps sqoop
odps-sqoop是基于社区sqoop 1.4.6版本开发的,增加了对MaxCompute的支持,可以支持将数据从Mysql等关系数据库和MaxCompute的导入和导出,也支持从Hdfs/Hive导入数据到MaxCompute的表中。
下面以几个基本的例子展示odps-sqoop工具的一些基本功能:
- 将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
注意:需要指定odps表的具体类型,默认会被当成string来处理,通过--map-column-odps a=STRING,b=STRING,c=BIGINT这个参数来指定。
$ 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
$ 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这个配置项。
RCFile,ORCFile等格式的数据需要通过hcatalog的方式进行导入,需要配置好环境变量HADOOP_HOME, HCAT_HOME参数。 对Hadoop版本和Hive的版本要求都为2.0以上的版本,否则在提交Sqoop作业的时候会报版本不兼容的错误。 将hive中一个表test_rcfile导入MaxCompute的表test_rcfile的命令如下:
$ sqoop import --hdfs-to-odps -hcatalog-table test_rcfile -m 1 \
--odps-table test_rcfile --columns a,b,c --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 --map-column-odps a=STRING,b=STRING,c=BIGINT
如果按分区导入,则需要增加hcatalog的分区参数--hcatalog-partition-keys xxx --hcatalog-partition-values xxx,MaxCompute的表也需要指定对应的分区参数--odps-partition-keys xxx --odps-partition-values xxx。
增加参数--odps-overwrite,会以覆盖的模式导入到MaxCompute的表或者分区当中。
增加参数--odps-input-dateformat yyyy-MM-dd\ HH:mm:ss
增加参数--skip-failed 会自动过滤一些数据源中的脏数据,继续完成数据的导入。
--input-null-string '\N'