sqoop import -D oracle.sessionTimeZone=CST --connect jdbc:oracle:thin:@192.168.78.6:1521:hexel \
--username TRX --table SQOOP -m 1 --password trx --warehouse-dir /xtld/data/gj/SQOOP \
--hive-import --create-hive-table --hive-database gj --hive-table SQOOP \
--as-textfile --append --fields-terminated-by '\t' \
--hive-drop-import-delims --compress --null-string '\\N' --null-non-string '\\N' \
--map-column-hive SCORE=bigint
-D,用于設定oracle的一些特性,這裡設定了時區
--warehouse-dir路徑,臨時存放hdfs路徑,與--target-dir不相容
--hive-import,表示把資料導入hive
--create-hive-table 建立表,第二次導入時,不要指定,否則導入失敗
--hive-database,指定hive資料庫名
--hive-table,指定導入到某個表,預設表名與源表名字一樣,表名要大寫
--as-textfile,表示導出成文本檔案,這是預設檔案格式
--fields-terminated-by,指定字段之間的分隔符,預設是',',字段分隔符可選如下:
簡單的字元:(--fields-terminated-by X)
轉義字元:(--fields-terminated-by \t). 支援的轉義字元如下:
\b (backspace)
\n (newline)
\r (carriage return)
\t (tab)
\" (double-quote)
\\' (single-quote)'
\\ (backslash)
\0 (NUL) - This will insert NUL characters between fields or lines, or will disable enclosing/escaping if used for one of the --enclosed-by, --optionally-enclosed-by, or --escaped-by arguments.
八進制數字表示的字元:
The octal representation of a UTF-8 character’s code point. This should be of the form \0ooo, where ooo is the octal value. For example, --fields-terminated-by \001 would yield the ^A character.
utf-8字元編碼表示的字元:
The hexadecimal representation of a UTF-8 character’s code point. This should be of the form \0xhhh, where hhh is the hex value. For example, --fields-terminated-by \0x10 would yield the carriage return character.
--map-column-hive 自定列類型,注意列名要大寫
--hive-delims-replacement,可以使用--hive-delims-replacement替換特殊字元。使用預設定界符時才生生效.
--hive-drop-import-delims 如果記錄總包含了\n,\r,\ 等字元,可能會導緻彙入不準确,使用這個選項可以删除特殊字元,使用預設定界符時這個選項才生效
--compress,表示壓縮導入,注意,壓縮後的檔案impala不支援.
--null-string,使用\N表示空字元
--null-non-string,使用\N表示空字元
--enclosed-by,字段包圍符,預設沒有包圍符
--escaped-by,轉義字元預設沒有轉義字元
--lines-terminated-by,行分隔符,預設是\n
--hive-partition-key and --hive-partition-value,分區相關
注意:
(1)把資料導入到hive時,不要使用,--escaped-by和--enclosed-by,如果記錄中有特殊字元,可能會導緻彙入結果不正确
(2)如果沒有指定delimiter,hive預設會使用^A作為字段定界符,使用\n最為記錄定界符