0

The following works for me when I just use the database name:

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()

However, when I try to load a particular design document and view name using the format like:

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

I get the following java exception:

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)

Is there a way to look at a particular design document view name?

webe3
  • 103
  • 1
  • 8

1 Answers1

0

In github, there is an example how to load views:https://github.com/cloudant-labs/spark-cloudant/blob/master/examples/python/CloudantDF.py#L74

You need to use view option. In your particular case it will be:

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)
Mayya Sharipova
  • 405
  • 4
  • 11
  • Thank you very much. That worked. Some of these things are hard to figure out because there does not seem to be a published api with all of the features. Do they really expect people to dig through all of the examples to figure out how to do anything besides the very basic? – webe3 Jun 10 '16 at 15:38
  • @webe3 All API is in README file https://github.com/cloudant-labs/spark-cloudant/blob/master/README.md; there is a section there on configuration: https://github.com/cloudant-labs/spark-cloudant/blob/master/README.md#Configuration-Overview – Mayya Sharipova Jun 10 '16 at 20:11
  • gettting an error while load() function.. Please refer for more details. http://stackoverflow.com/questions/40886228/cloudant-database-not-connecting-using-spark-python – Vimal Dhaduk Nov 30 '16 at 11:55