sqoop to import data to hive

≡放荡痞女 提交于 2019-12-12 01:22:15

问题


i am trying to import data to hive table using sqoop2. I am using --hive-import but it is not working

Code:

sqoop import --connect jdbc:sqlserver://192.168.x.xxx:11xx --username user --password user --table xxxx.NOTIFICATION --hive-import

Error:

ERROR manager.SqlManager: Error executing statement: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'XXXX.NOTIFICATION'.

What am I doing wrong?


回答1:


Below observations are based on Sqoop 1.4.6

you are using . (dot) in your table name.

Internally, Sqoop will fire command

SELECT t.* FROM xxxx.NOTIFICATION AS t WHERE 1=0

to fetch metadata of your SQL Server table.

This command is interpreted as

  • xxxx - schame name
  • NOTIFICATION - Table name

To avoid this you can use escape character ( [ ] in case of SQL Server):

sqoop import --connect jdbc:sqlserver://192.168.x.xxx:11xx --username user --password user --table [xxxx.NOTIFICATION] --hive-import

This will generate

SELECT t.* FROM [xxxx.NOTIFICATION] AS t WHERE 1=0

Now xxxx.NOTIFICATION will be treated as table name.




回答2:


Hi after doing a bit research and discussing on the question with @dev i found the solution.

I am using sqoop2 so i changed my command and used below one and it worked for me.

$ sqoop import --connect "jdbc:sqlserver://192.168.x.xxx:11xx;database=SSSS;username=user;password=user" --query "SELECT * FROM xxxx.NOTIFICATION where \$CONDITIONS" --split-by xxxx.NOTIFICATION.ID --hive-import --hive-table NOTIFICATION  --target-dir NOTIFICATION 

before executing this command we should create table in hive using create command. Here i have created hive table named NOTIFICATION.




回答3:


I assume the table name is NOTIFICATION and you are trying to mention database name xxxx when you write --table xxxx.NOTIFICATION

If this is the case, can you please try the below mentioned syntax instead?

sqoop import --connect jdbc:sqlserver://192.168.x.xxx:11xx;databaseName=xxxx --username user --password user --table NOTIFICATION --hive-import


来源:https://stackoverflow.com/questions/39142141/sqoop-to-import-data-to-hive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!