1、问题描述:

(1)问题示例:

Step1:创建作业:

[Hadoop@master TestDir]$ sqoop job \
> --create myjob_1 \
> -- import \
> --connect "jdbc:mysql://master:3306/source?useSSL=false&user=Hive&password=******" \
> --table sales_order \
> --columns "order_number,customer_number,product_code,order_date,entry_date,order_amount" \
> --where "entry_date < current_date()" \
> --hive-import \
> --hive-table rds.sales_order \
> --incremental append \
> --check-column entry_date \
> --last-value '1900-01-01'
2021-11-06 15:08:48,003 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
2021-11-06 15:08:48,242 INFO tool.BaseSqoopTool: Using Hive-specific delimiters for output. You can override
2021-11-06 15:08:48,242 INFO tool.BaseSqoopTool: delimiters with --fields-terminated-by, etc.
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
at org.apache.sqoop.util.SqoopJsonUtil.getJsonStringforMap(SqoopJsonUtil.java:43)
at org.apache.sqoop.SqoopOptions.writeProperties(SqoopOptions.java:785)
at org.apache.sqoop.metastore.hsqldb.HsqldbJobStorage.createInternal(HsqldbJobStorage.java:399)
at org.apache.sqoop.metastore.hsqldb.HsqldbJobStorage.create(HsqldbJobStorage.java:379)
at org.apache.sqoop.tool.JobTool.createJob(JobTool.java:181)
at org.apache.sqoop.tool.JobTool.run(JobTool.java:294)
at org.apache.sqoop.Sqoop.run(Sqoop.java:147)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:76)
at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:183)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:234)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:243)
at org.apache.sqoop.Sqoop.main(Sqoop.java:252)
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 12 more

Step2:查看作业:
[Hadoop@master TestDir]$ sqoop job --list
2021-11-06 15:09:01,663 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
Available jobs:
myjob_1

Step3:查看时间戳:
[Hadoop@master TestDir]$ sqoop job --show myjob_1 |grep last.value
2021-11-06 15:09:10,169 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
at org.apache.sqoop.util.SqoopJsonUtil.getJsonStringforMap(SqoopJsonUtil.java:43)
at org.apache.sqoop.SqoopOptions.writeProperties(SqoopOptions.java:785)
at org.apache.sqoop.tool.JobTool.showJob(JobTool.java:261)
at org.apache.sqoop.tool.JobTool.run(JobTool.java:302)
at org.apache.sqoop.Sqoop.run(Sqoop.java:147)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:76)
at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:183)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:234)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:243)
at org.apache.sqoop.Sqoop.main(Sqoop.java:252)
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 10 more

Step4:提交作业:
[Hadoop@master TestDir]$ sqoop job --exec myjob_1
2021-11-06 15:09:20,062 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
--table or --query is required for import. (Or use sqoop import-all-tables.)
Try --help for usage instructions.

Step5:二次查看时间戳:
[Hadoop@master TestDir]$ sqoop job --show myjob_1 |grep last.value
2021-11-06 15:09:28,496 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
at org.apache.sqoop.util.SqoopJsonUtil.getJsonStringforMap(SqoopJsonUtil.java:43)
at org.apache.sqoop.SqoopOptions.writeProperties(SqoopOptions.java:785)
at org.apache.sqoop.tool.JobTool.showJob(JobTool.java:261)
at org.apache.sqoop.tool.JobTool.run(JobTool.java:302)
at org.apache.sqoop.Sqoop.run(Sqoop.java:147)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:76)
at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:183)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:234)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:243)
at org.apache.sqoop.Sqoop.main(Sqoop.java:252)
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 10 more

(2)问题综述:

通过以上步骤示例,Sqoop从MySQL向Hive进行增量式导入数据报错,问题的核心在于:

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject

解决该问题,是关键。

2、问题剖析:

(1)参考:https://www.cnblogs.com/QuestionsZhang/p/10082735.html

(2)剖析:根据参考,以及本示例所报出的问题,基本可以肯定是因为Sqoop安装路径下lib目录缺少java-json.jar。因此只需要寻找一个Java-json.jar放入Sqoop安装路径中的lib目录下即可。笔者从最终测试结果可知,此为正解。

3、解决方案:

(1)下载java-json.jar:

下载地址:http://www.java2s.com/Code/JarDownload/java-json/java-json.jar.zip

(2)二次测试:

Step1:创建作业:

