spark集成clickhouse报错: .ClassNotFound Failed to find data source: clickhouse. Please find packages at

报错描述

1.报错信息

Exception in thread "main" java.lang.ClassNotFoundException: Failed to find data source: clickhouse. Please find packages at http://spark.apache.org/third-party-projects.html
    at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:689)
    at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSourceV2(DataSource.scala:743)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:266)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:226)
    at org.zhibiaocul.DomeThree$.main(DomeThree.scala:25)
    at org.zhibiaocul.DomeThree.main(DomeThree.scala)
Caused by: java.lang.ClassNotFoundException: clickhouse.DefaultSource
    at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)

报错截图:

spark集成clickhouse报错: .ClassNotFound Failed to find data source: clickhouse. Please find packages at_第1张图片

报错分析:

首先我先是检查依赖是否都正常安装了

spark集成clickhouse报错: .ClassNotFound Failed to find data source: clickhouse. Please find packages at_第2张图片

spark集成clickhouse报错: .ClassNotFound Failed to find data source: clickhouse. Please find packages at_第3张图片

发现这个是正常的,后面我左思右想后终于发现了问题出现处!

我的问题是spark集成clickhouse时连接的代码顺序不对出现的错误,比如:

val frame = sc.read.format("jdbc")

.option("password", "123456")
.option("url", "jdbc:clickhouse://192.168.23.xx:8123")
.option("user", "default")

.option("driver","ru.yandex.clickhouse.ClickHouseDriver" )
.option("dbtable", "shtd_result.cityavgcmpprovince")
.load()

一般来说不仔细看这个代码是没有问题的,但是问题就出在这里!

问题是配置信息的顺序不对,应该是先driver->url->user->password->dbtable

正确代码是:

val frame = sc.read.format("jdbc")
.option("driver","ru.yandex.clickhouse.ClickHouseDriver" )
.option("url", "jdbc:clickhouse://192.168.23.xx:8123")
.option("user", "default")
.option("password", "123456")
.option("dbtable", "shtd_result.cityavgcmpprovince")
.load()

问题解决

1.首先先检查你的依赖有没有正常的下载

2.查看你的连接代码是否正确,可以参考我上面的问题分析

你可能感兴趣的:(报错问题,spark,clickhouse,大数据)