1. 想用 sqoop 增量的方式導入到 hive。運行下面的命令:
sqoop import --connect jdbc:mysql://192.168.7.159:3306/test
--username root --password 123456
--query "select name, age, dept, update_dt from emp WHERE \$CONDITIONS"
--hive-import --hive-database default --hive-table emp_tmp
--target-dir /warehouse/tablespace/managed/hive/emp_tmp
--fields-terminated-by '\001' --incremental lastmodified
--check-column update_dt --last-value '2018-03-21' --append -m 1
錯誤提示: --incremental lastmodified option for hive imports is not supported
我暈, --incremental lastmodified 和 --hive-import 竟然不能同時使用。把 lastmodified 改成 append 后就可以運行了。看了 sqoop 的官方文檔,append 通常用於自增的 id 列,lastmodified 用於更新的日期列,日期同樣也可以比較大小啊,有點不明白為什么 lastmodified 不可以。
2. 上面命令中,如果去掉 “--hive-import --hive-database default --hive-table emp_tmp” 后,同樣可以導入數據,在 hive 中運行 select * from emp_tmp 可以看到有數據,但是運行 select count(1) from emp_tmp 出來的結果是 0
3. 上面命令中 “-m” 指定有多少個 map 任務,如果任務數大於 1,則需要額外指定 --split-by <分割列>
4. 用下面的命令可以創建一個 job。
sqoop job --create emp_job -- import
--connect jdbc:mysql://192.168.7.159:3306/test
--username root --password 123456
--query "select name, id, age, dept, update_tm from emp where \$CONDITIONS"
--target-dir /warehouse/tablespace/managed/hive/emp
--fields-terminated-by '\001' --hive-delims-replacement ' '
--null-string "" --null-non-string ""
--hive-import --hive-database default --hive-table emp
--incremental lastmodified --check-column update_tm --last-value '1980-01-01 00:00:00' --append -m 1
使用 sqoop job --exec emp_job 就可以進行一次導入了,sqoop 會自動記錄上一次的更新時間,用於替換以后跑這個 job 時 last-value 的值
5. 怎么查詢 sqoop 的 job 每次用到的 last-value 的值?
找到 metastore.db.script 這個文件所在的位置,打開它,搜索 incremental.last.value ,每個 job 都會對應一個。
find / -name metastore.db.script
2. 查詢表中的記錄時,出現 ORC split generation failed with exception: org.apache.orc.FileFormatException: Malformed ORC file 的異常

原因:HDP 的 hive 中設置了默認存儲格式為 ORC, 用 sqoop 增量方式導入 emp 表時,使用的是 textfile 的格式。所以查詢時就出現這個問題。很奇怪,sqoop 可以指定 avro,parquet 等格式,唯獨沒有 ORC 格式。
