如何在sqoop自由格式查询中传递字符串值

问题描述 投票:0回答:1

我需要从几个不同的SQL服务器导入数据,这些服务器具有相同的表,表结构甚至主键值。因此,为了唯一地标识记录,从SQLserver中提取“S1”,我希望有一个额外的列 - 比如我的hive表中的“serverName”。我应该如何在我的sqoop自由格式查询中添加它。

我想要做的就是传递硬编码值以及列列表,以便硬编码列值应存储在Hive中。完成后,我可以根据服务器数据动态更改此值。

sqoop import --connect "connDetails" --username "user"  --password "pass" --query "select col1, col2, col3, 'S1' from table where \$CONDITIONS" --hive-import --hive-overwrite --hive-table stg.T1  --split-by col1 --as-textfile  --target-dir T1  --hive-drop-import-delims

S1是这里的硬编码值。我在用SQL方式思考,当你传递硬编码值时,会返回与查询结果相同的值。任何指针如何完成这项工作?提前致谢。

hadoop sqoop
1个回答
0
投票

已解决:实际上它只需要硬编码值的别名。所以执行的sqoop命令是 -

sqoop import --connect "connDetails" --username "user"  --password "pass" --query "select col1, col2, col3, 'S1' as serverName from table where \$CONDITIONS" --hive-import --hive-overwrite --hive-table stg.T1  --split-by col1 --as-textfile  --target-dir T1  --hive-drop-import-delims
© www.soinside.com 2019 - 2024. All rights reserved.