Hello! I’m trying to execute a prepared N1QL query using the Go SDK and many are working but one in particular consistently fails with this error:
{
"code": 4070,
"msg": "Unable to decode prepared statement - cause: Unrecognizable prepared statement - cause: unable to convert to prepared statment."
}
This happens with a development project, but I’ve been able to reproduce it with a contrived database structure. Here’s the client code:
package main
import (
"fmt"
"github.com/couchbase/gocb"
)
func main() {
cluster, err := gocb.Connect("couchbase://localhost")
if err != nil {
panic(err)
}
bucket, err := cluster.OpenBucket("n1ql-test", "")
if err != nil {
panic(err)
}
query := gocb.NewN1qlQuery("select distinct field1 from `n1ql-test` where field2 in [\"value2\", \"value3\"] and field3 = $value").AdHoc(false)
results, err := bucket.ExecuteN1qlQuery(query, map[string]interface{}{
"value": "value3",
})
if err != nil {
panic(err)
}
var row interface{}
for results.Next(&row) {
fmt.Println("row:", row)
}
}
The HTTP exchanges are below.
Prepare statement:
POST /query/service HTTP/1.1
Host: localhost:8093
Authorization: Basic bjFxbC10ZXN0Og==
Content-Type: application/json
{"statement":"PREPARE select distinct field1 from `n1ql-test` where field2 in [\"value2\", \"value3\"] and field3 = $value"}
HTTP/1.1 200 OK
Content-Length: 9414
Content-Type: application/json; version=1.0.0
Date: Fri, 23 Oct 2015 14:16:41 GMT
{
"requestID": "4decf33a-f207-4158-8f5e-b2bd64c16b3d",
"signature": "json",
"results": [
{
"encoded_plan": "H4sIAAAJbogA/7xTUW/aMBD+K9ZtDyCFCRICNNIeKq3VkPaAQHtqUTHxEdwah9pOy1ax374LAVKWtNKqqk9xzt/3+e67uydAHacCxc1acQ0RgAear5BO3flZr4dh3OLzQbvV7YeiNZ/3Fq12KILFPPR5GHYJna7RcJcaiJ7gU/kDE7zPSBsJ8ideSiUMkv7VKeg8c8vUyN85agd6k8pQOzQWYzeJqQYPLH1sBfVTy1S/ihhqgZs9QuZnii0kKhFQ4A5/2TWPc2d05161HFpHYSVX0kF05vtB0PfbQW8Qdvv9cNDuF0YeOAIXPFM5gyL7tyeIdxDpTCkPxlwnmFf/I32kS/j8wFWGMPXgu0yWp5GhjlVmqRqIgu3Wey8hCtCPTijbxErYTnPpd3LQ/3gHr2FXp38Nz4s/jf6Xk3tqUCsY1AlWHa14OuKGK4XqOOBv2oBLdPHyZYvrbPw3kUupaIvyPUy1kG5XAjQajdlRaPZlVvRy1mRSs6vSSo+VLkybjGvB6ogBEb+yYvyazUoGQ03PcjUy6S3tMmUipHVS0zFyJkMPDFrK/IbSXBXtx806J9Y81Zk1awb420GwWrwuHybey0TShLWRD1JhgjZv1t7QqDQ86lQEJs4gXxV0KxPNXWZ2s1VkS4hbS47TrcONy+difDE6H18wi4pyYgcrWIFnC5Ou2LOy2eMSDRa3/mvd2TWn6MaxF7D9GwAA//+WY5r7BwYAAA==",
"name": "4b966e5c-ab80-475d-bb6f-05d3fb52a554",
"operator": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Authorize",
"child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "IntersectScan",
"scans": [
{
"#operator": "UnionScan",
"scans": [
{
"#operator": "IndexScan",
"index": "field3",
"keyspace": "n1ql-test",
"limit": 9.223372036854776e+18,
"namespace": "default",
"spans": [
{
"Range": {
"High": [
"$value"
],
"Inclusion": 3,
"Low": [
"$value"
]
},
"Seek": null
},
{
"Range": {
"High": [
"$value"
],
"Inclusion": 3,
"Low": [
"$value"
]
},
"Seek": null
}
],
"using": "gsi"
}
]
},
{
"#operator": "UnionScan",
"scans": [
{
"#operator": "IndexScan",
"index": "field2",
"keyspace": "n1ql-test",
"limit": 9.223372036854776e+18,
"namespace": "default",
"spans": [
{
"Range": {
"High": [
"\"value2\""
],
"Inclusion": 3,
"Low": [
"\"value2\""
]
},
"Seek": null
},
{
"Range": {
"High": [
"\"value3\""
],
"Inclusion": 3,
"Low": [
"\"value3\""
]
},
"Seek": null
}
],
"using": "gsi"
}
]
}
]
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Fetch",
"keyspace": "n1ql-test",
"namespace": "default"
},
{
"#operator": "Filter",
"condition": "(((`n1ql-test`.`field2`) in [\"value2\", \"value3\"]) and ((`n1ql-test`.`field3`) = $value))"
},
{
"#operator": "InitialProject",
"distinct": true,
"result_terms": [
{
"expr": "(`n1ql-test`.`field1`)"
}
]
},
{
"#operator": "Distinct"
},
{
"#operator": "FinalProject"
}
]
}
},
{
"#operator": "Distinct"
}
]
},
"privileges": {
"default:n1ql-test": 1
}
},
{
"#operator": "Stream"
}
]
},
"signature": {
"field1": "json"
},
"text": "PREPARE select distinct field1 from `n1ql-test` where field2 in [\"value2\", \"value3\"] and field3 = $value"
}
],
"status": "success",
"metrics": {
"elapsedTime": "5.0003ms",
"executionTime": "5.0003ms",
"resultCount": 1,
"resultSize": 9122
}
}
Execute statement:
POST /query/service HTTP/1.1
Host: localhost:8093
Authorization: Basic bjFxbC10ZXN0Og==
Content-Type: application/json
{"$value":"value3","encoded_plan":"H4sIAAAJbogA/7xTUW/aMBD+K9ZtDyCFCRICNNIeKq3VkPaAQHtqUTHxEdwah9pOy1ax374LAVKWtNKqqk9xzt/3+e67uydAHacCxc1acQ0RgAear5BO3flZr4dh3OLzQbvV7YeiNZ/3Fq12KILFPPR5GHYJna7RcJcaiJ7gU/kDE7zPSBsJ8ideSiUMkv7VKeg8c8vUyN85agd6k8pQOzQWYzeJqQYPLH1sBfVTy1S/ihhqgZs9QuZnii0kKhFQ4A5/2TWPc2d05161HFpHYSVX0kF05vtB0PfbQW8Qdvv9cNDuF0YeOAIXPFM5gyL7tyeIdxDpTCkPxlwnmFf/I32kS/j8wFWGMPXgu0yWp5GhjlVmqRqIgu3Wey8hCtCPTijbxErYTnPpd3LQ/3gHr2FXp38Nz4s/jf6Xk3tqUCsY1AlWHa14OuKGK4XqOOBv2oBLdPHyZYvrbPw3kUupaIvyPUy1kG5XAjQajdlRaPZlVvRy1mRSs6vSSo+VLkybjGvB6ogBEb+yYvyazUoGQ03PcjUy6S3tMmUipHVS0zFyJkMPDFrK/IbSXBXtx806J9Y81Zk1awb420GwWrwuHybey0TShLWRD1JhgjZv1t7QqDQ86lQEJs4gXxV0KxPNXWZ2s1VkS4hbS47TrcONy+difDE6H18wi4pyYgcrWIFnC5Ou2LOy2eMSDRa3/mvd2TWn6MaxF7D9GwAA//+WY5r7BwYAAA==","prepared":"4b966e5c-ab80-475d-bb6f-05d3fb52a554","statement":"select distinct field1 from `n1ql-test` where field2 in [\"value2\", \"value3\"] and field3 = $value"}
HTTP/1.1 500 Internal Server Error
Content-Length: 458
Content-Type: application/json; version=1.0.0
Date: Fri, 23 Oct 2015 14:16:41 GMT
{
"requestID": "5272c999-1927-45f4-9abc-56d06947a54a",
"errors": [
{
"code": 4070,
"msg": "Unable to decode prepared statement - cause: Unrecognizable prepared statement - cause: unable to convert to prepared statment."
}
],
"status": "fatal",
"metrics": {
"elapsedTime": "0",
"executionTime": "0",
"resultCount": 0,
"resultSize": 0,
"errorCount": 1
}
}
I noticed in bucket_http.go that during preparation the statement
key is delete from the request options but not during execution, so I tried adding the same delete
statement to execution. Interestingly this works on subsequent execution requests, but not the initial execution request.
Any ideas?