当前位置: 首页 > 知识库问答 >
问题:

Cloudant数据库未使用Spark python连接

楚帅
2023-03-14

错误抛出在“load(couldant_credentials['db_name'])”上,所以是否缺少要导入的库?

我确信我使用的Cloudant证书是正确的。

我尝试使用Java代码,但得到同样的错误。

import pandas
import pyspark
from pyspark.mllib.regression import LabeledPoint
from pyspark.ml.evaluation import MulticlassClassificationEvaluator
from pyspark.mllib.util import MLUtils
from pyspark import SparkContext, SparkConf
from pyspark.sql import SQLContext

#Needs to be created once.
sc = SparkContext("local[4]","demo")
sqlContext = SQLContext(sc)
print(sc.version) //2.0.1

tic = timeit.default_timer()
candidate_data = sqlContext.read.format("com.cloudant.spark").\
option("cloudant.host",cloudant_credentials['url']).\
option("cloudant.username",cloudant_credentials['username']).\
option("cloudant.password",cloudant_credentials['password']).\
load(cloudant_credentials['db_name'])
toc = timeit.default_timer()
<dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.10</artifactId>
            <version>2.0.0</version>
        </dependency>

        <!-- <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-streaming-kafka-0-10_2.10</artifactId> 
            <version>2.0.0</version> </dependency> -->
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-mllib_2.10</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>sample</groupId>
            <artifactId>com.sample</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/resource/spark-cloudant-2.0.0-s_2.11.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.cloudant</groupId>
            <artifactId>cloudant-client</artifactId>
            <version>2.0.0</version>
        </dependency>
        <!-- <dependency> <groupId>com.cloudant</groupId> <artifactId>cloudant-client</artifactId> 
            <version>2.6.2</version> </dependency> -->
        <!-- <dependency> <groupId>com.typesafe</groupId> <artifactId>config</artifactId> 
            <version>1.2.1</version> </dependency> -->
        <dependency>
            <groupId>com.typesafe.play</groupId>
            <artifactId>play_2.11</artifactId>
            <version>2.5.10</version>
        </dependency>
        <dependency>
            <groupId>org.scalaj</groupId>
            <artifactId>scalaj-http_2.11</artifactId>
            <version>2.3.0</version>
        </dependency>
---------------------------------------------------------------------------
Py4JJavaError                             Traceback (most recent call last)
<ipython-input-12-44e0613fa6f4> in <module>()
      6 print(cloudant_credentials['db_name'])
      7 
----> 8 candidate_data = sqlContext.read.format("com.cloudant.spark").option("cloudant.host",cloudant_credentials['url']).option("cloudant.username",cloudant_credentials['username']).option("cloudant.password",cloudant_credentials['password']).load(cloudant_credentials['db_name'])
      9 
     10 toc = timeit.default_timer()

/home/spark/spark/python/pyspark/sql/readwriter.pyc in load(self, path, format, schema, **options)
    145         self.options(**options)
    146         if isinstance(path, basestring):
--> 147             return self._df(self._jreader.load(path))
    148         elif path is not None:
    149             if type(path) != list:

/home/spark/spark/python/lib/py4j-0.10.3-src.zip/py4j/java_gateway.py in __call__(self, *args)
   1131         answer = self.gateway_client.send_command(command)
   1132         return_value = get_return_value(
-> 1133             answer, self.gateway_client, self.target_id, self.name)
   1134 
   1135         for temp_arg in temp_args:

/home/spark/spark/python/pyspark/sql/utils.pyc in deco(*a, **kw)
     61     def deco(*a, **kw):
     62         try:
---> 63             return f(*a, **kw)
     64         except py4j.protocol.Py4JJavaError as e:
     65             s = e.java_exception.toString()

/home/spark/spark/python/lib/py4j-0.10.3-src.zip/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
    317                 raise Py4JJavaError(
    318                     "An error occurred while calling {0}{1}{2}.\n".
--> 319                     format(target_id, ".", name), value)
    320             else:
    321                 raise Py4JError(

Py4JJavaError: An error occurred while calling o111.load.
: java.lang.NoSuchMethodError: org.apache.spark.SparkEnv.actorSystem()Lakka/actor/ActorSystem;
    at com.cloudant.spark.DefaultSource.<init>(DefaultSource.scala:104)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:325)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:149)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:132)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:237)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:280)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:214)
    at java.lang.Thread.run(Thread.java:745)

共有1个答案

沈俊晤
2023-03-14

尝试在spark-submit中使用cloudant包:https://spark-packages.org/package/cloudant-labs/spark-cloudant

使用spark-shell、pyspark或spark-submit将此包包含在Spark应用程序

$SPARK_HOME/bin/spark-shell --packages cloudant-labs:spark-cloudant:2.0.0-s_2.11

注意:您还可以使用以下格式:https://github.com/cloudant-labs/spark-cloudant

 类似资料:
  • 问题内容: 我正在尝试使用Node.js连接到Cloudant上的CouchDB数据库。 这在外壳上起作用: 但是此node.js代码不起作用: 它给了我这些数据: 如何使用Node.js列出我的所有数据库? 问题答案: 内置的Node.js http客户端相当低级,它不支持现成的HTTP Basic身份验证。第二个参数只是一个主机名。它不希望那里有凭据。 您有两种选择: 1.自己构造HTTP基本

  • 我正在使用Glassfish应用服务器开发一个web应用程序。我已经安装了H2 DB,现在正试图在glassfish中定义一个连接池,但在尝试ping DB时失败了。 以下是我所做的: > 资源类型:javax。sql。数据源 数据库驱动程序供应商:H2 数据源类名:org。h2.jdbcx。JdbcDataSource 我的“其他属性”包括: 用户:my\u db\u user 当我尝试ping

  • 我正在使用sqldeveloper查询数据库并将结果导出到csv文件。我每天都需要这个文件,所以考虑创建可以在windows任务调度器上调度的bat文件。我在研究它,发现我可以使用SQLcl运行脚本来导出查询数据。但不知何故,我无法连接它,它给了我一个错误“ORA-01017:无效的用户名/密码;登录被拒绝。以下是我的sql developer连接属性 这是我的命令行: 我安装了java开发工具包

  • 我有一个带hibernate的SpringBoot应用程序。在我的测试中,我想禁用任何类型的数据库连接和配置(测试不能访问数据库)。我该怎么做? 我的测试类是用注释的,并且具有属性。禁用所有数据库交互的正确注释值是多少?

  • 下面是我的java代码, Maven依赖项 获取错误详细信息,

  • 我的Grails应用程序在开发模式下使用h2数据库(Grails应用程序的默认行为)。中的DB连接设置是 我正在尝试使用IntelliJ IDEA的数据库客户端工具为此数据库建立连接。我开始这样创建连接 然后在下面的对话框中,输入JDBC URL 并选择“模式”上的所有可用数据库 “Test Connection”(测试连接)按钮表示成功,但从红色圆圈中可以看到,没有找到任何表格。似乎我已经正确地