在sqoop自由形式查询中使用mysql函数

sczxawaw  于 2021-06-03  发布在  Sqoop
关注(0)|答案(1)|浏览(358)

我正试图执行这样的查询

SELECT replace(name, '\0', '') FROM example

在sqoop中使用参数--query

--query "select replace(name, '\\0', '')" from example e

但是这种方法返回了错误

ERROR tool.ImportTool: Imported Failed: No column by the name namefound while importing data; expecting one of [id, REPLACE_name___0_____]

你知道怎么解决这个问题吗?

m4pnthwp

m4pnthwp1#

首先,您需要正确地封装sql语句。然后需要用“/”转义“\”字符。
请检查以下为我工作:

sqoop import \
  --connect "jdbc:mysql://quickstart.cloudera:3306/retail_db" \
  --username=retail_dba \
  --password=cloudera \
  --query "select replace(department_name, '/\0', '*') from departments  where 1=1 and \$CONDITIONS" \
  --split-by "department_name" \
  --target-dir "/km/op_sqoop/dept_names" \
  -m 1

eval也发挥了作用:

sqoop eval \
  --connect "jdbc:mysql://quickstart.cloudera:3306/retail_db" \
  --username retail_dba \
  --password cloudera \
  --query "select department_id, department_name, replace(department_name, '/\0', '*') from departments"

不过,我不明白你的错误。希望有帮助。

相关问题