简体   繁体   中英

sqoop to import data to hive

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?

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.

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM