我正在尝试按照 https://developer.ibm.com/clouddataservices/docs/ibm-data-science-experience/docs/load-and-filter-cloudant-data-with-spark/使用 Spark 加载云数据。我有一个带有Spark 2.1的Scala 2.11(Spark 2.0也发生(笔记本,其中包含以下代码:
// @hidden_cell
var credentials = scala.collection.mutable.HashMap[String, String](
"username"->"<redacted>",
"password"->"""<redacted>""",
"host"->"<redacted>",
"port"->"443",
"url"->"<redacted>"
)
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
val cloudantdata = sqlContext.read.format("com.cloudant.spark").
option("cloudant.host", credentials("host")).
option("cloudant.username", credentials("username")).
option("cloudant.password", credentials("password")).
load("crimes")
尝试执行该单元格仅以
名称: java.lang.ClassNotFoundException 消息:找不到数据源:com.cloudant.spark。请在 http://spark.apache.org/third-party-projects.html 找到套餐 StackTrace: at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:569( at org.apache.spark.sql.execution.datasources.DataSource.providingClass$lzycompute(DataSource.scala:86( at org.apache.spark.sql.execution.datasources.DataSource.providingClass(DataSource.scala:86( at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:325( at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:152( at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:135( ...42 省略 原因:java.lang.ClassNotFoundException: com.cloudant.spark.DefaultSource at scala.reflect.internal.util.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:62( at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:844( at java.lang.ClassLoader.loadClass(ClassLoader.java:823( at java.lang.ClassLoader.loadClass(ClassLoader.java:803( at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$25$$anonfun$apply$13.apply(DataSource.scala:554( at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$25$$anonfun$apply$13.apply(DataSource.scala:554( at scala.util.Try$.apply(Try.scala:192( at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$25.apply(DataSource.scala:554( at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$25.apply(DataSource.scala:554( at scala.util.Try.orElse(Try.scala:84( at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:554(
如何克服此错误并连接到我的 Cloudant 数据库?
一定是存在一些导致 cloudant 驱动程序丢失的问题,这通常默认存在于 DSX 笔记本中。 请改用 python 2.0 和 spark 2.1 内核 并运行 Cloudant 连接器的一次性安装(每个 Spark 服务(,以便它可用于所有 Spark 2.0+ 内核。
!pip install --upgrade pixiedust
import pixiedust
pixiedust.installPackage("cloudant-labs:spark-cloudant:2.0.0-s_2.11")
重新启动内核一次。
然后将内核更改为 scala 内核,然后运行 cloudant 连接代码。
谢谢 查尔斯。