您的位置:首页 > 文旅 > 旅游 > 合肥建设网站_疫情骗局_百度用户服务中心人工电话_百度图片搜索引擎

合肥建设网站_疫情骗局_百度用户服务中心人工电话_百度图片搜索引擎

2025/2/24 9:23:48 来源:https://blog.csdn.net/wusuoweiieq/article/details/144348117  浏览:    关键词:合肥建设网站_疫情骗局_百度用户服务中心人工电话_百度图片搜索引擎
合肥建设网站_疫情骗局_百度用户服务中心人工电话_百度图片搜索引擎

目录

  • 数据传输流程
  • 脚本
  • 报错和异常说明
    • 1. Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hive.conf.HiveConf
    • 2. 数据导入hive后显示NULL


数据传输流程

mysql---->>hdfs---->>hive
数据从mysql表中取出,放到hdfs上(由target-dir指定目录),所有数据转移完成后,将hdfs上传数据到hive表的对于目录下,并将该目录删除

脚本

import
--connect
jdbc:mysql://127.0.0.1:3306/sqoop
--username
root
--password
password
--as-textfile
--target-dir
/sqoop/student4
--delete-target-dir
--num-mappers
1
--bindir 
/opt/module/sqoop/lib
--table
student
--columns
id,name
--fields-terminated-by
,
--hive-import
--hive-table
student

报错和异常说明

1. Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hive.conf.HiveConf

原因:缺少hive的配置文件
解决方案:将hive目录下的hive-common-3.1.2.jar移动到sqoop的lib目录下

2. 数据导入hive后显示NULL

原因:建hive表是设定的分割符不恰当,跟从mysql导入过来的数据的分隔符不一样,所以导致hive切分不了数据,于是查询为空,但是这个过程,不属于导入失败,所以导入脚本正常运行。
导入流程:mysql---->>hdfs---->>hive
解决方案
首先检查mysql内部的数据是否正确导入到hdfs中
一般而言,mysql中的数据切分是’,’
检查hdfs中的数据情况(执行以下代码)
sqoop脚本student

import
--connect
jdbc:mysql://127.0.0.1:3306/sqoop
--username
root
--password
password
--as-textfile
--target-dir
/sqoop/student3
--delete-target-dir
--num-mappers
1
--bindir 
/opt/module/sqoop/lib
--table
student
--columns
id,name
--fields-terminated-by
,

脚本执行代码

sqoop --options-file sqoop_student.txt

检查生成的hdfs文件

 hdfs dfs -cat /sqoop/student3/part-m-00000

分析
在这里插入图片描述
hdfs中,数据以’,‘进行分割,因此hdfs---->>hive中也需要设定’,'作为分隔符

hive数据库创建
数据库创建脚本
设定’,'作为分割符

create table student
(id   string,name string
)ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE;

检查数据库情况

show create table student;

在这里插入图片描述
完整的导入脚本mysql---->>hdfs---->>hive

import
--connect
jdbc:mysql://127.0.0.1:3306/sqoop
--username
root
--password
password
--as-textfile
--target-dir
/sqoop/student4
--delete-target-dir
--num-mappers
1
--bindir 
/opt/module/sqoop/lib
--table
student
--columns
id,name
--fields-terminated-by
,
--hive-import
--hive-table
student

总结
可以修改分隔符为其他的形式’\t’ '\001’都可以,但是需要保证hdfs和hive中的分隔符统一

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com