1
votes

Sqoop import script:

sqoop import --connect jdbc:mysql://localhost/retail_db --username root --password cloudera --target-dir /user/cloudera/retail_db/products_test --table products --hive-import  --create-hive-table  --hive-table retail_db.products_test

After successful sqoop import and Hive table creation the location is /hive/warehouse/retail_db.db/products_test instead of /user/cloudera/retail_db/products_test

HIVE:

SHOW CREATE TABLE products_test;


CREATE TABLE `products_test`(
  `product_id` int, 
  `product_category_id` int, 
  `product_name` string, 
  `product_description` string, 
  `product_price` double, 
  `product_image` string)
COMMENT 'Imported by sqoop on 2017/07/05 05:52:43'
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' 
WITH SERDEPROPERTIES ( 
  'field.delim'='\u0001', 
  'line.delim'='\n', 
  'serialization.format'='\u0001') 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  'hdfs://quickstart.cloudera:8020/user/hive/warehouse/retail_db.db/products_test'
TBLPROPERTIES (
  'COLUMN_STATS_ACCURATE'='true', 
  'numFiles'='4', 
  'totalSize'='173993', 
  'transient_lastDdlTime'='1499259177')
Time taken: 0.892 seconds, Fetched: 25 row(s)
1

1 Answers

0
votes

the directory /user/cloudera is where data is imported and this will b picked up by hive and create table. So to create a Hive table in this directory u need to re-frame query like

sqoop import --connect jdbc:mysql://localhost/retail_db --username root --password cloudera --target-dir /user/cloudera/retail_db/products_test --table products --hive-import  --create-hive-table  --hive-table --warehouse-dir /user/cloudera retail_db.products_test

i have added the warehouse directory(--warehouse-dir ) option. Hope it helps.