Apache Sqoop Cookbook 英文版-翻译学习!!
sqoop 主要的命令
19/05/31 05:49:02 INFO sqoop.Sqoop: Running Sqoop version: 1.4.5.2.2.4.2-2
usage: sqoop COMMAND [ARGS]
Available commands:
codegen Generate code to interact with database records
create-hive-table Import a table definition into Hive
eval Evaluate a SQL statement and display the results
export Export an HDFS directory to a database table
help List available commands
import Import a table from a database to HDFS
import-all-tables Import tables from a database to HDFS
job Work with saved jobs
list-databases List available databases on a server
list-tables List available tables in a database
merge Merge results of incremental imports
metastore Run a standalone Sqoop metastore
version Display version information
See 'sqoop help COMMAND' for information on a specific command.
问题
上一节使用的例子能够很好的工作,这可以让你决定将Sqoop整合到Hadoop的数据工作流中。
为了能够做到这点,需要指定一个目录来存放导入的数据。
解决方案
Sqoop提供了两个参数用来指定自定义输出路径。
--target-dir 和 --warehouse-dir ,使用 --target-dir 参数用来指定数据将要导入到的HDFS的路径上. 如 使用以下命令将cities表数据导入到目录 /etc/input/cities。
sqoop import \
--connect jdbc:mysql://localhost:3306/sqoop \
--username sqoop \
--password sqoop \
--table cities \
--target-dir /etl/input/cities
指定所有sqoop任务的父目录的方法,使用 --warehouse-dir 参数
sqoop import \
--connect jdbc:mysql://localhost:3306/sqoop \
--username sqoop \
--password sqoop \
--table cities \
--warehouse-dir /mydir/input
讨论
默认情况下,sqoop将会创建一个和导入表名相同的目录在HDFS上,并将全部的数据到这个目录中。举例来说
当用户jarcec导入表cities时,数据将会被导入到/user/jarcec/cities目录下。而这个目录替换成在HDFS上的
任意的目录通过使用参数--target-dir,前提条件是这个目录需要事先创建好。
对于已经存在的目录,Sqoop会拒绝写入,以防止数据覆盖而产生问题。

如果想对多个表执行sqoop作业,需要修改 --target-dir 参数
相比直接指定最终的存储路径,使用 --warehouse-dir 可以用来指定一个父目录,这样不仅仅是将数据写入到
warehouse目下,sqoop还会创建一个
和表同名的文件夹,并且将数据导入到这个文件夹下,这种情况有点像是sqoop将数据导入到你HDFS系统下的家目录下。但需要注意的是 --warehouse-dir 参数允许使用除家目录以外的路径,还有一点需要提醒的是,使用这个
参数时不需要改变每个表名,除非有同名的表。
网友评论