[MDEV-28072] JSON_EXTRACT has inconsistent behavior with '0' value in json path (when range is used) Created: 2022-03-15  Updated: 2022-04-14  Resolved: 2022-04-14

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: None
Fix Version/s: 10.9.1

Type: Bug Priority: Major
Reporter: Lena Startseva Assignee: Rucha Deodhar
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-27911 Implement range notation for json path Closed

 Description   

Test:

SET @json= '[ 11, 22 , 33]';
SELECT JSON_EXTRACT(@json, '$[-2 to 1]');
SELECT JSON_EXTRACT(@json, '$[-1 to 1]');
SELECT JSON_EXTRACT(@json, '$[-1 to 0]');
SELECT JSON_EXTRACT(@json, '$[0 to 0]');
SELECT JSON_EXTRACT(@json, '$[-0 to 0]');
SELECT JSON_EXTRACT(@json, '$[-0 to 1]');
SELECT JSON_EXTRACT(@json, '$[0 to -0]');

Actual result:

SET @json= '[ 11, 22 , 33]';
SELECT JSON_EXTRACT(@json, '$[-2 to 1]');
JSON_EXTRACT(@json, '$[-2 to 1]')
[22]
SELECT JSON_EXTRACT(@json, '$[-1 to 1]');
JSON_EXTRACT(@json, '$[-1 to 1]')
NULL
SELECT JSON_EXTRACT(@json, '$[-1 to 0]');
JSON_EXTRACT(@json, '$[-1 to 0]')
NULL
Warnings:
Warning	4042	Syntax error in JSON path in argument 2 to function 'json_extract' at position 9
SELECT JSON_EXTRACT(@json, '$[0 to 0]');
JSON_EXTRACT(@json, '$[0 to 0]')
NULL
Warnings:
Warning	4042	Syntax error in JSON path in argument 2 to function 'json_extract' at position 8
SELECT JSON_EXTRACT(@json, '$[-0 to 0]');
JSON_EXTRACT(@json, '$[-0 to 0]')
NULL
Warnings:
Warning	4042	Syntax error in JSON path in argument 2 to function 'json_extract' at position 9
SELECT JSON_EXTRACT(@json, '$[-0 to 1]');
JSON_EXTRACT(@json, '$[-0 to 1]')
[11, 22]
SELECT JSON_EXTRACT(@json, '$[0 to -0]');
JSON_EXTRACT(@json, '$[0 to -0]')
[11]

Look like '0' on the right side of range is bad value, but '-0' - is good value. Why?



 Comments   
Comment by Rucha Deodhar [ 2022-03-21 ]

Patch: https://github.com/MariaDB/server/commit/f4b1e4f8e7f52559a689969240f7032d232db57b

Comment by Alexey Botchkov [ 2022-04-14 ]

ok to push.

Comment by Rucha Deodhar [ 2022-04-14 ]

Pushed to: bb-10.9-MDEV-27911

Generated at Thu Feb 08 09:57:50 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.