N1QL Delete/Update from SPARK

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

}

}

Keep in mind that you may not get an error by trying to delete something that doesn’t exist, thus you won’t get an exception. Assembling strings can be a bit tricky. N1QL supports both single and double quotes though, so I don’t see anything wrong with the above other than you’re not checking the result.

I’d recommend turning the log level up, and then you can see the conversation between the client and the server.

Thanks for your reply. I double checked my query string. It works fine from admin console though.
Any example of delete/update from Spark would be highly helpful for me.

What showed in your logs for your query string? I could change it for myself, but that may not be the most useful since my data won’t match yours. In other words, your example looks fine at the moment if you’re deleting a document whose key is “birairports::France”.