Skip to content

Commit ad647cc

Browse files
author
Alexey Botchkov
committed
MDEV-15561 json_extract returns NULL with numbers in scientific notation.
Scientific notation handling fixed. Conflicts: mysql-test/r/func_json.result mysql-test/t/func_json.test
1 parent 843b414 commit ad647cc

File tree

4 files changed

+21
-32
lines changed

4 files changed

+21
-32
lines changed

mysql-test/r/func_json.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,9 @@ insert into t1 values (2),(1);
736736
select 1 from t1 where json_extract(a,'$','$[81]');
737737
1
738738
drop table t1;
739+
select json_extract('{"test":8.437e-5}','$.test');
740+
json_extract('{"test":8.437e-5}','$.test')
741+
8.437e-5
739742
#
740743
# Start of 10.3 tests
741744
#

mysql-test/suite/json/r/json_no_table.result

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,9 +1061,7 @@ json_type(json_compact(3.14))
10611061
DOUBLE
10621062
select json_type(json_compact(3.14E30));
10631063
json_type(json_compact(3.14E30))
1064-
NULL
1065-
Warnings:
1066-
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_type' at position 7
1064+
DOUBLE
10671065
select json_type(json_compact(cast('10101abcde' as binary)));
10681066
json_type(json_compact(cast('10101abcde' as binary)))
10691067
INTEGER
@@ -3445,52 +3443,34 @@ JSON_ARRAY(CASE WHEN 1 THEN NULL ELSE NULL END)
34453443
#
34463444
SELECT JSON_EXTRACT('-1E-36181012216111515851075235238', '$');
34473445
JSON_EXTRACT('-1E-36181012216111515851075235238', '$')
3448-
NULL
3449-
Warnings:
3450-
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_extract' at position 33
3446+
-1E-36181012216111515851075235238
34513447
SELECT JSON_EXTRACT('1E-36181012216111515851075235238', '$');
34523448
JSON_EXTRACT('1E-36181012216111515851075235238', '$')
3453-
NULL
3454-
Warnings:
3455-
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_extract' at position 32
3449+
1E-36181012216111515851075235238
34563450
SELECT JSON_EXTRACT('1E-325', '$');
34573451
JSON_EXTRACT('1E-325', '$')
3458-
NULL
3459-
Warnings:
3460-
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_extract' at position 6
3452+
1E-325
34613453
SELECT JSON_EXTRACT('1E-324', '$');
34623454
JSON_EXTRACT('1E-324', '$')
3463-
NULL
3464-
Warnings:
3465-
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_extract' at position 6
3455+
1E-324
34663456
SELECT JSON_EXTRACT('1E-323', '$');
34673457
JSON_EXTRACT('1E-323', '$')
3468-
NULL
3469-
Warnings:
3470-
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_extract' at position 6
3458+
1E-323
34713459
SELECT JSON_EXTRACT('1E+308', '$');
34723460
JSON_EXTRACT('1E+308', '$')
3473-
NULL
3474-
Warnings:
3475-
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_extract' at position 6
3461+
1E+308
34763462
error ER_INVALID_JSON_TEXT_IN_PARAM
34773463
SELECT JSON_EXTRACT('1E+309', '$');
34783464
JSON_EXTRACT('1E+309', '$')
3479-
NULL
3480-
Warnings:
3481-
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_extract' at position 6
3465+
1E+309
34823466
error ER_INVALID_JSON_TEXT_IN_PARAM
34833467
SELECT JSON_EXTRACT('1E+36181012216111515851075235238', '$');
34843468
JSON_EXTRACT('1E+36181012216111515851075235238', '$')
3485-
NULL
3486-
Warnings:
3487-
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_extract' at position 32
3469+
1E+36181012216111515851075235238
34883470
error ER_INVALID_JSON_TEXT_IN_PARAM
34893471
SELECT JSON_EXTRACT('-1E+36181012216111515851075235238', '$');
34903472
JSON_EXTRACT('-1E+36181012216111515851075235238', '$')
3491-
NULL
3492-
Warnings:
3493-
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_extract' at position 33
3473+
-1E+36181012216111515851075235238
34943474
#
34953475
# Bug#21383284: ASSERTION IN SELECT_LEX::SETUP_CONDS
34963476
#

mysql-test/t/func_json.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,12 @@ insert into t1 values (2),(1);
391391
select 1 from t1 where json_extract(a,'$','$[81]');
392392
drop table t1;
393393

394+
#
395+
# MDEV-15561 json_extract returns NULL with numbers in scientific notation.
396+
#
397+
398+
select json_extract('{"test":8.437e-5}','$.test');
399+
394400
--echo #
395401
--echo # Start of 10.3 tests
396402
--echo #

strings/json_lib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ static int json_num_states[NS_NUM_STATES][N_NUM_CLASSES]=
473473
/*ZE1*/ { JE_SYN, JE_SYN, JE_SYN, JE_SYN, NS_FRAC, JE_SYN, NS_OK, JE_BAD_CHR },
474474
/*INT*/ { JE_SYN, JE_SYN, NS_INT, NS_INT, NS_FRAC, NS_EX, NS_OK, JE_BAD_CHR },
475475
/*FRAC*/ { JE_SYN, JE_SYN, NS_FRAC, NS_FRAC,JE_SYN, NS_EX, NS_OK, JE_BAD_CHR },
476-
/*EX*/ { NS_EX1, NS_EX1, NS_EX1, NS_EX1, JE_SYN, JE_SYN, JE_SYN, JE_BAD_CHR },
477-
/*EX1*/ { JE_SYN, JE_SYN, NS_EX1, NS_EX1, JE_SYN, JE_SYN, JE_SYN, JE_BAD_CHR }
476+
/*EX*/ { NS_EX, NS_EX, NS_EX1, NS_EX1, JE_SYN, JE_SYN, JE_SYN, JE_BAD_CHR },
477+
/*EX1*/ { JE_SYN, JE_SYN, NS_EX1, NS_EX1, JE_SYN, JE_SYN, NS_OK, JE_BAD_CHR }
478478
};
479479

480480

0 commit comments

Comments
 (0)