Sqoop:从MySQL导入到Hive时替换字符?

时间:2014-03-18 07:49:00

标签: mysql hadoop sqoop

将数据从MySQL导入Hive时,我需要在电话号码中删除两个字符+7。以下请求返回SQL错误。我应该使用什么是正确的replace命令?

sqoop import --connect jdbc:mysql://server/db --username xxxx --password yyyy --query 'select name, last_name, email, second_name, Replace(personal_phone, '+7', ''), Replace(mobile, '+7', ''), Replace(phone, '+7', '') from user where $CONDITIONS' --target-dir /data/test -m 1 --null-string '\\N' --null-non-string '\\N' --hive-import --hive-table user_inf

2 个答案:

答案 0 :(得分:1)

这个适用于我:

sqoop import --connect jdbc:mysql://server/db --username xxxx --password yyyy --query "select name, last_name, email, second_name, Replace(phone, "+7", '') as phone, Replace(mobile, "+7", '') as mobile from test where \$CONDITIONS" --target-dir /data/test -m 1 --null-string '\\N' --null-non-string '\\N' --hive-import --hive-table info

答案 1 :(得分:0)

REPLACE命令看起来正确。错误可能是由于引号,因为您在开头使用了单引号。我在SQL查询中将其更改为双引号。它现在应该工作:

sqoop import --connect jdbc:mysql://server/db --username xxxx --password yyyy --query "select name, last_name, email, second_name, Replace(personal_phone, '+7', ''), Replace(mobile, '+7', ''), Replace(phone, '+7', '') from user where $CONDITIONS" --target-dir /data/test -m 1 --null-string '\\N' --null-non-string '\\N' --hive-import --hive-table user_inf