Chinaunix首页 | 论坛 | 博客
  • 博客访问: 427301
  • 博文数量: 55
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1584
  • 用 户 组: 普通用户
  • 注册时间: 2013-05-04 15:15
个人简介

热衷技术,热爱交流

文章分类

全部博文(55)

文章存档

2014年(7)

2013年(48)

分类: HADOOP

2014-04-11 14:12:53

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最为记录定界符
阅读(8100) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~