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