1

I am newbie in CouchBase.I am trying to write data into CouchBase in local mode.My sample code is following,

 val cfg = new SparkConf()
.setAppName("couchbaseQuickstart")
.setMaster("local[*]")
.set("com.couchbase.bucket.MyBucket","pwd") 

    val sc = new SparkContext(cfg)
    val doc1 = JsonDocument.create("doc1", JsonObject.create().put("some","content"))
    val doc2 = JsonArrayDocument.create("doc2", JsonArray.from("more", "content", "in", "here"))
    val data = sc.parallelize(Seq(doc1, doc2))

But I can't access data.saveToCouchbase().

I am using Spark 1.6.1 & Scala 2.11.8

I gave following dependencies in built.sbt

libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "1.6.1"
libraryDependencies += "com.couchbase.client" % "spark-connector_2.11" % "1.2.1"

How can I write data into CouchBase using Spark & Scala?

1 Answer 1

1

Looks like you are just missing an import statement that'll enable you to use Couchbase functions on RDDs and dataframes:

import com.couchbase.spark._

val cfg = new SparkConf()
.setAppName("couchbaseQuickstart")
.setMaster("local[*]")
.set("com.couchbase.bucket.MyBucket","pwd") 

val sc = new SparkContext(cfg)
val doc1 = JsonDocument.create("doc1", 

JsonObject.create().put("some","content"))
val doc2 = JsonArrayDocument.create("doc2", JsonArray.from("more", "content", "in", "here"))

val data = sc.parallelize(Seq(doc1, doc2))

data.saveToCouchbase()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.