2015-03-19 41 views
0

我可以使用sqoop導入RDBMS表數據(表沒有主鍵)以使用sqoop?如果是的話,你可以請給出sqoop導入命令,在RDBMS中沒有主鍵的sqoop導入

我試過用sqoop導入一般命令但失敗了。

在此先感謝

PK

回答

5

如果你的表中有定義,那麼你必須給-m 1選項導入數據,或者你必須提供--split-by爭論一些列名沒有主鍵,否則其給出錯誤:

ERROR tool.ImportTool: Error during import: No primary key could be found for table <table_name>. Please specify one with --split-by or perform a sequential import with '-m 1' 

那麼你sqoop命令看起來像

sqoop import \ 
    --connect jdbc:mysql://localhost/test_db \ 
    --username root \ 
    --password **** \ 
    --table user \ 
    --target-dir /user/root/user_data \ 
    --columns "first_name, last_name, created_date" 
    -m 1 

sqoop import \ 
    --connect jdbc:mysql://localhost/test_db \ 
    --username root \ 
    --password **** \ 
    --table user \ 
    --target-dir /user/root/user_data \ 
    --columns "first_name, last_name, created_date" 
    --split-by created_date 
1

在使用1映射第一個場景......如果這個文件的大小是非常大的這個過程將需要更多的時間來響應或可能會失敗。在使用mapper = 1之前檢查數據的大小。

1

您可以將數據從RDBMS導入到沒有主鍵的配置單元中。

首先,你需要創建一個hive.After表,你需要編寫以下代碼:

sqoop import \ 
    --connect jdbc:mysql://localhost/test_db \ 
    --username root \ 
    --password **** \ 
    --table <RDBMS-Table-name> \ 
    --target-dir /user/root/user_data \ 
    --hive-import \ 
    --hive-table <hive-table-name> \ 
    --create-hive-table \ 
    -m 1 (or) --split-by <RDBMS-Column>