Sqoop import --target-dir无法正常工作,而是将文件放在默认目录中

时间:2017-07-05 14:32:29

标签: hive sqoop

Sqoop导入脚本:

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

成功完成sqoop导入和Hive表创建后 位置是/hive/warehouse/retail_db.db/products_test而不是/ 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 个答案:

答案 0 :(得分:0)

目录/ user / cloudera是导入数据的地方,这将由hive和create table获取。因此,要在此目录中创建Hive表,您需要重新构建查询,如

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

我添加了仓库目录( - warehouse-dir)选项。希望它有所帮助。