2017-04-21 116 views
0

我正尝试使用sqoop中的--query选项从SQL Server导入数据。我关心的是,我们如何声明在SQL Server中使用--query使用哪个模式。SQOOP - 在SQL Server中使用SCHEMA查询

我的脚本:

sqoop \ 
--options-file sqoop/aw_mssql.cfg \ 
--query "select BusinessEntityId, LoginID, cast(OrganizationNode as string) from Employee where \$CONDITIONS" \ 
--hive-table employees \ 
--hive-database mssql \ 
-- --schema=HumanResources 

仍然会产生一个错误

Invalid object name 'Employee'

也试过

--connect "jdbc:sqlserver://192.168.1.17;database=AdventureWorks;schema=HumanResources" 

但也失败了。

回答

0

你可以试试这个下面的代码:

sqoop import \ 
--connect jdbc:sqlserver://192.168.1.17;database=AdventureWorks \ 
--username "Your User" \ 
--password "Your Password" \ 
--driver com.microsoft.sqlserver.jdbc.SQLServerDriver \ 
--verbose \ 
--query "select BusinessEntityId, LoginID, cast(OrganizationNode as string) from HumanResources.Employee where \$CONDITIONS" \ 
--split-by "EmpID" \ 
--where " EmpID='Employee ID' " \ 
-m 1 \ 
--target-dir /user/cloudera/ingest/raw/Employee\ 
--fields-terminated-by "," \ 
--hive-import \ 
--create-hive-table \ 
--hive-table mssql.employees \ 
  1. hive-import - 导入表到蜂巢(采用蜂巢的默认分隔符 如果没有设置。)
  2. create-hive-table - 这将创造新的HIBE表。 Note:如果Hive表已存在,则作业 将失败。它在这个 的情况下工作。
  3. hive-table - 指定<db_name>.<table_name>
+0

嗨,我的关注是源表EMPLOYEE是在架构HumanResources下的AdventureWorks数据库。我如何声明脚本使用HumanResources模式作为源。感谢 – askdk

+0

然后在--query参数尝试使用'HumanResources.Employee' – Souvik

+0

已经尝试过但失败。 – askdk

0

您使用的sqoop命令缺少一些东西。首先你需要指定这是一个sqoop导入作业。除此之外,你的查询需要有一个连接字符串。此外,我不知道你在选项文件中传递的是什么论点,所以如果你已经发布了细节,它会更容易,我不知道-- --schema=HumanResources的事情,因为我没有看到它。正确的工作sqoop例如查询:

sqoop import --connect <connection string> --username <username> --password <password> --query <query> --hive-import --target-table <table_name> -m <no_if_mappers 

而且记住这一点,在使用--query工具,你不需要指定--table工具,否则会抛出异常。

+0

的问题是,我的源表是在架构人力资源,而不是默认dbo架构。基本上它就像AdventureWorks.HumanResources.Employee。我如何将脚本设置为在HumanResources模式下查询?谢谢 – askdk

+0

你应该尝试--query'SELECT * FROM HumanResources.Employee WHERE $ CONDITIONS' –

0

-schema可以结合工作与-table,但不与-query。想一下这意味着什么,它需要解析查询的文本,并用两部分名称替换每个非限定表引用,但不包括已经包含两部分,三部分或四部分名称的表引用。与完全匹配后端的语法规则(本例中为SQL Server)。这是不可行的。

明确指定模式查询:

select BusinessEntityId, LoginID, cast(OrganizationNode as string) 
from HumanResources.Employee 
where ... 
+0

尝试HumanResources.Employee但仍失败。 ERROR manager.SqlManager:执行语句时出错:com.microsoft.sqlserver.jdbc.SQLServerException:类型字符串不是定义的系统类型。 – askdk

+0

是的,请使用有效的SQL Server语法。请参阅[Transact-SQL参考](https://docs.microsoft.com/en-us/sql/t-sql/language-reference)。在T-SQL中不存在类似'string'的CAST。 –

+0

糟糕!我的错! HumanResources.Employee是解决方案。只是没有意识到Binary在Parquet中不被支持。非常感谢! – askdk