Sqoop Hive 导入
Sqoop Hive import
我正在尝试将 table 从 MySql 数据库导入到配置单元 table 以了解配置单元如何导入 works.The table 名称是我的设备已经在 HDFS 的主目录中导入 HDFS。我使用以下语句在配置单元中创建了一个 table。
create table device_hive (device_num int,device_name varchar(255));
现在我正在执行下面的 sqoop import 语句以从 Mysql 数据库中的 device
table 获取数据到 Hive
sqoop import --connect jdbc:mysql://localhost/loudacre --table device
--username training --password training --hive-import --hive-table device_hive
--hive-database hadoopexam --hive-table device_hive --fields-terminated-by '[=11=]1'
--table device --columns "device_num,device_name"
错误消息中指出输出目录设备已经 exists.The 位置失败,指向我之前使用 sqoop 导入的 HDFS 中的 device
文件夹。
我的问题是为什么 sqoop 会转到基本目录并检查该文件夹。这是一个配置单元导入,所以 sqoop 不应该直接转到 hive/warehouse 目录吗?我从 HDFS 中删除了那个文件夹,它工作正常。任何建议。
By default, imports go to a new target location. If the destination
directory already exists in HDFS, Sqoop will refuse to import and
overwrite that directory’s contents.
因此,如果您已经将 table 导入 HDFS,则 device
目录已存在的错误将是正常行为。当您添加 --hive-import
命令时,Sqoop 将数据复制到 HDFS(在您的例子中,在 device
目录中)并使用数据的布局更新 Hive 元存储。
您可以使用 --hive-overwrite 选项来告诉 Sqoop 覆盖 table:
If the Hive table already exists, you can specify the --hive-overwrite
option to indicate that existing table in hive must be replaced.
希望对您有所帮助。
您需要了解 Sqoop 导入 hive 的工作原理。
分 3 个步骤进行:
- 导入数据到 HDFS (HOME_DIRECTORY/TABLE_NAME)
- 创建蜂巢TABLE.....
- 在路径中加载数据...
根据docs,
After your data is imported into HDFS or this step is omitted, Sqoop will generate a Hive script containing a CREATE TABLE operation defining your columns using Hive’s types, and a LOAD DATA INPATH statement to move the data files into Hive’s warehouse directory.
在您的情况下,第一步失败了。
使用导入控制参数--delete-target-dir
。如果存在,它将删除导入目标目录。
我正在尝试将 table 从 MySql 数据库导入到配置单元 table 以了解配置单元如何导入 works.The table 名称是我的设备已经在 HDFS 的主目录中导入 HDFS。我使用以下语句在配置单元中创建了一个 table。
create table device_hive (device_num int,device_name varchar(255));
现在我正在执行下面的 sqoop import 语句以从 Mysql 数据库中的 device
table 获取数据到 Hive
sqoop import --connect jdbc:mysql://localhost/loudacre --table device
--username training --password training --hive-import --hive-table device_hive
--hive-database hadoopexam --hive-table device_hive --fields-terminated-by '[=11=]1'
--table device --columns "device_num,device_name"
错误消息中指出输出目录设备已经 exists.The 位置失败,指向我之前使用 sqoop 导入的 HDFS 中的 device
文件夹。
我的问题是为什么 sqoop 会转到基本目录并检查该文件夹。这是一个配置单元导入,所以 sqoop 不应该直接转到 hive/warehouse 目录吗?我从 HDFS 中删除了那个文件夹,它工作正常。任何建议。
By default, imports go to a new target location. If the destination directory already exists in HDFS, Sqoop will refuse to import and overwrite that directory’s contents.
因此,如果您已经将 table 导入 HDFS,则 device
目录已存在的错误将是正常行为。当您添加 --hive-import
命令时,Sqoop 将数据复制到 HDFS(在您的例子中,在 device
目录中)并使用数据的布局更新 Hive 元存储。
您可以使用 --hive-overwrite 选项来告诉 Sqoop 覆盖 table:
If the Hive table already exists, you can specify the --hive-overwrite option to indicate that existing table in hive must be replaced.
希望对您有所帮助。
您需要了解 Sqoop 导入 hive 的工作原理。
分 3 个步骤进行:
- 导入数据到 HDFS (HOME_DIRECTORY/TABLE_NAME)
- 创建蜂巢TABLE.....
- 在路径中加载数据...
根据docs,
After your data is imported into HDFS or this step is omitted, Sqoop will generate a Hive script containing a CREATE TABLE operation defining your columns using Hive’s types, and a LOAD DATA INPATH statement to move the data files into Hive’s warehouse directory.
在您的情况下,第一步失败了。
使用导入控制参数--delete-target-dir
。如果存在,它将删除导入目标目录。