eclipse / jnosql

Eclipse JNoSQL is a framework which has the goal to help Java developers to create Jakarta EE applications with NoSQL.
Other
229 stars 72 forks source link

[BUG] Query attribute of `N1QLQuery` converted from `DocumentQuery` isn't following the N1QL Escaped Identifiers spec #381

Closed dearrudam closed 1 year ago

dearrudam commented 1 year ago

Which JNoSQL project the issue refers to?

JNoSQL Databases

Bug description

The query attribute of the converted N1QLQuery from DocumentQuery conversion isn't following the N1QL Escaped Identifiers spec that requires that backticks " ` " be surrounding the escaped identifiers. Without that, the queries aren't performing as expected against the Couchbase database;

JNoSQL Version

1.0.0-SNAPSHOT

Steps To Reproduce

  1. Start a Couchbase instance in a docker container:

    docker run -d --name couchbase-instance -p 8091-8094:8091-8094 -p 11210:11210 couchbase
  2. Access the http://localhost:8091 to access the web console: image After start it, click in Setup New Cluster button:

  3. Setup a sample cluster like the image below: image Setting up the cluster name and the administrator password... image And click on the "Finish With Defaults" button to finalize the wizard.

  4. Click on the Buckets left menu and click on the "ADD BUCKET" to create the heroes bucket like below: image

  5. After the heroes bucket creation, click on the "Scopes & Collections" link to access the scopes and collections view and then click on "Add collection" in order to create the Hero collection like below:

image Click on the _default scope to expand the window then you will be able to see the Hero collection in the table: image

  1. Click on the "Documents" link to open the document list view:

image

  1. Add a document to the created collection by clicking on the "ADD DOCUMENT":

    {
    "name":"iron man",
    "realName":"Tony Stark",
    "powers":["rich"],
    "age":34
    }

    image

  2. Click on the Query left menu in order to access the Query view, then perform the following query to create a required index:

CREATE PRIMARY INDEX ON `heroes`.`_default`.`Hero`

image

  1. Then perform the following query:

    select * from heroes._default.Hero WHERE 'age' = 34

    It's expected to return the stored document, but no documents are retrieved. image

  2. Execute again the query surrounding the age identifier with backticks then the expected stored data will be retrieved. image And more, if we execute again the query by letting the age identifier alone it'll work too. I think that it's better to explicitly surround the identifiers with backticks for better visualization purposes; image

Expected Results

It's expected the query attribute of N1QLQuery converted from DocumentQuery objects has the identifiers surrounded by backticks in order to about undesired querying behavior.

Code example, screenshot, or link to a repository

No response

dearrudam commented 1 year ago

@otaviojava, I'm working on it already! I'm going to improve the test cases to cover this scenario.

dearrudam commented 1 year ago

@otaviojava, this issue was fixed on https://github.com/eclipse/jnosql-databases/pull/225.