Uploaded image for project: 'Couchbase Java Client'
  1. Couchbase Java Client
  2. JCBC-41

incorrect conversion from string to number in json attribute

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.1dp
    • Fix Version/s: 1.1-dp4
    • Component/s: Core
    • Security Level: Public
    • Labels:
      None
    • Environment:
      Java 1.1 client
      CB dp4

      Description

      zendesk ticket from customer below - is there existing functionality for this and it is simply not documented?

      The method Query.setKey( String ) converts strings consisting of digits into numbers instead of keeping the format a string. This can be seen by inspecting the Query object after running setKey( "300" ) (or any other all digit string). The internal association is ?key=300. For example, setKey( "Hey" ) yields ?key="Hey".

      The issue here is that we have data stored in JSON documents where the data portion is treated as a string, but it is all digits. So, a query for setKey( "300" ) fails to match fields that contain "300", because the query is ultimately if ( 300 == "300" ).

      There should be two versions of setKey(), one for strings and one for number types.

      I was unable to find any documentation regarding this particular case, so I assumed it is not an expected issue.

      The problem is inside of the Query class. In getArg(), the check for isJsonObject() returns true for stringified numbers, and the resulting key/value does not contain quotes. The result now is

      ?key=300

      We want the output of the query object to be

      ?key="300"

      or

      ?key=300

      based on the input type (String or number). As of now, it makes that determination for us, which is incorrect.

      which is impossible given the current implementation.

      No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

        Hide
        TimSmith Tim Smith (Inactive) added a comment -

        See duplicate JCBC-90 for other examples.

        See JCBC-48 for related issues regarding JSON object handling.

        Show
        TimSmith Tim Smith (Inactive) added a comment - See duplicate JCBC-90 for other examples. See JCBC-48 for related issues regarding JSON object handling.
        Hide
        rags Raghavan Srinivas (Inactive) added a comment -

        This seems to work well for float.

        For example,

        query.setKey("6.6");

        will find the keys with the string as 6.6.

        However a

        query.setKey("0")

        will not find the keys with String "0".

        Show
        rags Raghavan Srinivas (Inactive) added a comment - This seems to work well for float. For example, query.setKey("6.6"); will find the keys with the string as 6.6. However a query.setKey("0") will not find the keys with String "0".
        Hide
        daschl Michael Nitschinger added a comment -

        This issue is addressed here: http://review.couchbase.com/#/c/21337/

        Show
        daschl Michael Nitschinger added a comment - This issue is addressed here: http://review.couchbase.com/#/c/21337/
        Hide
        daschl Michael Nitschinger added a comment -

        Fixed in master and will be available in dp4.

        Show
        daschl Michael Nitschinger added a comment - Fixed in master and will be available in dp4.
        Hide
        ctash_jt Chris Tashjian added a comment -

        This does not work for longs...

        Query q1 = new Query();
        long time1 = 0;
        long time2 = 99999999;
        long time3 = 99999999999l;

        q1.setRangeStart(ComplexKey.of(time1));
        q1.setRangeEnd(ComplexKey.of(time2));
        q1.toString() --> ?startkey=0&endkey=99999999

        q1.setRangeStart(ComplexKey.of(time1));
        q1.setRangeEnd(ComplexKey.of(time3));
        q1.toString()) --> ?startkey=0&endkey=%2299999999999%22

        It's throwing quotes around the long value.

        Show
        ctash_jt Chris Tashjian added a comment - This does not work for longs... Query q1 = new Query(); long time1 = 0; long time2 = 99999999; long time3 = 99999999999l; q1.setRangeStart(ComplexKey.of(time1)); q1.setRangeEnd(ComplexKey.of(time2)); q1.toString() --> ?startkey=0&endkey=99999999 q1.setRangeStart(ComplexKey.of(time1)); q1.setRangeEnd(ComplexKey.of(time3)); q1.toString()) --> ?startkey=0&endkey=%2299999999999%22 It's throwing quotes around the long value.
        Hide
        SteveC Steven Cooke added a comment -

        see JCBC-48: net.spy.memcached.util.StringUtils does not implement isJsonObject to spec (http://www.json.org/) which breaks queries.

        ComplexKey.toJson outputs the values as a string which just you back to the problem in the original post. ComplexKey essentially does nothing with respect to the original problem.

        imagine this next sentence in all caps -->> StringUtils.isJson is broken and should not be used

        The original poster's solution of adding an explicit method to handle numeric keys as numbers will work.

        Show
        SteveC Steven Cooke added a comment - see JCBC-48 : net.spy.memcached.util.StringUtils does not implement isJsonObject to spec ( http://www.json.org/ ) which breaks queries. ComplexKey.toJson outputs the values as a string which just you back to the problem in the original post. ComplexKey essentially does nothing with respect to the original problem. imagine this next sentence in all caps -->> StringUtils.isJson is broken and should not be used The original poster's solution of adding an explicit method to handle numeric keys as numbers will work.

          People

          • Assignee:
            daschl Michael Nitschinger
            Reporter:
            alex Alex Ma
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Gerrit Reviews

              There are no open Gerrit changes