couchbaselabs / Linq2Couchbase

A Language Integrated Query (LINQ) provider for the Couchbase .NET SDK
Apache License 2.0
95 stars 47 forks source link

ParsingFailureExceptions thrown when creating brewery_id index in Couchbase.Linq.IntegrationTests #348

Open jeffrymorris opened 3 years ago

jeffrymorris commented 3 years ago

While upgrading the CouchbaseNetClient dependency to 3.2.0, a number of integration tests (JoinTests_InnerJoin_IndexJoin, JoinTests_LeftJoin_IndexJoin, etc) are failing with ParsingFailureExceptions. For example the request:

{"statement":"CREATE INDEX brewery_id ON beer-sample(brewery_id) USING GSI WITH {\"defer_build\":False};","client_context_id":"07f299f0-0ac5-4ddd-bf2c-aac64fb3e777"}

Fails with the following response:

{
"requestID": "127a687a-bd85-4db5-8437-8a87e2f4a1d1",
"clientContextID": "07f299f0-0ac5-4ddd-bf2c-aac64fb3e777",
"errors": [{"code":3000,"msg":"syntax error - at -"}],
"status": "fatal",
"metrics": {"elapsedTime": "578.8µs","executionTime": "468.4µs","resultCount": 0,"resultSize": 0,"serviceLoad": 2,"errorCount": 1}
}

The issue appears to be that the bucket name is not being escaped with back ticks: "beer-sample" should be "`beer-sample`". This can be confirmed by running the query in the request in the query console in CB.

Note this happens for 3.0.7 and for 3.2.0 versions and I suspect all 3.X versions.

@brantburnett shouldn't this escaping be happening by the N1QlHelpers.EscapeIdentifier: https://github.com/couchbaselabs/Linq2Couchbase/blob/master/Src/Couchbase.Linq/QueryGeneration/N1QLQueryModelVisitor.cs#L137

Note that you may have to drop brewer_id index first: DROP INDEX brewery_id on `beer-sample

Jeff

brantburnett commented 3 years ago

@jeffrymorris

I was waiting to fix this on the resolution to this issue since the consensus was that the SDK should be doing the backtick wrapping. I didn't want to come back and undo the change later.

jeffrymorris commented 3 years ago

@brantburnett -

I guess I dropped the ball on this one - looks like this one should have been in the queue and released long ago. I'll assign the ticket to 3.2.1 and get it resolved.

-Jeff

brantburnett commented 3 years ago

Linked to wrong issue, reopening