Sqoop工具使用(一)--从oracle导入数据到hive

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最为记录定界符
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值