CouchBase Spark connector SparkSession multiple bucket not work in spark connector 2.2.0 and CB 5.1

I used “CB 5.1” version and spark connector “2.2.0” and my spark session I added two buckets as below :

 lazy val spark : SparkSession = {
SparkSession
  .builder()
  .master("local")
  .appName("Demo")
  .config("spark.couchbase.nodes", "127.0.0.1")
  .config("spark.couchbase.username", "admin")
  .config("spark.couchbase.password", "admin")
  .config("spark.couchbase.bucket.test", "")
  .config("spark.couchbase.bucket.test1", "")
  .getOrCreate()

}

but when I run my code it show following error :
“Caused by: java.lang.IllegalStateException: The bucket name can only be inferred if there is exactly 1 bucket set on the config”

With the help of this thread mentioned that “if you open more than one bucket and forget to set the bucket name explicitly” so I changed my query as below :

val query ="select  META(t).id from "+bucketName
  sc.sparkContext
    .couchbaseQuery(N1qlQuery.simple(query), bucketName = bucketName) // Explicitly passed bucket name 
    .map(row=>row.value.getString("id"))
    .distinct()
1 Like

How about writing the data into Couchbase, I am getting this error while writing data into multiple buckets simultaneously