我正在尝试按照https://developer.ibm.com/clouddataservices/docs/ibm-data-science-experience/docs/load-and-filter-cloudant-data-with-spark/使用 Spark 加载 cloudant 数据. 我有一个带有 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:在 org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:569) 在 org.apache.spark.sql.execution.datasources.DataSource.providingClass$lzycompute(DataSource.scala:86 ) 在 org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:325) 在 org.apache.spark.sql.execution.datasources.DataSource.providingClass(DataSource.scala:86) 在 org. org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:135) 处的 apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:152) ... 42 已删除 原因:java.lang.ClassNotFoundException: com .cloudant.spark.DefaultSource 在 scala.reflect.internal.util.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:62) 在 java.lang.ClassLoader.loadClassHelper(ClassLoader.java:844) 在 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)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)在 org.apache.spark.sql.execution.datasources.DataSource$$anonfun$25.apply(DataSource.scala:554) 在 scala.util.Try.orElse(Try.scala:84) 在 org.apache.spark.sql .execution.datasources.DataSource$.lookupDataSource(DataSource.scala:554)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)在 org.apache.spark.sql.execution.datasources.DataSource$$anonfun$25.apply(DataSource.scala:554) 在 scala.util.Try.orElse(Try.scala:84) 在 org.apache.spark.sql .execution.datasources.DataSource$.lookupDataSource(DataSource.scala:554)192) 在 org.apache.spark.sql.execution.datasources.DataSource$$anonfun$25.apply(DataSource.scala:554) 在 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)192) 在 org.apache.spark.sql.execution.datasources.DataSource$$anonfun$25.apply(DataSource.scala:554) 在 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 数据库?