Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-27972

Unexpected behavior with negative zero (-0) in JSON Path

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.9(EOL)
    • 10.9.0
    • JSON

    Description

      Test:

      SET @json='{ "x": [0,1]}';
      SELECT JSON_VALUE(@json,'$.x[last]');
      SELECT JSON_VALUE(@json,'$.x[last-0]');
      SELECT JSON_VALUE(@json,'$.x[-0]');
      SELECT JSON_VALUE(@json,'$.x[0]');
      

      Expected result:
      Expected that 'last' and 'last-0' give the same result

      SELECT JSON_VALUE(@json,'$.x[last]');
      JSON_VALUE(@json,'$.x[last]')
      1
      SELECT JSON_VALUE(@json,'$.x[last-0]');
      JSON_VALUE(@json,'$.x[last-0]')
      1
      

      and index '0' and '-0' too:

      SELECT JSON_VALUE(@json,'$.x[-0]');
      JSON_VALUE(@json,'$.x[-0]')
      0
      SELECT JSON_VALUE(@json,'$.x[0]');
      JSON_VALUE(@json,'$.x[0]')
      0
      

      but Actual result:

      SET @json='{ "x": [0,1]}';
      SELECT JSON_VALUE(@json,'$.x[last]');
      JSON_VALUE(@json,'$.x[last]')
      1
      SELECT JSON_VALUE(@json,'$.x[last-0]');
      JSON_VALUE(@json,'$.x[last-0]')
      NULL
      SELECT JSON_VALUE(@json,'$.x[-0]');
      JSON_VALUE(@json,'$.x[-0]')
      NULL
      SELECT JSON_VALUE(@json,'$.x[0]');
      JSON_VALUE(@json,'$.x[0]')
      0
      

      Attachments

        Issue Links

          Activity

            lstartseva Lena Startseva created issue -
            lstartseva Lena Startseva made changes -
            Field Original Value New Value
            lstartseva Lena Startseva made changes -
            Description *Test:*
            {code}
            SET @json='{ "x": [0,1]}';
            SELECT JSON_VALUE(@json,'$.x[last]');
            SELECT JSON_VALUE(@json,'$.x[last-0]');
            SELECT JSON_VALUE(@json,'$.x[-0]');
            SELECT JSON_VALUE(@json,'$.x[0]');
            {code}

            *Expected result:*
            Expected that 'last' and 'last-0' give the same result
            {code}
            SELECT JSON_VALUE(@json,'$.x[last]');
            JSON_VALUE(@json,'$.x[last]')
            1
            SELECT JSON_VALUE(@json,'$.x[last-0]');
            JSON_VALUE(@json,'$.x[last-0]')
            1
            {code}

            and index '0' and '0' too:
            {code}
            SELECT JSON_VALUE(@json,'$.x[-0]');
            JSON_VALUE(@json,'$.x[-0]')
            0
            SELECT JSON_VALUE(@json,'$.x[0]');
            JSON_VALUE(@json,'$.x[0]')
            0
            {code}

            but *Actual result:*
            {code}
            SET @json='{ "x": [0,1]}';
            SELECT JSON_VALUE(@json,'$.x[last]');
            JSON_VALUE(@json,'$.x[last]')
            1
            SELECT JSON_VALUE(@json,'$.x[last-0]');
            JSON_VALUE(@json,'$.x[last-0]')
            NULL
            SELECT JSON_VALUE(@json,'$.x[-0]');
            JSON_VALUE(@json,'$.x[-0]')
            NULL
            SELECT JSON_VALUE(@json,'$.x[0]');
            JSON_VALUE(@json,'$.x[0]')
            0
            {code}
            *Test:*
            {code}
            SET @json='{ "x": [0,1]}';
            SELECT JSON_VALUE(@json,'$.x[last]');
            SELECT JSON_VALUE(@json,'$.x[last-0]');
            SELECT JSON_VALUE(@json,'$.x[-0]');
            SELECT JSON_VALUE(@json,'$.x[0]');
            {code}

            *Expected result:*
            Expected that 'last' and 'last-0' give the same result
            {code}
            SELECT JSON_VALUE(@json,'$.x[last]');
            JSON_VALUE(@json,'$.x[last]')
            1
            SELECT JSON_VALUE(@json,'$.x[last-0]');
            JSON_VALUE(@json,'$.x[last-0]')
            1
            {code}

            and index '0' and '-0' too:
            {code}
            SELECT JSON_VALUE(@json,'$.x[-0]');
            JSON_VALUE(@json,'$.x[-0]')
            0
            SELECT JSON_VALUE(@json,'$.x[0]');
            JSON_VALUE(@json,'$.x[0]')
            0
            {code}

            but *Actual result:*
            {code}
            SET @json='{ "x": [0,1]}';
            SELECT JSON_VALUE(@json,'$.x[last]');
            JSON_VALUE(@json,'$.x[last]')
            1
            SELECT JSON_VALUE(@json,'$.x[last-0]');
            JSON_VALUE(@json,'$.x[last-0]')
            NULL
            SELECT JSON_VALUE(@json,'$.x[-0]');
            JSON_VALUE(@json,'$.x[-0]')
            NULL
            SELECT JSON_VALUE(@json,'$.x[0]');
            JSON_VALUE(@json,'$.x[0]')
            0
            {code}
            rucha174 Rucha Deodhar made changes -
            Status Open [ 1 ] Confirmed [ 10101 ]
            rucha174 Rucha Deodhar made changes -
            Status Confirmed [ 10101 ] In Review [ 10002 ]
            rucha174 Rucha Deodhar made changes -
            Assignee Rucha Deodhar [ rucha174 ] Alexey Botchkov [ holyfoot ]
            rucha174 Rucha Deodhar added a comment - - edited patch: https://github.com/MariaDB/server/commit/95fa5ce939813ae91392c597cee0b1cf51757b2b

            ok to push,

            holyfoot Alexey Botchkov added a comment - ok to push,
            holyfoot Alexey Botchkov made changes -
            Assignee Alexey Botchkov [ holyfoot ] Rucha Deodhar [ rucha174 ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            rucha174 Rucha Deodhar added a comment -

            rebased on top of bb-10.9-MDEV-22224 and preview-10.9-MDEV-22224

            rucha174 Rucha Deodhar added a comment - rebased on top of bb-10.9- MDEV-22224 and preview-10.9- MDEV-22224
            rucha174 Rucha Deodhar made changes -
            Fix Version/s 10.9.0 [ 27113 ]
            Fix Version/s 10.9 [ 26905 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]

            People

              rucha174 Rucha Deodhar
              lstartseva Lena Startseva
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.