[Hadoop@master tmp]$ sqoop job \
> --create myjob_1 \
> -- import \
> --connect "jdbc:mysql://master:3306/source?useSSL=false&user=Hive&password=******" \
> --table sales_order \
> --columns "order_number,customer_number,product_code,order_date,entry_date,order_amount" \
> --where "entry_date < current_date()" \
> --hive-import \
> --hive-table rds.sales_order \
> --incremental append \
> --check-column entry_date \
> --last-value '1900-01-01'
2021-11-06 15:49:52,350 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
2021-11-06 15:49:52,632 INFO tool.BaseSqoopTool: Using Hive-specific delimiters for output. You can override
2021-11-06 15:49:52,632 INFO tool.BaseSqoopTool: delimiters with --fields-terminated-by, etc.

Step2:查看作业:

[Hadoop@master tmp]$ sqoop job --list
2021-11-06 15:50:10,531 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
Available jobs:
myjob_1

Step3:查看时间戳:

[Hadoop@master tmp]$ sqoop job --show myjob_1 |grep last.value
2021-11-06 15:50:29,832 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
incremental.last.value = 1900-01-01

Step4:提交作业:

[Hadoop@master tmp]$ sqoop job --exec myjob_1
2021-11-06 16:05:23,188 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
2021-11-06 16:05:23,815 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
2021-11-06 16:05:23,851 INFO tool.CodeGenTool: Beginning code generation
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2021-11-06 16:05:27,962 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `sales_order` AS t LIMIT 1
2021-11-06 16:05:29,150 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `sales_order` AS t LIMIT 1
......(此处有省略)
2021-11-06 16:09:35,112 INFO hive.HiveImport: OK
2021-11-06 16:09:35,273 INFO hive.HiveImport: Time taken: 1.611 seconds
2021-11-06 16:09:35,274 INFO hive.HiveImport: 2021-11-06 16:09:35,273 INFO [af634dbf-7808-4849-bd2e-f2b12b7435a8 main] CliDriver (SessionState.java:printInfo(1227)) - Time taken: 1.611 seconds
2021-11-06 16:09:35,274 INFO hive.HiveImport: 2021-11-06 16:09:35,273 INFO [af634dbf-7808-4849-bd2e-f2b12b7435a8 main] conf.HiveConf (HiveConf.java:getLogIdVar(5040)) - Using the default value passed in for log id: af634dbf-7808-4849-bd2e-f2b12b7435a8
2021-11-06 16:09:35,274 INFO hive.HiveImport: 2021-11-06 16:09:35,273 INFO [af634dbf-7808-4849-bd2e-f2b12b7435a8 main] session.SessionState (SessionState.java:resetThreadName(452)) - Resetting thread name to main
2021-11-06 16:09:35,274 INFO hive.HiveImport: 2021-11-06 16:09:35,274 INFO [main] conf.HiveConf (HiveConf.java:getLogIdVar(5040)) - Using the default value passed in for log id: af634dbf-7808-4849-bd2e-f2b12b7435a8
2021-11-06 16:09:35,319 INFO hive.HiveImport: 2021-11-06 16:09:35,318 INFO [main] session.SessionState (SessionState.java:dropPathAndUnregisterDeleteOnExit(885)) - Deleted directory: /user/hive/tmp/grid/af634dbf-7808-4849-bd2e-f2b12b7435a8 on fs with scheme hdfs
2021-11-06 16:09:35,319 INFO hive.HiveImport: 2021-11-06 16:09:35,319 INFO [main] session.SessionState (SessionState.java:dropPathAndUnregisterDeleteOnExit(885)) - Deleted directory: /tmp/hive/Local/af634dbf-7808-4849-bd2e-f2b12b7435a8 on fs with scheme file
2021-11-06 16:09:35,319 INFO hive.HiveImport: 2021-11-06 16:09:35,319 INFO [main] metastore.HiveMetaStoreClient (HiveMetaStoreClient.java:close(600)) - Closed a connection to metastore, current connections: 1
2021-11-06 16:09:35,389 INFO hive.HiveImport: Hive import complete.
2021-11-06 16:09:35,392 INFO hive.HiveImport: Export directory is empty, removing it.
2021-11-06 16:09:35,408 INFO tool.ImportTool: Saving incremental import state to the metastore
2021-11-06 16:09:35,454 INFO tool.ImportTool: Updated data for job: myjob_1

Step5:二次查看时间戳:

