Chapter 5 / 第 5 章
- A saved job has kept all the information for executing a specified sqoop command, once a saved job is created, it can be executed at any time you want.
- 保存的作业保留了执行指定 Sqoop 命令的所有信息,一旦创建了保存的作业,您可以在任何时候执行它。
- By default, job descriptions are saved to a private repository stored in $HOME/.sqoop/.
- 默认情况下,作业描述保存在存储于 $HOME/.sqoop/ 的私有存储库中。
- You can configure Sqoop to instead use a shared metastore, which makes saved jobs available to multiple users across a shared cluster.
- 您可以配置 Sqoop 改为使用共享元存储,这使得保存的作业可供共享集群中的多个用户使用。
- Syntax: sqoop job (generic-args) (job-args) [– [subtool-name (subtool-args)]
- 语法:sqoop job (通用参数) (作业参数) [– [子工具名称 (子工具参数)]
- Job management options:
- 作业管理选项:
| Argument | Description | 说明 |
|---|---|---|
| --create <job-id> | Define a new saved job with the specified job-id (name). A second Sqoop command-line, separated by a -- should be specified; this defines the saved job. | 定义一个具有指定作业 ID(名称)的新保存作业。应指定由 -- 分隔的第二个 Sqoop 命令行;这定义了保存的作业。 |
| --delete <job-id> | Delete a saved job. | 删除一个保存的作业。 |
| --exec <job-id> | Given a job defined with --create, run the saved job. | 给定一个用 --create 定义的作业,运行该保存的作业。 |
| --show <job-id> | Show the parameters for a saved job. | 显示保存作业的参数。 |
| -list | List all saved jobs | 列出所有保存的作业 |
- Creating saved jobs is done with the --create action. Consider:
- 创建保存的作业是通过 --create 操作完成的。例如:
sqoop job --create myjob import --connect jdbc:mysql://example.com/db --table mytable
- And if we are satisfied with it, we can run the job with --exec:
- 如果我们对它满意,我们可以使用 --exec 运行该作业:
sqoop job --exec myjob
- Metastore connection options:
- 元存储连接选项:
| Argument | Description | 说明 |
|---|---|---|
| --meta-connect <jdbc-uri> | Specifies the JDBC connect string used to connect to the metastore | 指定用于连接到元存储的 JDBC 连接字符串 |
- The metadata repository can be configured in conf/sqoop-site.xml files, and the metadata is by default stored in HSQLDB memory-level database, the location of the metastore’files on disk is controlled by the sqoop.metastore.server.location property. This should point to a directory on the local filesystem.
- 元数据存储库可以在 conf/sqoop-site.xml 文件中配置,元数据默认存储在 HSQLDB 内存级数据库中,元存储文件在磁盘上的位置由 sqoop.metastore.server.location 属性控制。这应该指向本地文件系统上的一个目录。
- The metastore is available over TCP/IP, and the default port number is 16000, which can be controlled by the sqoop.metastore.server.port property.
- 元存储可通过 TCP/IP 访问,默认端口号为 16000,这可以通过 sqoop.metastore.server.port 属性控制。
- You can specify how to connect to the metastore service by the --meta-connect property: for example:
- 您可以通过 --meta-connect 属性指定如何连接到元存储服务:例如:
--meta-connect jdbc:hsqldb:hsql://metaserver.example.com:16000/sqoop
If you want to automatically connect to the metadata repository without specifying the --meta-connect option, you can use the sqoop.metastore.client.enable.autoconnect property in sqoop-site.xml and give it a true value, and set the sqoop.metastore.client.autoconnect.url property to a correct url address. If the value of the sqoop.metastore.client.autoconnect.url is not specified, the private metadata repository will be used and metastore’s files are located at $HOME/.sqoop/ by default.
- 如果您想在不指定 --meta-connect 选项的情况下自动连接到元数据存储库,您可以在 sqoop-site.xml 中使用 sqoop.metastore.client.enable.autoconnect 属性并将其设为 true,并将 sqoop.metastore.client.autoconnect.url 属性设置为正确的 url 地址。如果未指定 sqoop.metastore.client.autoconnect.url 的值,将使用私有元数据存储库,并且元存储的文件默认位于 $HOME/.sqoop/。
The Sqoop Metadata Service can be started and shut down by using the sqoop-metastore tool.
- 可以使用 sqoop-metastore 工具启动和关闭 Sqoop 元数据服务。
a. Start-up the metastore service: sqoop metastore
- 启动元存储服务:sqoop metastore
b. Shutdown the metastore service: sqoop metastore shutdown
- 关闭元存储服务:sqoop metastore shutdown
SQOOP Merge Tool / SQOOP 合并工具
- The merge tool allows you to combine two datasets where entries in one dataset should overwrite entries of an older dataset.
- 合并工具允许您组合两个数据集,其中一个数据集中的条目应覆盖较旧数据集中的条目。
- Syntax: sqoop merge (generic-args) (merge-args)
- 语法:sqoop merge (通用参数) (合并参数)
- Merge options:
- 合并选项:
| 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. | 指定从中加载记录类的 jar 的名称。 |
| -merge-key <col> | Specify the name of a column to use as the merge key. (PK) | 指定用作合并键的列名。(主键) |
| --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. | 指定合并作业输出的目标路径。 |
- The merge tool runs a MapReduce job that takes two directories as input: a newer dataset, and an older one.
- 合并工具运行一个 MapReduce 作业,该作业将两个目录作为输入:一个较新的数据集和一个较旧的数据集。
- These are specified with --new-data and --onto respectively.
- 这些分别通过 --new-data 和 --onto 指定。
- The output of the MapReduce job will be placed in the directory in HDFS specified by --target-dir.
- MapReduce 作业的输出将放置在由 --target-dir 指定的 HDFS 目录中。
- When merging the datasets, it is assumed that there is a unique primary key value in each record.
- 合并数据集时,假设每条记录中都有一个唯一的主键值。
- The column for the primary key is specified with --merge-key.
- 主键的列由 --merge-key 指定。
- Multiple rows in the same dataset should not have the same primary key, or else data loss may occur.
- 同一数据集中的多行不应具有相同的主键,否则可能会发生数据丢失。
- The merge tool is typically run after an incremental import with the date-last-modified mode (sqoop import --incremental lastmodified…) to merge the newly imported data onto the old data.
- 合并工具通常在执行最后修改日期模式的增量导入(sqoop import --incremental lastmodified…)之后运行,以将新导入的数据合并到旧数据上。
SQOOP Code Generation Tool / SQOOP 代码生成工具
- Sqoop automatically generates code to parse and interpret records of the files containing the data to be exported back to the database.
- Sqoop 自动生成代码来解析和解释包含要导出回数据库的数据的文件记录。
- If these files were created with non-default delimiters (comma-separated fields with newline-separated records), you should specify the same delimiters again so that Sqoop can parse your files.
- 如果这些文件是使用非默认分隔符(逗号分隔字段,换行符分隔记录)创建的,您应该再次指定相同的分隔符,以便 Sqoop 可以解析您的文件。
- Code generation arguments for sqoop-import or sqoop-export tool:
- sqoop-import 或 sqoop-export 工具的代码生成参数:
| Argument | Description | 说明 |
|---|---|---|
| --bindir <dir> | Output directory for compiled objects | 编译对象的输出目录 |
| --class-name <name> | Sets the generated class name. This overrides -package-name. When combined with-jar-file, sets the input class. | 设置生成的类名。这将覆盖 -package-name。当与 -jar-file 结合使用时,设置输入类。 |
| --jar-file <file> | Disable code generation; use specified jar | 禁用代码生成;使用指定的 jar |
| --outdir <dir> | Output directory for generated code | 生成代码的输出目录 |
| --package-name <name> | Put auto-generated classes in this package | 将自动生成的类放入此包中 |
| --map-column-java <m> | Override default mapping from SQL type to Java type for configured columns. | 覆盖配置列的 SQL 类型到 Java 类型的默认映射。 |
- The generated class name is typically the same as the table name, you can also specify it by using --class-name option. Similarly, you can specify just the package name with --package-name option.
- 生成的类名通常与表名相同,您也可以使用 --class-name 选项指定它。同样,您可以使用 --package-name 选项仅指定包名。
a. sqoop import --connect <connect-str> --table SomeTable --package-name com.foocorp
- The java source file for your class will be written to the current working directory where you run sqoop. You can control the output directory with --outdir. For example:
- 您的类的 java 源文件将被写入您运行 sqoop 的当前工作目录。您可以使用 --outdir 控制输出目录。例如:
a. --outdir src/generated
- The import process compiles the source into class and jar files; these are ordinarily stored under /tmp. You can select an alternate target directory with --bindir.
- 导入过程将源代码编译成 class 和 jar 文件;这些通常存储在 /tmp 下。您可以使用 --bindir 选择备用目标目录。
- If you already have a compiled class that can be used to perform the import and want to suppress the code-generation aspect of the import process, you can use an existing jar and class by providing the --jar-file and --class-name options.
- 如果您已经有一个可用于执行导入的编译类,并且希望抑制导入过程的代码生成方面,您可以通过提供 --jar-file 和 --class-name 选项来使用现有的 jar 和类。
- Note that the --update-key option cannot be used with the --jar-file and --class-name options because the update mode export must be parsed using the newly generated code.
- 请注意,–update-key 选项不能与 --jar-file 和 --class-name 选项一起使用,因为更新模式导出必须使用新生成的代码进行解析。
- If the generated code is missing, you can use the Sqoop code generation tool(sqoop-codegen) to regenerate it.
- 如果生成的代码丢失,您可以使用 Sqoop 代码生成工具 (sqoop-codegen) 重新生成它。
Hive arguments / Hive 参数:
- If Hive arguments are provided to the code generation tool, Sqoop generates a file containing the HQL statements to create a table and load data.
- 如果向代码生成工具提供了 Hive 参数,Sqoop 将生成一个包含创建表和加载数据的 HQL 语句的文件。
- Recreate the record interpretation code for the employees table of a corporate database:
- 为公司数据库的 employees 表重新创建记录解释代码:
a. sqoop codegen --table employees --connect jdbc:mysql://db.foo.com/c
SQOOP Create HIVE Table Tool / SQOOP 创建 HIVE 表工具
- The create-hive-table tool populates a Hive metastore with a definition for a table based on a database table. This effectively performs the “–hive-import” step of sqoop-import without running the preceding import.
- create-hive-table 工具根据数据库表在 Hive 元存储中填充表的定义。这有效地执行了 sqoop-import 的 “–hive-import” 步骤,而无需运行前面的导入。
- Syntax: sqoop create-hive-table (generic-args) (create-hive-table-args)
- 语法:sqoop create-hive-table (通用参数) (create-hive-table 参数)
- Note that the new Hive table will be created under the Hive’s default database named default.
- 请注意,新的 Hive 表将在名为 default 的 Hive 默认数据库下创建。
- To create it under a specified Hive database, such as hivedb, you can specify it with --hive-table hivedb.emps, or use --hive-database hivedb to specify the name of the imported Hive database separately.
- 要在指定的 Hive 数据库(如 hivedb)下创建它,您可以使用 --hive-table hivedb.emps 指定它,或者使用 --hive-database hivedb 单独指定导入的 Hive 数据库的名称。
SQOOP Evaluation Tool / SQOOP 评估工具
- The eval tool allows users to quickly run simple SQL queries against a database; results are printed to the console.
- eval 工具允许用户针对数据库快速运行简单的 SQL 查询;结果将打印到控制台。
- Syntax: sqoop eval (generic-args) (eval-args)
- 语法:sqoop eval (通用参数) (eval 参数)