Commit 6f6d0531 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-11439 No data type JSON, but CAST(something AS JSON) pretends to work

Use JSON_COMPACT(X) instead of CAST(X AS JSON).
Bonus - X is validated to be a valid JSON.
Fix a typo in the error message.
parent e0fa2ce4
......@@ -402,14 +402,14 @@ json_object("a", json_object("b", "abcd"))
select json_object("a", '{"b": "abcd"}');
json_object("a", '{"b": "abcd"}')
{"a": "{\"b\": \"abcd\"}"}
select json_object("a", cast('{"b": "abcd"}' as json));
json_object("a", cast('{"b": "abcd"}' as json))
select json_object("a", json_compact('{"b": "abcd"}'));
json_object("a", json_compact('{"b": "abcd"}'))
{"a": {"b": "abcd"}}
select cast(NULL AS JSON);
cast(NULL AS JSON)
select json_compact(NULL);
json_compact(NULL)
NULL
select json_depth(cast(NULL as JSON));
json_depth(cast(NULL as JSON))
select json_depth(json_compact(NULL));
json_depth(json_compact(NULL))
NULL
select json_depth('[[], {}]');
json_depth('[[], {}]')
......
......@@ -7,21 +7,21 @@
# Some extra checks for comparisons between positive and negative zero.
# All should be equal.
SELECT CAST(0.0e0 AS JSON) = -0.0e0;
SELECT CAST(CAST(0 AS DECIMAL) AS JSON) = CAST(-0.0e0 AS DECIMAL);
SELECT CAST(0.0e0 AS JSON) = CAST(-0.0e0 AS DECIMAL);
SELECT CAST(CAST(0 AS DECIMAL) AS JSON) = -0.0e0;
SELECT CAST(CAST(0 AS SIGNED) AS JSON) = -0.0e0;
SELECT CAST(CAST(0 AS SIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL);
SELECT CAST(CAST(0 AS UNSIGNED) AS JSON) = -0.0e0;
SELECT CAST(CAST(0 AS UNSIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL);
SELECT JSON_COMPACT(0.0e0) = -0.0e0;
SELECT JSON_COMPACT(CAST(0 AS DECIMAL)) = CAST(-0.0e0 AS DECIMAL);
SELECT JSON_COMPACT(0.0e0) = CAST(-0.0e0 AS DECIMAL);
SELECT JSON_COMPACT(CAST(0 AS DECIMAL)) = -0.0e0;
SELECT JSON_COMPACT(CAST(0 AS SIGNED)) = -0.0e0;
SELECT JSON_COMPACT(CAST(0 AS SIGNED)) = CAST(-0.0e0 AS DECIMAL);
SELECT JSON_COMPACT(CAST(0 AS UNSIGNED)) = -0.0e0;
SELECT JSON_COMPACT(CAST(0 AS UNSIGNED)) = CAST(-0.0e0 AS DECIMAL);
# Test that CAST string argument isn't treated as ANY_JSON_ATOM
# in that a MySQL string needs to be parsed to JSON here; it is not
# auto-converted to a JSON string as in ANY_JSON_ATOM contexts.
select cast('"abc"' as json);
select json_compact('"abc"');
--echo error ER_INVALID_JSON_TEXT_IN_PARAM
select cast('abc' as json);
select json_compact('abc');
--echo
--echo # String literal - valid JSON
......@@ -50,11 +50,11 @@ set names 'utf8';
--echo
--echo # Json expression
select JSON_VALID(cast('[123]' as JSON ));
select JSON_VALID(json_compact('[123]'));
--echo
--echo # Json expression NULL
select JSON_VALID(cast(NULL as JSON ));
select JSON_VALID(json_compact(NULL));
--echo
--echo # Bare NULL
......@@ -80,7 +80,7 @@ select JSON_VALID( CAST('2015-01-15' AS DATE) );
--echo # The date string doesn't parse as JSON text, so wrong:
select JSON_VALID( CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8') );
--echo # OK, though:
select JSON_VALID( CAST(CURDATE() as JSON) );
select JSON_VALID( json_compact(CURDATE()) );
--echo
--echo # Function result - NULL
......@@ -299,14 +299,14 @@ SELECT JSON_LENGTH
--echo # Test of JSON_DEPTH function.
--echo # ----------------------------------------------------------------------
select json_depth(null);
select json_depth(cast(null as json));
select json_depth(json_compact(null));
#select i, json_depth(j) from t1;
select json_depth(cast('[]' as json)),
json_depth(cast('{}' as json)),
json_depth(cast('null' as json)),
select json_depth(json_compact('[]')),
json_depth(json_compact('{}')),
json_depth(json_compact('null')),
json_depth(json_quote('foo'));
select json_depth(cast('[[2], 3, [[[4]]]]' as json));
select json_depth(cast('{"a": {"a1": [3]}, "b": {"b1": {"c": {"d": [5]}}}}' as json));
select json_depth(json_compact('[[2], 3, [[[4]]]]'));
select json_depth(json_compact('{"a": {"a1": [3]}, "b": {"b1": {"c": {"d": [5]}}}}'));
# examples from the wl7909 spec
# returns 1
......@@ -325,7 +325,7 @@ SELECT JSON_DEPTH
SELECT JSON_DEPTH( '"abc"' );
# returns 1
SELECT JSON_DEPTH( CAST( '"abc"' AS JSON ) );
SELECT JSON_DEPTH( json_compact( '"abc"') );
--echo error ER_INVALID_TYPE_FOR_JSON
SELECT JSON_DEPTH( 1 );
......@@ -334,7 +334,7 @@ SELECT JSON_DEPTH( 1 );
SELECT JSON_DEPTH( 'abc' );
# returns 1
SELECT JSON_DEPTH( CAST( 1 AS JSON ) );
SELECT JSON_DEPTH( json_compact( 1) );
# returns 2
SELECT JSON_DEPTH
......@@ -608,93 +608,93 @@ select json_type('3.14');
select json_type(CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8'));
--echo # ----------------------------------------------------------------------
--echo # Test of CAST(literal AS JSON)
--echo # Test of json_compact(literal)
--echo # ----------------------------------------------------------------------
select json_type(cast(cast('2014-11-25 18:00' as datetime) as json));
select json_type(cast(cast('2014-11-25' as date) as json));
select json_type(cast(cast('18:00:59' as time) as json));
# select json_type(cast(cast('2014-11-25 18:00' as timestamp) as json)); -- cast target type not supported
# select json_type(cast(cast('1999' as year) as json)); -- cast target type not supported
select json_type(cast(127 as json));
select json_type(cast(255 as json));
select json_type(cast(32767 as json));
select json_type(cast(65535 as json));
select json_type(cast(8388607 as json));
select json_type(cast(16777215 as json));
select json_type(cast(2147483647 as json));
select json_type(cast(4294967295 as json));
select json_type(cast(9223372036854775807 as json));
select json_type(cast(18446744073709551615 as json));
select json_type(cast(true as json));
select json_type(cast(b'10101' as json));
select json_type(cast(cast(3.14 as decimal(5,2)) as json));
select json_type(cast(3.14 as json));
select json_type(cast(3.14E30 as json));
# select json_type(cast(cast(3.14 as numeral(5,2)) as json)); -- cast target type not supported
# select json_type(cast(cast(3.14 as double) as json)); -- cast target type not supported
# select json_type(cast(cast(3.14 as float) as json)); -- cast target type not supported
# select json_type(cast(cast(b'10101' as bit(10)) as json)); -- cast target type not supported
# select json_type(cast(cast('10101abcde' as blob) as json)); -- cast target type not supported
select json_type(cast(cast('10101abcde' as binary) as json));
# select json_type(cast(cast('a' as enum('a','b','c')) as json)); -- cast target type not supported
# select json_type(cast(cast('a,c' as set('a','b','c')) as json)); -- cast target type not supported
select json_type(cast(ST_GeomFromText('POINT(1 1)') as json));
select json_type(cast(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)') as json));
select json_type(cast(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
(5 5,7 5,7 7,5 7, 5 5))') as json));
select json_type(cast(null as json));
select json_type(cast(null as json)) is null; # check that it is an SQL NULL
select json_type(json_compact(cast('2014-11-25 18:00' as datetime)));
select json_type(json_compact(cast('2014-11-25' as date)));
select json_type(json_compact(cast('18:00:59' as time)));
# select json_type(json_compact(cast('2014-11-25 18:00' as timestamp))); -- cast target type not supported
# select json_type(json_compact(cast('1999' as year))); -- cast target type not supported
select json_type(json_compact(127));
select json_type(json_compact(255));
select json_type(json_compact(32767));
select json_type(json_compact(65535));
select json_type(json_compact(8388607));
select json_type(json_compact(16777215));
select json_type(json_compact(2147483647));
select json_type(json_compact(4294967295));
select json_type(json_compact(9223372036854775807));
select json_type(json_compact(18446744073709551615));
select json_type(json_compact(true));
select json_type(json_compact(b'10101'));
select json_type(json_compact(cast(3.14 as decimal(5,2))));
select json_type(json_compact(3.14));
select json_type(json_compact(3.14E30));
# select json_type(json_compact(cast(3.14 as numeral(5,2)))); -- cast target type not supported
# select json_type(json_compact(cast(3.14 as double))); -- cast target type not supported
# select json_type(json_compact(cast(3.14 as float))); -- cast target type not supported
# select json_type(json_compact(cast(b'10101' as bit(10)))); -- cast target type not supported
# select json_type(json_compact(cast('10101abcde' as blob))); -- cast target type not supported
select json_type(json_compact(cast('10101abcde' as binary)));
# select json_type(json_compact(cast('a' as enum('a','b','c')))); -- cast target type not supported
# select json_type(json_compact(cast('a,c' as set('a','b','c')))); -- cast target type not supported
select json_type(json_compact(ST_GeomFromText('POINT(1 1)')));
select json_type(json_compact(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)')));
select json_type(json_compact(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
(5 5,7 5,7 7,5 7, 5 5))')));
select json_type(json_compact(null));
select json_type(json_compact(null)) is null; # check that it is an SQL NULL
select json_type(null) is null; # is an SQL NULL
#
# same, but now show the printable value:
#
select cast(cast('2014-11-25 18:00' as datetime) as json);
select cast(cast('2014-11-25' as date) as json);
select cast(cast('18:00:59' as time) as json);
# select cast(cast('2014-11-25 18:00' as timestamp) as json); -- cast target type not supported
# select cast(cast('1999' as year) as json); -- cast target type not supported
select cast(127 as json);
select cast(255 as json);
select cast(32767 as json);
select cast(65535 as json);
select cast(8388607 as json);
select cast(16777215 as json);
select cast(2147483647 as json);
select cast(4294967295 as json);
select cast(9223372036854775807 as json);
select cast(18446744073709551615 as json);
select cast(true as json);
select cast(b'10101' as json);
select cast(cast(3.14 as decimal(5,2)) as json);
select cast(3.14 as json);
select cast(3.14e0 as json);
# select cast(cast(3.14 as numeral(5,2)) as json); -- cast target type not supported
# select cast(cast(3.14 as double) as json); -- cast target type not supported
# select cast(cast(3.14 as float) as json); -- cast target type not supported
# select cast(cast(b'10101' as bit(10) as json); -- cast target type not supported
# select cast(cast('10101abcde' as blob) as json); -- cast target type not supported
select cast(cast('10101abcde' as binary) as json);
# select cast(cast('a' as enum('a','b','c') as json); -- cast target type not supported
# select cast(cast('a,c' as set('a','b','c') as json); -- cast target type not supported
select cast(ST_GeomFromText('POINT(1 1)') as json);
select cast(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)') as json);
select cast(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
(5 5,7 5,7 7,5 7, 5 5))') as json);
select cast(null as json);
select cast(null as json) is null; # check that it is an SQL NULL
select json_compact(cast('2014-11-25 18:00' as datetime));
select json_compact(cast('2014-11-25' as date));
select json_compact(cast('18:00:59' as time));
# select json_compact(cast('2014-11-25 18:00' as timestamp)); -- cast target type not supported
# select json_compact(cast('1999' as year)); -- cast target type not supported
select json_compact(127);
select json_compact(255);
select json_compact(32767);
select json_compact(65535);
select json_compact(8388607);
select json_compact(16777215);
select json_compact(2147483647);
select json_compact(4294967295);
select json_compact(9223372036854775807);
select json_compact(18446744073709551615);
select json_compact(true);
select json_compact(b'10101');
select json_compact(cast(3.14 as decimal(5,2)));
select json_compact(3.14);
select json_compact(3.14e0);
# select json_compact(cast(3.14 as numeral(5,2))); -- cast target type not supported
# select json_compact(cast(3.14 as double)); -- cast target type not supported
# select json_compact(cast(3.14 as float)); -- cast target type not supported
# select json_compact(cast(b'10101' as bit(10)); -- cast target type not supported
# select json_compact(cast('10101abcde' as blob)); -- cast target type not supported
select json_compact(cast('10101abcde' as binary));
# select json_compact(cast('a' as enum('a','b','c')); -- cast target type not supported
# select json_compact(cast('a,c' as set('a','b','c')); -- cast target type not supported
select json_compact(ST_GeomFromText('POINT(1 1)'));
select json_compact(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)'));
select json_compact(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
(5 5,7 5,7 7,5 7, 5 5))'));
select json_compact(null);
select json_compact(null) is null; # check that it is an SQL NULL
--echo # ----------------------------------------------------------------------
--echo # Test of JSON_KEYS function.
......@@ -761,7 +761,7 @@ SELECT JSON_KEYS('{}', '$', '$');
--echo # conversion tests.
--echo # ----------------------------------------------------------------------
select cast(json_keys('{"a": 1}') as char);
select cast(cast(1 as json) as char);
select cast(json_compact(1) as char);
select cast(json_keys(NULL) as char);
#select cast(j as char) from keys1;
......@@ -996,8 +996,8 @@ select json_extract( '[ { "a": [3,4] }, { "b": 2 } ]', '$[0].a', '$[1].a' ) jdoc
--echo # ----------------------------------------------------------------------
# NULLs
select json_array_append(NULL, '$.b', cast(1 as json));
select json_array_append('[1,2,3]', NULL, cast(1 as json));
select json_array_append(NULL, '$.b', json_compact(1));
select json_array_append('[1,2,3]', NULL, json_compact(1));
select json_array_append('[1,2,3]', '$', NULL);
# wrong # args
......@@ -1009,25 +1009,25 @@ select json_array_append(NULL, NULL);
select json_array_append(NULL, NULL, NULL, NULL);
# auto-wrap
SELECT JSON_ARRAY_APPEND(cast('1' as json), '$', 3);
SELECT JSON_ARRAY_APPEND(cast('{"a": 3}' as json), '$', 3);
SELECT JSON_ARRAY_APPEND(json_compact('1'), '$', 3);
SELECT JSON_ARRAY_APPEND(json_compact('{"a": 3}'), '$', 3);
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_array_append(cast('{"a": {"b": [3]}}' as json), '$**[0]', 6);
select json_array_append(json_compact('{"a": {"b": [3]}}'), '$**[0]', 6);
# Examples from the specification
--echo # Auto-wrapping, since because the paths identify scalars.
--echo # should return {"a": "foo", "b": ["bar", 4], "c": ["wibble", "grape"]}
SELECT JSON_ARRAY_APPEND('{"a": "foo", "b": "bar", "c": "wibble"}',
'$.b', cast(4 as json),
'$.c', cast('"grape"' as json));
'$.b', json_compact(4),
'$.c', json_compact('"grape"'));
--echo # should return {"a": "foo", "b": [1, 2, 3, 4],
--echo # "c": ["apple", "pear", "grape"]}
SELECT JSON_ARRAY_APPEND('{"a" : "foo","b": [1, 2, 3], "c": ["apple", "pear"]}',
'$.b', cast(4 as json),
'$.c', cast('"grape"' as json));
'$.b', json_compact(4),
'$.c', json_compact('"grape"'));
# without CAST: cf. not required for ANY_JSON_ATOM arguments in specification
SELECT JSON_ARRAY_APPEND('{"a" : "foo","b": [1, 2, 3], "c": ["apple", "pear"]}',
......@@ -1070,8 +1070,8 @@ select json_array_append('3', '$[0][0][0][0]', 100);
--echo # ----------------------------------------------------------------------
# NULLs
select json_insert(NULL, '$.b', cast(1 as json));
select json_insert('[1,2,3]', NULL, cast(1 as json));
select json_insert(NULL, '$.b', json_compact(1));
select json_insert('[1,2,3]', NULL, json_compact(1));
select json_insert('[1,2,3]', '$[3]', NULL);
# wrong # args
......@@ -1104,35 +1104,35 @@ select json_insert('{"a": 3}', '$.a[1]', 4, '$.a[2]', '5');
# wild card & auto-wrap (scalars)
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_insert(cast('{"a": [1], "b": 2}' as json), '$.*[1]', 6);
select json_insert(json_compact('{"a": [1], "b": 2}'), '$.*[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_insert(cast('{"a": 1, "b": 2}' as json), '$.*[1]', 6);
select json_insert(json_compact('{"a": 1, "b": 2}'), '$.*[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_insert(cast('{"a": {"b": 3}}' as json), '$.a.*[1]', 6);
select json_insert(json_compact('{"a": {"b": 3}}'), '$.a.*[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_insert(cast('{"a": {"b": [3]}}' as json), '$.a.*[1]', 6);
select json_insert(json_compact('{"a": {"b": [3]}}'), '$.a.*[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_insert(cast('{"a": {"b": 3}}' as json), '$**[1]', 6);
select json_insert(json_compact('{"a": {"b": 3}}'), '$**[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_insert(cast('{"a": {"b": [3]}}' as json), '$**[1]', 6);
select json_insert(json_compact('{"a": {"b": [3]}}'), '$**[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_insert(cast('[1]' as json), '$[*][1]', 6);
select json_insert(json_compact('[1]'), '$[*][1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_insert(cast('[1]' as json), '$**[1]', 6);
select json_insert(json_compact('[1]'), '$**[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_insert(cast('[1, [2], 3]' as json), '$[*][1]', 6);
select json_insert(json_compact('[1, [2], 3]'), '$[*][1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_insert(cast('[1, [2], 3]' as json), '$**[1]', 6);
select json_insert(json_compact('[1, [2], 3]'), '$**[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_insert(cast('[[1]]' as json), '$[*][1]', 6);
select json_insert(json_compact('[[1]]'), '$[*][1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_insert(cast('[[1]]' as json), '$**[1]', 6);
select json_insert(json_compact('[[1]]'), '$**[1]', 6);
# auto-wrap object
select json_insert(cast('{"a": 3}' as json), '$[1]', 6);
select json_insert(json_compact('{"a": 3}'), '$[1]', 6);
# Examples from the specification
......@@ -1270,7 +1270,7 @@ select json_insert('[]', '$[*][1]', 6);
# multiple paths,
select json_array_insert( '[ 1, 2, 3 ]', '$[1]', true, '$[1]', false );
select json_array_insert( '[ 1, 2, 3 ]', '$[1]',
cast( '[ "a", "b", "c", "d" ]' as json ), '$[1][2]', false );
json_compact( '[ "a", "b", "c", "d" ]'), '$[1][2]', false );
# test an error while evaluating the document expression
--echo error ER_INVALID_JSON_TEXT_IN_PARAM
......@@ -1285,8 +1285,8 @@ select json_array_insert( '[ 1, 2, 3 ]', '$[1]', json_extract( '[', '$' ) );
--echo # ----------------------------------------------------------------------
# NULLs
select json_set(NULL, '$.b', cast(1 as json));
select json_set('[1,2,3]', NULL, cast(1 as json));
select json_set(NULL, '$.b', json_compact(1));
select json_set('[1,2,3]', NULL, json_compact(1));
select json_set('[1,2,3]', '$[3]', NULL);
# wrong # args
......@@ -1323,7 +1323,7 @@ select json_set('{"a": 3}', '$.a[1]', 4, '$.a[2]', '5');
# auto-wrap plus ellipsis with nested hits should give: {"a": [{"b": [3, 6]}, 6]}
--echo error ER_INVALID_JSON_PATH_WILDCARD
select json_set(cast('{"a": {"b": [3]}}' as json), '$**[1]', 6);
select json_set(json_compact('{"a": {"b": [3]}}'), '$**[1]', 6);
# Examples from the specification: Include when missing functions are
# available.
......@@ -1341,7 +1341,7 @@ select json_set(cast('{"a": {"b": [3]}}' as json), '$**[1]', 6);
# # returns { "a" : "foo", "b" : [ 1, 2, 3 ], "c" : [ true, false ] }
# SELECT JSON_SET('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
# '$.c',
# JSON_ARRAY( CAST( 'true' AS JSON ), CAST( 'false' AS JSON ) ));
# JSON_ARRAY( json_compact( 'true'), json_compact( 'false') ));
# # returns [ 1, null, null, 2 ]
# SELECT JSON_SET('1', '$[3]', 2);
......@@ -1353,19 +1353,19 @@ SELECT JSON_SET('{ "a" : "foo"}', '$.a',
# returns { "a" : {}, "b" : [ 1, 2, 3 ] }
select json_set('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
'$.a',
cast('{}' as json));
json_compact('{}'));
# returns { "a" : "foo", "b" : [ 1, 2, 3 ], "c" : [ true, false ] }
select json_set('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
'$.c',
cast('[true, false]' as json));
json_compact('[true, false]'));
# returns [ 1, null, null, 2 ]
select json_set('1', '$[3]', 2);
# should return { "a": { "b": false, "c": true } }
select json_set('{ "a" : "foo"}', '$.a',
cast('{"b": false}' as json), '$.a.c', true);
json_compact('{"b": false}'), '$.a.c', true);
# examples from wl7909 spec
# returns {"a": {}, "b": [1, 2, 3]}
......@@ -1389,7 +1389,7 @@ SELECT JSON_SET
(
'{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
'$.c',
JSON_ARRAY( CAST( 'true' AS JSON ), CAST( 'false' AS JSON ) )
JSON_ARRAY( json_compact( 'true'), json_compact( 'false') )
);
# returns [1, 2]
......@@ -1413,8 +1413,8 @@ SELECT JSON_SET
--echo # ----------------------------------------------------------------------
# NULLs
select json_replace(NULL, '$.b', cast(1 as json));
select json_replace('[1,2,3]', NULL, cast(1 as json));
select json_replace(NULL, '$.b', json_compact(1));
select json_replace('[1,2,3]', NULL, json_compact(1));
select json_replace('[1,2,3]', '$[2]', NULL);
# wrong # args
......@@ -1468,8 +1468,8 @@ SELECT JSON_REPLACE('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
--echo # ----------------------------------------------------------------------
# NULLs
select json_array(NULL, '$.b', cast(1 as json));
select json_array('[1,2,3]', NULL, cast(1 as json));
select json_array(NULL, '$.b', json_compact(1));
select json_array('[1,2,3]', NULL, json_compact(1));
select json_array('[1,2,3]', '$[3]', NULL);
......@@ -1477,7 +1477,7 @@ select json_array('[1,2,3]', '$[3]', NULL);
select json_array();
select json_array(3.14);
select json_array('[1,2,3]');
select json_array(cast('[1,2,3]' as json));
select json_array(json_compact('[1,2,3]'));
select json_array(1,2,3);
select json_array(b'0', b'1', b'10');
......@@ -1503,8 +1503,8 @@ select json_object();
select json_object( 'a', null );
select json_object( 'a', 1 );
select json_object( 'a', 1, 'b', 'foo' );
select json_object( 'a', 1, 'b', 'foo', 'c', cast( '{ "d": "wibble" }' as json ) );
select json_object( 'a', true, 'b', false, 'c', cast( 'null' as json) );
select json_object( 'a', 1, 'b', 'foo', 'c', json_compact( '{ "d": "wibble" }') );
select json_object( 'a', true, 'b', false, 'c', json_compact( 'null') );
select json_valid( json_object( '"a"', 1 ) );
# long key
......@@ -1707,29 +1707,29 @@ SELECT JSON_UNQUOTE
);
select json_type(case (null is null) when 1 then
cast('null' as json) else
cast('[1,2,3]' as json) end);
json_compact('null') else
json_compact('[1,2,3]') end);
select json_type(case (null is not null) when 1 then
cast('null' as json) else
cast('[1,2,3]' as json) end);
json_compact('null') else
json_compact('[1,2,3]') end);
select json_type( if(null is null,
cast('null' as json),
cast('[1,2,3]' as json)) );
json_compact('null'),
json_compact('[1,2,3]')) );
select json_type( if(null is not null,
cast('null' as json),
cast('[1,2,3]' as json)));
json_compact('null'),
json_compact('[1,2,3]')));
select cast(json_extract(cast(concat('[', cast('["A",2]' as json), ']') as json),
select cast(json_extract(json_compact(concat('[', json_compact('["A",2]'), ']')),
'$[0][1]') as char) = 2;
--echo # ----------------------------------------------------------------------
--echo # Test of aggregate function MAX, MIN.
--echo # ----------------------------------------------------------------------
select max(cast('[1,2,3]' as json));
select max(json_compact('[1,2,3]'));
--echo # ----------------------------------------------------------------------
--echo # Test of JSON_QUOTE, JSON_UNQUOTE
......@@ -1781,26 +1781,26 @@ select json_unquote(123); # integer not allowed
select json_unquote('""'); # empty string
select char_length(json_unquote('""')); # verify empty string
select json_unquote('"" '); # unchanged: no final "
select json_unquote(cast(json_quote('abc') as json)); # round trip
select json_unquote(json_compact(json_quote('abc'))); # round trip
# No change in this JSON string: it is an object
select cast('{"abc": "foo"}' as json);
select json_unquote(cast('{"abc": "foo"}' as json));
select json_compact('{"abc": "foo"}');
select json_unquote(json_compact('{"abc": "foo"}'));
# This is a JSON string, so it is actually unquoted
select json_extract(cast('{"abc": "foo"}' as json), '$.abc');
select json_unquote(json_extract(cast('{"abc": "foo"}' as json), '$.abc'));
select json_extract(json_compact('{"abc": "foo"}'), '$.abc');
select json_unquote(json_extract(json_compact('{"abc": "foo"}'), '$.abc'));
# Bug fix: thse should be the same
select json_unquote('["a", "b", "c"]');
select json_unquote(cast('["a", "b", "c"]' as json));
select json_unquote(json_compact('["a", "b", "c"]'));
select charset(json_unquote('"abc"'));
select json_quote(convert(X'e68891' using utf8)); # chinese "I" (wo3)
select json_quote(convert(X'e68891' using utf8mb4)); # chinese "I" (wo3)
select cast(json_quote(convert(X'e68891' using utf8)) as json);
select json_compact(json_quote(convert(X'e68891' using utf8)));
select json_unquote(convert(X'e68891' using utf8)); # chinese "I" (wo3)
......@@ -1809,12 +1809,12 @@ select json_unquote(json_unquote(json_unquote( # long round trip of it
json_quote(json_quote(json_quote('abc'))))));
# DATE/TIME will lose their quotes, too:
select cast(cast('2015-01-15 23:24:25' as datetime) as json);
select json_unquote(cast(cast('2015-01-15 23:24:25' as datetime) as json));
select json_compact(cast('2015-01-15 23:24:25' as datetime));
select json_unquote(json_compact(cast('2015-01-15 23:24:25' as datetime)));
# as well as opaque values:
select cast(st_geomfromtext('point(1 1)') as json);
select json_unquote(cast(st_geomfromtext('point(1 1)') as json));
select json_compact(st_geomfromtext('point(1 1)'));
select json_unquote(json_compact(st_geomfromtext('point(1 1)')));
# examples from the wl7909 spec
# returns the SQL string literal abc
......@@ -1828,7 +1828,7 @@ SELECT JSON_UNQUOTE( 123 );
# returns the SQL string literal abc
SELECT JSON_UNQUOTE
( CAST( CAST( '"abc"' AS JSON ) AS CHAR ) );
( CAST( json_compact( '"abc"') AS CHAR ) );
# returns 1
SELECT JSON_UNQUOTE
......@@ -1853,7 +1853,7 @@ SELECT JSON_QUOTE( 'abc' );
SELECT JSON_QUOTE( 123 );
# returns the JSON document consisting of the string scalar "123"
SELECT CAST( JSON_QUOTE( '123' ) AS JSON );
SELECT json_compact( JSON_QUOTE( '123' ));
--echo # ----------------------------------------------------------------------
--echo # Test of JSON_CONTAINS
......@@ -1861,47 +1861,47 @@ SELECT CAST( JSON_QUOTE( '123' ) AS JSON );
--echo # should give NULL
select json_contains(NULL, NULL);
select json_contains(cast('{"a": 1, "b": 2}' as json), NULL);
select json_contains(NULL, cast('null' as json));
select json_contains(cast('[1]' as json), cast('[1]' as json), NULL);
select json_contains(json_compact('{"a": 1, "b": 2}'), NULL);
select json_contains(NULL, json_compact('null'));
select json_contains(json_compact('[1]'), json_compact('[1]'), NULL);
--echo # should give 0:
select json_contains(cast(3.14 as json), cast(3 as json));
select json_contains(json_compact(3.14), json_compact(3));
--echo # should give 0: not at top level
select json_contains(cast('{"a": {"b": 7}}' as json), cast('{"b": 7}' as json));
select json_contains(json_compact('{"a": {"b": 7}}'), json_compact('{"b": 7}'));
--echo # but path argument will fix it:
select json_contains(cast('{"a": {"b": 7}}' as json), cast('{"b": 7}' as json), '$.a');
select json_contains(json_compact('{"a": {"b": 7}}'), json_compact('{"b": 7}'), '$.a');
--echo # but arrays "introspect"
select json_contains(cast('[1,[2.0, 3.0]]' as json), cast('[2.0]' as json));
select json_contains(cast('[1, 2, [3, [4, 5]], 6, 7]' as json), cast('5' as json));
select json_contains(json_compact('[1,[2.0, 3.0]]'), json_compact('[2.0]'));
select json_contains(json_compact('[1, 2, [3, [4, 5]], 6, 7]'), json_compact('5'));
--echo # should give 0: just a key
select json_contains(cast('{"a": 1, "b": 2}' as json), cast('"a"' as json));
select json_contains(json_compact('{"a": 1, "b": 2}'), json_compact('"a"'));
--echo # should give 0: one candidate element doesn't match
select json_contains(cast('[1]' as json), cast('[1,2]' as json));
select json_contains(json_compact('[1]'), json_compact('[1,2]'));
--echo # should all give 1
select json_contains(cast('null' as json), cast('null' as json));
select json_contains(json_compact('null'), json_compact('null'));
--echo # simple object subset
select json_contains(cast('{"a": 1, "b": 2}' as json), cast( '{"a": 1}' as json));
select json_contains(json_compact('{"a": 1, "b": 2}'), json_compact( '{"a": 1}'));
--echo # simple vector subset
select json_contains(cast('[1, 2, 3]' as json), cast('[1, 3]' as json));
select json_contains(json_compact('[1, 2, 3]'), json_compact('[1, 3]'));
--echo # auto-wrap, should give 1
select json_contains(cast('[1, 2, 3]' as json), cast(3 as json));
select json_contains(json_compact('[1, 2, 3]'), json_compact(3));
--echo # ok even with nested cast off elements
select json_contains(cast('{"person": {"id": 1, "country": "norway"}}' as json),
cast('{"person": {"country": "norway"}}' as json));
select json_contains(json_compact('{"person": {"id": 1, "country": "norway"}}'),
json_compact('{"person": {"country": "norway"}}'));
--echo # vector reordering and duplicates is ok
select json_contains(cast('[1,3,5]' as json), cast('[5,3,1,5]' as json));
select json_contains(json_compact('[1,3,5]'), json_compact('[5,3,1,5]'));
--echo # ok even with more elts in candidate than in doc
select json_contains(cast('[{"b": 4, "a":7}]' as json), cast('[{"a":7},{"b":4}]' as json));
select json_contains(cast('[{"b": 4, "a":7}, 5]' as json), cast('[5, {"a":7, "b":4}]' as json));
select json_contains(json_compact('[{"b": 4, "a":7}]'), json_compact('[{"a":7},{"b":4}]'));
select json_contains(json_compact('[{"b": 4, "a":7}, 5]'), json_compact('[5, {"a":7, "b":4}]'));
--echo # ok even with mixed number types that compare equal
select json_contains(cast('[{"b": 4, "a":7}, 5.0]' as json), cast('[5, {"a":7.0E0, "b":4}]' as json));
select json_contains(json_compact('[{"b": 4, "a":7}, 5.0]'), json_compact('[5, {"a":7.0E0, "b":4}]'));
# Bug discovered by Rick: used to give 1 (true).
select json_contains( '{"customer": "cust3"}', '{"customer": "cust1"}' );
......@@ -1919,36 +1919,36 @@ SELECT JSON_CONTAINS('{"a":1}', '{"a":1,"b":2}');
# returns 1
SELECT JSON_CONTAINS
(
CAST('[1, 4, 6]' AS JSON),
CAST('[1, 6]' AS JSON)
json_compact('[1, 4, 6]'),
json_compact('[1, 6]')
);
# returns 1; even with nested cast off elements
SELECT JSON_CONTAINS
(
CAST('{"person": {"id": 1, "country": "norway"}}' AS JSON),
CAST('{"person": {"country": "norway"}}' AS JSON)
json_compact('{"person": {"id": 1, "country": "norway"}}'),
json_compact('{"person": {"country": "norway"}}')
);
# returns 1; reordering and duplicates are ok
SELECT JSON_CONTAINS
(
CAST('[1,3,5]' AS JSON),
CAST('[5,3,1,5]' AS JSON)
json_compact('[1,3,5]'),
json_compact('[5,3,1,5]')
);
# return 0; no type conversion is performed
SELECT JSON_CONTAINS
(
CAST('[3.14]' AS JSON),
CAST('[3]' AS JSON)
json_compact('[3.14]'),
json_compact('[3]')
);
# returns 1, due to auto-wrapping
SELECT JSON_CONTAINS
(
CAST('[1, 2, 3]' AS JSON),
CAST(3 AS JSON)
json_compact('[1, 2, 3]'),
json_compact(3)
);
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
......@@ -1963,20 +1963,20 @@ SELECT JSON_CONTAINS('[1]', '[1]', '$', '$[0]');
--echo # Item_func_json_quote::fix_length_and_dec. Bug found by Knut.
--echo # Similar issue for JSON_UNQUOTE and JSON_TYPE.
--echo # ----------------------------------------------------------------------
select json_object("a", ifnull(json_quote('test'), cast('null' as json)));
select cast(concat('[', json_quote('ab'), ']') as json);
select cast(concat('[', json_unquote('"12"'), ']') as json);
select cast(concat('["', json_type(cast(1 as json)), '"]') as json);
select json_object("a", ifnull(json_quote('test'), json_compact('null')));
select json_compact(concat('[', json_quote('ab'), ']'));
select json_compact(concat('[', json_unquote('"12"'), ']'));
select json_compact(concat('["', json_type( json_compact(1)), '"]'));
--echo #
--echo # Bug#20912438: ITEM_TYPE_HOLDER::DISPLAY_LENGTH(ITEM*): ASSERTION `0' FAILED
--echo #
(SELECT JSON_KEYS('{ "key80": "2015-04-20 11:53:55"}')) UNION ALL
(SELECT JSON_KEYS('{ "key80": "2015-04-20 11:53:55" }') LIMIT 0);
SELECT CAST(1 AS JSON) UNION ALL SELECT CAST(1 AS JSON);
SELECT json_compact(1) UNION ALL SELECT json_compact(1);
# Exercise NULL handling and error handling in Item_copy_json::copy().
SELECT COUNT(*), CAST(NULL AS JSON);
SELECT COUNT(*), json_compact(NULL);
--echo error ER_INVALID_JSON_TEXT_IN_PARAM
SELECT COUNT(*), JSON_EXTRACT('not valid json!', '$');
......@@ -2118,7 +2118,7 @@ execute json_stmt12 USING @mypath;
--echo #
select json_quote( json_type( json_object() ) );
select json_quote( json_type( cast('{}' as json) ) );
select json_quote( json_type( json_compact('{}') ) );
--echo #
--echo # Bug#21148020 OUTPUT FROM JSON_TYPE() IS TRUNCATED
......@@ -2130,9 +2130,9 @@ CREATE VIEW v1 AS SELECT JSON_TYPE(JSON_OBJECT());
SELECT * FROM v1;
drop view v1;
# SELECT JSON_TYPE(CAST(CAST('2015-05-25 11:23:55' AS DATETIME) AS JSON));
# CREATE VIEW v2 AS SELECT JSON_TYPE(CAST(CAST('2015-05-25 11:23:55' AS
# DATETIME) AS JSON));
# SELECT JSON_TYPE(json_compact(CAST('2015-05-25 11:23:55' AS DATETIME)));
# CREATE VIEW v2 AS SELECT JSON_TYPE(json_compact(CAST('2015-05-25 11:23:55' AS
# DATETIME)));
# SELECT * FROM v2;
# drop view v2;
......@@ -2284,5 +2284,5 @@ SELECT JSON_REPLACE('[[[1]]]', '$[0][0][0]', 100);
# a mix of NULLs and JSON values.
SELECT JSON_ARRAY(LEAST(NULL, NULL), GREATEST(NULL, NULL), LEAST(j1, NULL),
GREATEST(NULL, j2), LEAST(j1, j2), GREATEST(j1, j2)) AS j
FROM (SELECT CAST('1' AS JSON) AS j1, CAST('2' AS JSON) AS j2) t;
FROM (SELECT json_compact('1') AS j1, json_compact('2') AS j2) t;
......@@ -161,10 +161,10 @@ select json_unquote('abc');
select json_object("a", json_object("b", "abcd"));
select json_object("a", '{"b": "abcd"}');
select json_object("a", cast('{"b": "abcd"}' as json));
select json_object("a", json_compact('{"b": "abcd"}'));
select cast(NULL AS JSON);
select json_depth(cast(NULL as JSON));
select json_compact(NULL);
select json_depth(json_compact(NULL));
select json_depth('[[], {}]');
select json_depth('[[[1,2,3],"s"], {}, []]');
select json_depth('[10, {"a": 20}]');
......
......@@ -1095,6 +1095,8 @@ class Item: public Value_source,
Returns the val_str() value converted to the given character set.
*/
String *val_str(String *str, String *converter, CHARSET_INFO *to);
virtual String *val_json(String *str) { return val_str(str); }
/*
Return decimal representation of item with fixed point.
......
......@@ -7228,9 +7228,6 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type,
res= new (thd->mem_root) Item_char_typecast(thd, a, len, real_cs);
break;
}
case ITEM_CAST_JSON:
res= new (thd->mem_root) Item_json_typecast(thd, a);
break;
default:
{
DBUG_ASSERT(0);
......
......@@ -2221,7 +2221,7 @@ enum Cast_target
{
ITEM_CAST_BINARY, ITEM_CAST_SIGNED_INT, ITEM_CAST_UNSIGNED_INT,
ITEM_CAST_DATE, ITEM_CAST_TIME, ITEM_CAST_DATETIME, ITEM_CAST_CHAR,
ITEM_CAST_DECIMAL, ITEM_CAST_DOUBLE, ITEM_CAST_JSON
ITEM_CAST_DECIMAL, ITEM_CAST_DOUBLE
};
......
......@@ -373,7 +373,7 @@ static int path_setup_nwc(json_path_t *p, CHARSET_INFO *i_cs,
longlong Item_func_json_valid::val_int()
{
String *js= args[0]->val_str(&tmp_value);
String *js= args[0]->val_json(&tmp_value);
json_engine_t je;
if ((null_value= args[0]->null_value))
......@@ -401,7 +401,7 @@ longlong Item_func_json_exists::val_int()
json_engine_t je;
uint array_counters[JSON_DEPTH_LIMIT];
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
if (!path.parsed)
{
......@@ -454,7 +454,7 @@ void Item_func_json_value::fix_length_and_dec()
String *Item_func_json_value::val_str(String *str)
{
json_engine_t je;
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
int error= 0;
uint array_counters[JSON_DEPTH_LIMIT];
......@@ -587,7 +587,7 @@ void Item_func_json_unquote::fix_length_and_dec()
String *Item_func_json_unquote::val_str(String *str)
{
String *js= args[0]->val_str(&tmp_s);
String *js= args[0]->val_json(&tmp_s);
json_engine_t je;
int c_len;
......@@ -712,7 +712,7 @@ static bool path_ok(const json_path_with_flags *paths_list, int n_paths,
String *Item_func_json_extract::val_str(String *str)
{
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
json_engine_t je, sav_je;
json_path_t p;
const uchar *value;
......@@ -817,7 +817,7 @@ String *Item_func_json_extract::val_str(String *str)
longlong Item_func_json_extract::val_int()
{
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
uint n_arg;
uint array_counters[JSON_DEPTH_LIMIT];
......@@ -1040,7 +1040,7 @@ static int check_contains(json_engine_t *js, json_engine_t *value)
longlong Item_func_json_contains::val_int()
{
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
json_engine_t je, ve;
int result;
......@@ -1049,7 +1049,7 @@ longlong Item_func_json_contains::val_int()
if (!a2_parsed)
{
val= args[1]->val_str(&tmp_val);
val= args[1]->val_json(&tmp_val);
a2_parsed= a2_constant;
}
......@@ -1179,7 +1179,7 @@ static int parse_one_or_all(const Item_func *f, Item *ooa_arg,
#ifdef DUMMY
longlong Item_func_json_contains_path::val_int()
{
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
uint n_arg;
longlong result;
......@@ -1247,7 +1247,7 @@ longlong Item_func_json_contains_path::val_int()
longlong Item_func_json_contains_path::val_int()
{
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
uint n_arg;
longlong result;
......@@ -1351,7 +1351,7 @@ static int append_json_value(String *str, Item *item, String *tmp_val)
return str->append(t_f, t_f_len);
}
{
String *sv= item->val_str(tmp_val);
String *sv= item->val_json(tmp_val);
if (item->null_value)
goto append_null;
if (item->is_json_type())
......@@ -1461,7 +1461,7 @@ void Item_func_json_array_append::fix_length_and_dec()
String *Item_func_json_array_append::val_str(String *str)
{
json_engine_t je;
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
uint n_arg, n_path, str_rest_len;
const uchar *ar_end;
......@@ -1588,7 +1588,7 @@ String *Item_func_json_array_append::val_str(String *str)
String *Item_func_json_array_insert::val_str(String *str)
{
json_engine_t je;
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
uint n_arg, n_path;
DBUG_ASSERT(fixed == 1);
......@@ -1959,7 +1959,7 @@ String *Item_func_json_merge::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
json_engine_t je1, je2;
String *js1= args[0]->val_str(&tmp_js1), *js2;
String *js1= args[0]->val_json(&tmp_js1), *js2;
uint n_arg;
if (args[0]->null_value)
......@@ -1970,7 +1970,7 @@ String *Item_func_json_merge::val_str(String *str)
str->set_charset(js1->charset());
str->length(0);
js2= args[n_arg]->val_str(&tmp_js2);
js2= args[n_arg]->val_json(&tmp_js2);
if (args[n_arg]->null_value)
goto null_return;
......@@ -2028,7 +2028,7 @@ void Item_func_json_length::fix_length_and_dec()
longlong Item_func_json_length::val_int()
{
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
uint length= 0;
uint array_counters[JSON_DEPTH_LIMIT];
......@@ -2105,7 +2105,7 @@ longlong Item_func_json_length::val_int()
longlong Item_func_json_depth::val_int()
{
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
uint depth= 0, c_depth= 0;
bool inc_depth= TRUE;
......@@ -2164,7 +2164,7 @@ void Item_func_json_type::fix_length_and_dec()
String *Item_func_json_type::val_str(String *str)
{
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
const char *type;
......@@ -2232,7 +2232,7 @@ void Item_func_json_insert::fix_length_and_dec()
String *Item_func_json_insert::val_str(String *str)
{
json_engine_t je;
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
uint n_arg, n_path;
json_string_t key_name;
......@@ -2478,7 +2478,7 @@ void Item_func_json_remove::fix_length_and_dec()
String *Item_func_json_remove::val_str(String *str)
{
json_engine_t je;
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
uint n_arg, n_path;
json_string_t key_name;
......@@ -2661,7 +2661,7 @@ void Item_func_json_keys::fix_length_and_dec()
String *Item_func_json_keys::val_str(String *str)
{
json_engine_t je;
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
uint n_keys= 0;
uint array_counters[JSON_DEPTH_LIMIT];
......@@ -2837,7 +2837,7 @@ static int append_json_path(String *str, const json_path_t *p)
String *Item_func_json_search::val_str(String *str)
{
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
String *s_str= args[2]->val_str(&tmp_js);
json_engine_t je;
json_path_t p, sav_path;
......@@ -2934,21 +2934,6 @@ String *Item_func_json_search::val_str(String *str)
}
void Item_json_typecast::fix_length_and_dec()
{
maybe_null= args[0]->maybe_null;
max_length= args[0]->max_length;
}
String *Item_json_typecast::val_str(String *str)
{
String *vs= args[0]->val_str(str);
null_value= args[0]->null_value;
return vs;
}
const char *Item_func_json_format::func_name() const
{
switch (fmt)
......@@ -2976,7 +2961,7 @@ void Item_func_json_format::fix_length_and_dec()
String *Item_func_json_format::val_str(String *str)
{
String *js= args[0]->val_str(&tmp_js);
String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
int tab_size= 4;
......@@ -3016,3 +3001,12 @@ String *Item_func_json_format::val_str(String *str)
}
String *Item_func_json_format::val_json(String *str)
{
String *js= args[0]->val_json(&tmp_js);
if ((null_value= args[0]->null_value))
return 0;
return js;
}
......@@ -414,19 +414,6 @@ class Item_func_json_search: public Item_json_str_multipath
};
class Item_json_typecast: public Item_str_func
{
public:
Item_json_typecast(THD *thd, Item *a): Item_str_func(thd, a) {}
const char *func_name() const { return "cast_as_json"; }
bool is_json_type() { return true; }
void fix_length_and_dec();
String *val_str(String *str);
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_json_typecast>(thd, mem_root, this); }
};
class Item_func_json_format: public Item_str_func
{
public:
......@@ -449,6 +436,8 @@ class Item_func_json_format: public Item_str_func
const char *func_name() const;
void fix_length_and_dec();
String *val_str(String *str);
String *val_json(String *str);
bool is_json_type() { return true; }
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_func_json_format>(thd, mem_root, this); }
};
......
......@@ -7417,7 +7417,7 @@ ER_BINLOG_UNCOMPRESS_ERROR
ER_JSON_BAD_CHR
eng "Broken JSON string in argument %d to function '%s' at position %d"
ER_JSON_NOT_JSON_CHR
eng "Character disallowd in JSON in argument %d to function '%s' at position %d"
eng "Character disallowed in JSON in argument %d to function '%s' at position %d"
ER_JSON_EOS
eng "Unexpected end of JSON text in argument %d to function '%s'"
ER_JSON_SYNTAX
......
......@@ -10714,7 +10714,6 @@ cast_type:
}
| cast_type_numeric { $$= $1; Lex->charset= NULL; }
| cast_type_temporal { $$= $1; Lex->charset= NULL; }
| JSON_SYM { $$.set(ITEM_CAST_JSON); }
;
cast_type_numeric:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment