2016-06-09 60 views
0

以下为我的作品时,我只是用数据库名称:cloudant Apache的火花访问设计文件

database = 'databasename' 

cloudantdata_df = sqlContext.read.format("com.cloudant.spark").\ 
option("cloudant.host", host).\ 
option("cloudant.username", username).\ 
option("cloudant.password", password).\ 
load(database) 

cloudantdata_df.printSchema() 

然而,当我尝试使用格式像加载特定的设计文档和视图名称:

database = 'databasename/_design/analytics/_view/invBA' 

我得到以下Java异常:

Py4JJavaError: An error occurred while calling o54.load. 
: java.lang.RuntimeException: Database databasename/_design/analytics/_view/invBA request error: {"error":"method_not_allowed","reason":"Only GET,POST,HEAD allowed"} 

at com.cloudant.spark.common.JsonStoreDataAccess.getQueryResult(JsonStoreDataAccess.scala:176) 
at com.cloudant.spark.common.JsonStoreDataAccess.getMany(JsonStoreDataAccess.scala:85) 
at com.cloudant.spark.DefaultSource.create(DefaultSource.scala:114) 
at com.cloudant.spark.DefaultSource.createRelation(DefaultSource.scala:100) 
at com.cloudant.spark.DefaultSource.createRelation(DefaultSource.scala:94) 
at org.apache.spark.sql.execution.datasources.ResolvedDataSource$.apply(ResolvedDataSource.scala:158) 
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:119) 
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:109) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) 
at java.lang.reflect.Method.invoke(Method.java:507) 
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231) 
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:381) 
at py4j.Gateway.invoke(Gateway.java:259) 
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133) 
at py4j.commands.CallCommand.execute(CallCommand.java:79) 
at py4j.GatewayConnection.run(GatewayConnection.java:209) 
at java.lang.Thread.run(Thread.java:785) 

有没有一种方式来看待一个汉邦cular设计文档视图名称?

回答

0

在github上,有一个例子,如何加载的观点:https://github.com/cloudant-labs/spark-cloudant/blob/master/examples/python/CloudantDF.py#L74

您需要使用view选项。 在您的具体情况下,它将是:

cloudantdata_df = sqlContext.read.format("com.cloudant.spark").\ 
option("cloudant.host", host).\ 
option("cloudant.username", username).\ 
option("cloudant.password", password).\ 
option("view","_design/analytics/_view/invBA").load(database) 
+0

非常感谢。这工作。其中有些东西很难弄清楚,因为似乎没有出版过所有功能的api。他们是否真的期望人们挖掘所有的例子来弄清楚除了基本的东西之外怎么做? – webe3

+0

@ webe3所有的API都在自述文件中https://github.com/cloudant-labs/spark-cloudant/blob/master/README.md;有一个部分有配置:https://github.com/cloudant-labs/spark-cloudant/blob/master/README.md#Configuration-Overview –

+0

gettting一个错误,同时load()函数..请参阅更多细节。 http://stackoverflow.com/questions/40886228/cloudant-database-not-connecting-using-spark-python –

相关问题