sqoop to import data to hive

2019-09-04 05:14发布

问题:

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