当从MySQL导入数据到配置单元时,我需要在电话号码中删除两个字符的+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
发布于 2014-03-18 20:37:18
这一条对我很有效:
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
发布于 2014-03-18 15:57:55
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
https://stackoverflow.com/questions/22473221
复制相似问题