[Hadoop@master tmp]$ sqoop job --show myjob_1 |grep last.value
2021-11-06 16:09:45,037 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
incremental.last.value = 2016-06-30 17:26:24.0

二次查看时间戳的目的是验证:Sqoop是不是成功将MySQL中数据采用增量式导入Hive中,此外还可以在Hive查看数据进行验证。

Sqoop从MySQL向Hive增量式导入数据报错:Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject的更多相关文章

  1. 创建Sqoop作业,报错Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject

    WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P in ...

  2. Sqoop异常:Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject

    18/12/07 01:09:03 INFO mapreduce.ImportJobBase: Beginning import of staffException in thread "m ...

  3. hive 启动不成功,报错:hive 启动报 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/mapred/MRVersi

    1. 现象:在任意位置输入 hive,准备启动 hive 时,报错: Exception in thread "main" java.lang.NoClassDefFoundErr ...

  4. Exception in thread "main" java.lang.RuntimeException: Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, do

    继上一篇Hive: Exception in thread "main" java.lang.RuntimeException: Hive metastore database i ...

  5. Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient

    hive安装时遇到的问题 解压后指定了hive-env.sh文件的Hadoop_home  & hive_conf 两个参数后,先直接bin/hive 用Derby数据库启动一下,然后再配置其 ...

  6. Oozie时出现Exception in thread "main" java.lang.UnsupportedClassVersionError: com/mysql/jdbc/Driver : Unsupported major.minor version 52.0?

    不多说,直接上干货! 问题详情 [hadoop@bigdatamaster oozie--cdh5.5.4]$ bin/ooziedb.sh create -sqlfile oozie.sql -ru ...

  7. Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

    这个问题当然是找不到mysql的驱动类,可能是环境CLASSPATH有问题或者就是那个人没有加载jdbc的驱动.我在网上下载mysql-connector-java-5.0.8-bin.jar一个这个 ...

  8. sqoop 创建job时 java.lang.NoClassDefFoundError: org/json/JSONObject

    缺少jar包 到maven仓库下载json in java 之后把jar包上传至sqoop的lib目录下即可

  9. pycharm中连接MySql出现 Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.的错误解决

    具体异常如下: 这个异常特别烦人,是mysql连接驱动的问题,可以用二步解决: 第一步 从网上下载驱动,从mysql-connector-java_8.0.16-1ubuntu16.04_all.de ...

  10. Sqoop import导入表时报错java.lang.ClassNotFoundException: org.json.JSONObject

    报错原因:sqoop缺少java-json.jar包. 解决方案:一. 下载java-json.jar包地址:https://download.csdn.net/download/qq_2213643 ...

随机推荐

  1. sap IUT255 Integration of SAP CRM and SAP IS-U_EN_Col62.pdf

    sap IUT255 Integration of SAP CRM and SAP IS-U_EN_Col62.pdf   sap IUT255 Integration of SAP CRM and ...

  2. HttpClient详细使用示例(转)

    https://blog.csdn.net/justry_deng/article/details/81042379

  3. 整合mybatis-示例

    引入依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.o ...

  4. Apache 基本配置 代理 重定向 跨域 https ssl证书 在windows下常用命令

    官网下载地址 https://httpd.apache.org/ => https://httpd.apache.org/docs/current/platform/windows.html#d ...

  5. 上传镜像到harbor

    https://blog.csdn.net/weixin_45335305/article/details/123817541

  6. EOVS 83开局

    目录 公司筹备阶段 第一季 公司筹备阶段 第一季

  7. Alfred 好用工具分享

    好用的mac工具分享 1.带历史记录的剪切板 根据快捷键切换选择保存的数据 2.创建热键工作流程 将常用的工具变为热键,快捷切换 如何创建: 设置热键 单击右键 创建actions 打开app 然后将 ...

  8. idea开发工具无法解析jdk

    jdk 设置好了,但是总是无法引入 java的库 解决办法如下 点击按钮即可

  9. 1、PyTorch基本操作

    一.简介 简单介绍PyTorch框架,基本使用和安装方法.Torch是什么?一个火炬!其实跟Tensorflow中Tensor是一个意思,就是说,有一批数据,无论是图像数据还是文本数据或数值数据,都需 ...

  10. ZSTUOJ刷题④:Problem B.--输出双层金字塔

    Problem B: 输出双层金字塔 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 7860  Solved: 5834 Description 输出双层 ...