分享

sqoop2如何指定字段导出

feature09 发表于 2017-8-23 16:49:37 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 6 11174
从MySQL导出数据到HDFS上
如何指定字段?
是sqoop1.99.7版本。

sqoop2用的真纠结

已有(6)人评论

跳转到指定楼层
nextuser 发表于 2017-8-23 19:44:42
本帖最后由 nextuser 于 2017-8-23 19:45 编辑

这个应该是可以设置。由于没有环境,我这里只是贴出,楼主自己测试下。
sqoop:000> help
For information about Sqoop, visit: http://sqoop.apache.org/

Available commands:
  exit    (\x  ) Exit the shell
  history (\H  ) Display, manage and recall edit-line history
  help    (\h  ) Display this help message
  set     (\st ) Configure various client options and settings
  show    (\sh ) Display various objects and configuration options
  create  (\cr ) Create new object in Sqoop repository
  delete  (\d  ) Delete existing object in Sqoop repository
  update  (\up ) Update objects in Sqoop repository
  clone   (\cl ) Create new object based on existing one
  start   (\sta) Start job
  stop    (\stp) Stop job
  status  (\stu) Display status of a job
  enable  (\en ) Enable object in Sqoop repository
  disable (\di ) Disable object in Sqoop repository

上面应该可以通过set来设置。
#########################
下面是创建job,如下面红字部分,是可选的

create job -f 3 -t 4
Creating job for links with from id 3 and to id 4
Please fill following values to create new job object
Name: testsqoop    #Name必须唯一

From database configuration

Schema name: mytest                     #必填,数据库名称
Table name: balance                          #必填,表名
Table SQL statement:                           #可选
Table column names:                                     #可选
Partition column name:                                 #可选
Null value allowed for the partition column:      #可选
Boundary query:                        #可选

Incremental read

Check column:                         #可选
Last value:                          #可选

To HDFS configuration

Override null value:                    #可选
Null value:
Output format:
  0 : TEXT_FILE
  1 : SEQUENCE_FILE
Choose: 0                           #必选
Compression format:
  0 : NONE
  1 : DEFAULT
  2 : DEFLATE
  3 : GZIP
  4 : BZIP2
  5 : LZO
  6 : LZ4
  7 : SNAPPY
  8 : CUSTOM
Choose: 0                               #必选
Custom compression format:
Output directory: /user/ubuntu/lucius/new_balance   #必填
Append mode:

Throttling resources

Extractors: 2                            #可选,对应mapreduce的job中的map的数量
Loaders: 1                              #可选,对应mapreduce的job中的reduce的数量
New job was successfully created with validation status OK  and persistent id 5        







回复

使用道具 举报

feature09 发表于 2017-8-23 20:04:59
nextuser 发表于 2017-8-23 19:44
这个应该是可以设置。由于没有环境,我这里只是贴出,楼主自己测试下。
sqoop:000> help
For information ...

Table SQL statement:                           #可选这个我一直没弄明白。我直接添加的条件,
如id<=3,出错;
如where id<=3,出错;
直接写sql语句也是出错的。
所以后来,就直接回车了。
Table column names:                                     #可选
这个选项选不了,是出现element# 回车后出来的内容。
不明白这个是什么意思。

Partition column name:                                 #可选
这个当时选择了一个area的分区。
这个虽然出错了,但是也出了结果,最后的结果出现了好多的重复数据。
我的map和reduce的数量都已经调整为5:4了,我感觉是Map数量少的问题。。。纯是感觉,等着明天上班再测试。
Null value allowed for the partition column:      #可选

这个不知道代表的含义。。。
回复

使用道具 举报

nextuser 发表于 2017-8-23 20:15:09
feature09 发表于 2017-8-23 20:04
Table SQL statement:                           #可选这个我一直没弄明白。我直接添加的条件,
如id

其实大的方向已经确定的,剩下的楼主只能试验了。官网似乎也没有。
Table SQL statement:                           #可选这个我一直没弄明白。我直接添加的条件,
这个是表sql数据,应该不用加条件。如果实在不行,忽略应该也没有问题。

Table column names:                                     #可选
这个应该是字段的选择。就是指定字段

Partition column name:                                 #可选
这个应该是分区字段
Null value allowed for the partition column:      #可选

这个应该是对空值的处理
回复

使用道具 举报

feature09 发表于 2017-8-23 23:36:45
nextuser 发表于 2017-8-23 20:15
其实大的方向已经确定的,剩下的楼主只能试验了。官网似乎也没有。
Table SQL statement:               ...

嗯嗯,谢谢。

回复

使用道具 举报

desehawk 发表于 2017-8-28 15:19:35
楼主可参考下面

1.表名和表的sql statement是互斥的。配置了表名,就不用配置表的sql statement。配置了表的sql statement,就不用配置表名。
2.只有配置了表名,才可以配置表的列名。

FROM作业涉及的输入包括:
Input        
Type        
Description        Example
Schema nameString可选。作为表的一部分,表中不可或缺的模式名sqoop
Table nameString可选。从该表名导入数据。参考以下注意点。test
Table SQL statementString可选。用于执行任意形式查询的sql statement。SELECT COUNT(*) FROM test ${CONDITIONS}
Table column namesString可选。从jdbc数据源要抽取的列。列之间用逗号隔开。col1,col2
Partition column nameMap可选。根据该列名将数据传输进程进行分区。默认选择主键的第一列。col1
Null value allowed for the partition columnBoolean可选。根据分区列是否允许有null值来选择true 或 false 。true
Boundary queryString可选。用于分区时定义上下界的查询。


来自:
sqoop2系统入门之3:用户指南通用JDBC连接器
http://www.aboutyun.com/forum.php?mod=viewthread&tid=22563


回复

使用道具 举报

feature09 发表于 2017-8-28 18:35:08
desehawk 发表于 2017-8-28 15:19
楼主可参考下面

1.表名和表的sql statement是互斥的。配置了表名,就不用配置表的sql statement。配置了 ...

我选择的是,填了两个,在SQL statement这个地方回车后,直接略过了列名那。Schema name: test1
Table name: tb_user
SQL statement:
Column names:

There are currently 0 values in the list:
element# ————————>然后直接就跳到这项了。配置不了列名。


Schema name和Table name官网定义的是必选的。
Schema name:(Required)sqoop  Table name:(Required)sqoop  Table SQL statement:(Optional)  Table column names:(Optional)  Partition column name:(Optional) id  Null value allowed for the partition column:(Optional)  Boundary query:(Optional)
一直没查到关于sqoop2的实际案例。要是有实际案例就好了,官网的那个5分钟案例太简单了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条