sqoop将数据导入hive和hdfs

gkl3eglg  于 2021-06-03  发布在  Sqoop
关注(0)|答案(2)|浏览(551)

我们可以用sqoop将数据导入hdfs和hive吗?我尝试了两个不同的用户(root和admin)在root和admin之间的命令下面
[根目录]

sqoop import --connect jdbc:mysql://10.6.162.58/test_alpha --username pbd -P --table posts --hive-import --hive-database test_root --hive-table posts1 --hive-drop-import-delims --null-string '\\N' --null-non-string '\\N' --target-dir test_hive_root/2

[管理员]

sqoop import --connect jdbc:mysql://10.6.162.58/test_alpha --username pbd -P --table posts --hive-import --hive-database test_admin --hive-table posts1 --hive-drop-import-delims --null-string '\\N' --null-non-string '\\N' --target-dir test_hive_admin/2

它返回:
两种方法都成功地将数据导入到配置单元,但都无法导入到hdfs。
对于root,它不会创建我定义的目录“test\u hive\u root/2”
对于admin,它只是创建目录“test\hive\u admin/2”,但只创建了“success”文件,而不是数据(通常当我将其导入hdfs时,它会创建“success”文件和4个以上的文件)
我怎样才能解决这个问题?sqoop可以导入到hdfs和hive吗?

3z6pesqy

3z6pesqy1#

target-dir 控制在加载到配置单元表之前需要临时存储数据的位置,但不在该位置创建配置单元表。
表是在中指定的目录中创建的 hive.metastore.warehouse.dir 中的属性 hive-site.xml .
如果要导入到特定目录,请使用 target-dir 没有 hive-import 参数并在hdfs目录顶部创建配置单元表。
(或)
创建指向目标目录的配置单元外部表,然后在sqoop import remove--create hive table参数和--target dir中。
请在此处阅读答案:https://community.hortonworks.com/questions/198586/running-a-sqoop-job-with-a-target-dir-destination.html
在这里:https://community.hortonworks.com/questions/193934/sqoop-import-mssql-table-into-hdfs.html

webghufk

webghufk2#

希望你用过 / 指定路径时的前缀 --target-dir ```
sqoop import --connect jdbc:mysql://10.6.162.58/test_alpha --username pbd -P --table posts --hive-import --hive-database test_root --hive-table posts1 --hive-drop-import-delims --null-string '\N' --null-non-string '\N' --target-dir /test_hive_root/2

相关问题