Hi,
I’m new to couchbase. Could someone please help. Delete and Update works fine from Admin Query portal. However, it is not happening when I try to execute the same delete/update statement from Spark. Is there a way how to use N1QL to delete/update from Spark?
Below is the code snippet I used. It runs fine but does not actually delete the document.
package testpackage
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.sql.SQLContext
import com.couchbase.client.java.query.N1qlQuery
import com.couchbase.spark.toSparkContextFunctions
object delete {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName(“test”).setMaster(“local”).set(“com.couchbase.bucket.mybucket”, “”)
val sc = new SparkContext(conf)
val sqlContext: SQLContext = new SQLContext(sc)
try {
deletedoc()(sc, sqlContext)
} catch {
case e: Exception =>
e.printStackTrace()
sc.stop()
System.exit(1)
} finally {
sc.stop()
}
}
def deletedoc()(sc: SparkContext, sqlContext: SQLContext) = {
val query = "delete from mybucket where meta().id=‘birairports::France’"
sc.couchbaseQuery(N1qlQuery.simple(query))
}
}