`
MyEyeOfJava
  • 浏览: 1163051 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
7af2d6ca-4fe1-3e9a-be85-3f65f7120bd0
测试开发
浏览量:71585
533896eb-dd7b-3cde-b4d3-cc1ce02c1c14
晨记
浏览量:0
社区版块
存档分类
最新评论

[Hadoop]Sqoop 1.4.2中文文档(三)之SqoopJob与其外的操作

阅读更多
一、sqoop job相关命令参数
usage: sqoop job [GENERIC-ARGS] [JOB-ARGS] [-- [<tool-name>] [TOOL-ARGS]]

Job management arguments:
   --create <job-id>            Create a new saved job
   --delete <job-id>            Delete a saved job
   --exec <job-id>              Run a saved job
   --help                       Print usage instructions
   --list                       List saved jobs
   --meta-connect <jdbc-uri>    Specify JDBC connect string for the
                                metastore
   --show <job-id>              Show the parameters for a saved job
   --verbose                    Print more information while working

Generic Hadoop command-line arguments:
(must preceed any tool-specific arguments)
Generic options supported are
-conf <configuration file>     specify an application configuration file
-D <property=value>            use value for given property
-fs <local|namenode:port>      specify a namenode
-jt <local|jobtracker:port>    specify a job tracker
-files <comma separated list of files>    specify comma separated files to be copied to the map reduce cluster
-libjars <comma separated list of jars>    specify comma separated jar files to include in the classpath.
-archives <comma separated list of archives>    specify comma separated archives to be unarchived on the compute machines.


简单第一眼望去,终于比导入和导出的参数少了很多,自然内容好说一些。

Job存在的目的,是对频繁只用不变化的导入导出工作做自动化处理,例如创建一个Job每天做增量导入,导入最新的数据,这样的任务就可以使用Job来进行。

举个例子:
创建一个Job
$ sqoop job --create myjob -- import --connect jdbc:mysql://example.com/db \
    --table mytable


查询当前Job列表
$ sqoop job --list
Available jobs:
  myjob


查看某个Job的详情:
 $ sqoop job --show myjob
 Job: myjob
 Tool: import
 Options:
 ----------------------------
 direct.import = false
 codegen.input.delimiters.record = 0
 hdfs.append.dir = false
 db.table = mytable
 ...


执行某个Job:
$ sqoop job --exec myjob
10/08/19 13:08:45 INFO tool.CodeGenTool: Beginning code generation
...

执行时重写相关参数,例如你数据库的用户名和密码改变了:
$ sqoop job --exec myjob -- --username someuser -P
Enter password:
...


拥有--meta-connect私有存储空间的hadoop机器才能进行job操作,否则将会报如下错误:
[work@vm-nba01 ~]$ sqoop job --list
12/10/24 16:38:34 ERROR tool.JobTool: There is no JobStorage implementation available
12/10/24 16:38:34 ERROR tool.JobTool: that can read your specified storage descriptor.
12/10/24 16:38:34 ERROR tool.JobTool: Don't know where to save this job info! You may
12/10/24 16:38:34 ERROR tool.JobTool: need to specify the connect string with --meta-connect.

也就是说机器不知道你要的Job保存在哪里了,所以关于一切Job的操作都是徒劳的。

二、Metastore connection options
上面Joblist出错的问题这里就可以解决了,这里可以教你怎么创建Job的存储空间,相关参数:
Argument	 Description
--meta-connect <jdbc-uri>	 Specifies the JDBC connect string used to connect to the metastore


默认你会在$HOME/.sqoop目录下有一个私有的数据存储,你通过sqoop-metastore命令可以使用热数据存储来建立空间
By default, a private metastore is instantiated in $HOME/.sqoop. If you have configured a hosted metastore with the sqoop-metastore tool, you can connect to it by specifying the --meta-connect argument. This is a JDBC connect string just like the ones used to connect to databases for import.

In conf/sqoop-site.xml, you can configure sqoop.metastore.client.autoconnect.url with this address, so you do not have to supply --meta-connect to use a remote metastore. This parameter can also be modified to move the private metastore to a location on your filesystem other than your home directory.

If you configure sqoop.metastore.client.enable.autoconnect with the value false, then you must explicitly supply --meta-connect.(上述位置待以后实际操作后再翻译)

找到sqoop-site.xml的配置文件,发现如下配置:
<property>
    <name>sqoop.metastore.client.enable.autoconnect</name>
    <value>false</value>
    <description>If true, Sqoop will connect to a local metastore
      for job management when no other metastore arguments are
      provided.
    </description>
  </property>

看来这个值设置为了false,导致不能够使用Job相关操作了。

<property>
    <name>sqoop.metastore.client.record.password</name>
    <value>true</value>
    <description>If true, allow saved passwords in the metastore.
    </description>
  </property>

当这个值为真的时候才会保存密码。

sqoop-metastore命令可以检查你配置sqoop数据连接的正确性,当然这些配置还是在sqoop-site.xml中。

sqoop-merge命令可以允许你合并2个数据集到1个数据集。merge命令的相关参数:
Argument	 Description
--class-name <class>	 Specify the name of the record-specific class to use during the merge job.
--jar-file <file>	 Specify the name of the jar to load the record class from.
--merge-key <col>	 Specify the name of a column to use as the merge key.
--new-data <path>	 Specify the path of the newer dataset.
--onto <path>	         Specify the path of the older dataset.
--target-dir <path>	 Specify the target path for the output of the merge job.


举例:
$ sqoop merge --new-data newer --onto older --target-dir merged \
    --jar-file datatypes.jar --class-name Foo --merge-key id

这样就会运行一个MapReduce的任务,新的数据集使用优先度高于老的数据集。
它能被使用在both SequenceFile-, Avro- and text-based incremental imports.并且新老的数据类型时相同的。

sqoop-codegen命令可以还原的你的java类,如果你的源码java丢失了,但是数据没有丢失,可以使用这样的命令:
$ sqoop codegen --connect jdbc:mysql://db.example.com/corp \
    --table employees


sqoop-create-hive-table可以创建一个Hive表,复制某一个数据源的数据存储格式,例如:
$ sqoop create-hive-table --connect jdbc:mysql://db.example.com/corp \
    --table employees --hive-table emps


sqoop-eval命令可以让用户快速做一个操作,结果显示在控制台中。例如:
$ sqoop eval --connect jdbc:mysql://db.example.com/corp \
    --query "SELECT * FROM employees LIMIT 10"

$ sqoop eval --connect jdbc:mysql://db.example.com/corp \
    -e "INSERT INTO foo VALUES(42, 'bar')"


sqoop-list-databases查看某个数据源的数据库列表,例如:
$ sqoop list-databases --connect jdbc:mysql://database.example.com/
information_schema
employees


sqoop-list-tables查看某个数据源的表列表,例如:
$ sqoop list-tables --connect jdbc:mysql://database.example.com/corp
employees
payroll_checks
job_descriptions
office_supplies


sqoop现在支持的数据库:
Database	 version	--direct support?	 connect string matches
HSQLDB	 1.8.0+	 No	jdbc:hsqldb:*//
MySQL	 5.0+	 Yes	jdbc:mysql://
Oracle	 10.2.0+	 No	jdbc:oracle:*//
PostgreSQL	 8.3+	 Yes (import only)	jdbc:postgresql://
分享到:
评论

相关推荐

    sqoop-1.4.2.bin__hadoop-2.0.0-alpha.tar

    这个压缩包 "sqoop-1.4.2.bin__hadoop-2.0.0-alpha.tar" 提供的是 Sqoop 1.4.2 版本,适用于与 Hadoop 2.0.0-alpha 版本集成。以下是对这个版本 Sqoop 的详细介绍以及相关的知识点: 1. **Sqoop 的作用**:Sqoop 是...

    第9章 Sqoop组件安装配置.docx

    实验任务三:启动 Sqoop 启动 Sqoop 服务,使用以下命令: `[root@master ~]# sqoop` ### 1.4.4. 实验任务四:Sqoop 模板命令 Sqoop 提供了多种模板命令,用于数据传输。用户可以使用以下命令来查看 Sqoop 的...

    Hadoop权威指南 第二版(中文版)

     本书从Hadoop的缘起开始,由浅入深,结合理论和实践,全方位地介绍Hadoop这一高性能处理海量数据集的理想工具。全书共16章,3个附录,涉及的主题包括:Haddoop简介;MapReduce简介;Hadoop分布式文件系统;Hadoop...

    Hadoop权威指南(中文版)2015上传.rar

    第1章 初识Hadoop 数据!数据! 数据存储与分析 与其他系统相比 关系型数据库管理系统 网格计算 志愿计算 1.3.4 Hadoop 发展简史 Apache Hadoop和Hadoop生态圈 第2章 关于MapReduce 一个气象数据集 数据的格式 使用...

    12_离线计算系统_第12天(辅助系统).docx

    1.4.2 Sqoop 导入示例 导入 MySQL 数据库中的 `mytable` 到 HDFS 的 `/user/hadoop/data/imported` 目录下: ```bash sqoop import \ --connect jdbc:mysql://localhost/mydb \ --table mytable \ --target-dir /...

Global site tag (gtag.js) - Google Analytics