You've already forked mariadb-columnstore-engine
							
							
				mirror of
				https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
				synced 2025-11-03 17:13:17 +03:00 
			
		
		
		
	The following functions are created: Create function JSON_VALID and test cases Create function JSON_DEPTH and test cases Create function JSON_LENGTH and test cases Create function JSON_EQUALS and test cases Create function JSON_NORMALIZE and test cases Create function JSON_TYPE and test cases Create function JSON_OBJECT and test cases Create function JSON_ARRAY and test cases Create function JSON_KEYS and test cases Create function JSON_EXISTS and test cases Create function JSON_QUOTE/JSON_UNQUOTE and test cases Create function JSON_COMPACT/DETAILED/LOOSE and test cases Create function JSON_MERGE and test cases Create function JSON_MERGE_PATCH and test cases Create function JSON_VALUE and test cases Create function JSON_QUERY and test cases Create function JSON_CONTAINS and test cases Create function JSON_ARRAY_APPEND and test cases Create function JSON_ARRAY_INSERT and test cases Create function JSON_INSERT/REPLACE/SET and test cases Create function JSON_REMOVE and test cases Create function JSON_CONTAINS_PATH and test cases Create function JSON_OVERLAPS and test cases Create function JSON_EXTRACT and test cases Create function JSON_SEARCH and test cases Note: Some functions output differs from MDB because session variables that affects functions output,e.g JSON_QUOTE/JSON_UNQUOTE This depends on MCOL-5212
		
			
				
	
	
		
			124 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			124 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
DROP DATABASE IF EXISTS json_length_db;
 | 
						|
CREATE DATABASE json_length_db;
 | 
						|
USE json_length_db;
 | 
						|
# ----------------------------------------------------------------------
 | 
						|
# Test of JSON_LENGTH function.
 | 
						|
# ----------------------------------------------------------------------
 | 
						|
CREATE TABLE t1(l LONGTEXT) ENGINE = columnstore;
 | 
						|
# Invalid json text
 | 
						|
INSERT INTO t1 VALUES(null);
 | 
						|
INSERT INTO t1 VALUES('1');
 | 
						|
INSERT INTO t1 VALUES('abc');
 | 
						|
INSERT INTO t1 VALUES('"abc"');
 | 
						|
INSERT INTO t1 VALUES('true');
 | 
						|
INSERT INTO t1 VALUES('false');
 | 
						|
INSERT INTO t1 VALUES('null');
 | 
						|
error ER_INVALID_JSON_TEXT_IN_PARAM
 | 
						|
SELECT JSON_LENGTH(l) FROM t1;
 | 
						|
JSON_LENGTH(l)
 | 
						|
NULL
 | 
						|
1
 | 
						|
NULL
 | 
						|
1
 | 
						|
1
 | 
						|
1
 | 
						|
1
 | 
						|
# Valid json text 
 | 
						|
TRUNCATE t1;
 | 
						|
INSERT INTO t1 VALUES('{}');
 | 
						|
INSERT INTO t1 VALUES('{ "a" : 100, "b" : 200 }');
 | 
						|
INSERT INTO t1 VALUES('{ "a" : 100, "b" : [ 300, 400, 500 ] }');
 | 
						|
INSERT INTO t1 VALUES('[]');
 | 
						|
INSERT INTO t1 VALUES('[ null, "foo", true, 1.1 ]');
 | 
						|
INSERT INTO t1 VALUES('[ null, "foo", true, { "a" : "b", "c" : "d" } ]');
 | 
						|
INSERT INTO t1 VALUES('"foo"');
 | 
						|
INSERT INTO t1 VALUES('1.2');
 | 
						|
SELECT JSON_LENGTH(l) FROM t1;
 | 
						|
JSON_LENGTH(l)
 | 
						|
0
 | 
						|
2
 | 
						|
2
 | 
						|
0
 | 
						|
4
 | 
						|
4
 | 
						|
1
 | 
						|
1
 | 
						|
# Bad path expressions
 | 
						|
TRUNCATE t1;
 | 
						|
INSERT INTO t1 VALUES('true');
 | 
						|
error ER_INVALID_JSON_PATH
 | 
						|
SELECT JSON_LENGTH(l, 'c$') FROM t1;
 | 
						|
JSON_LENGTH(l, 'c$')
 | 
						|
NULL
 | 
						|
TRUNCATE t1;
 | 
						|
INSERT INTO t1 VALUES('{ "foo" : [ true, false ] }');
 | 
						|
error ER_INVALID_JSON_PATH
 | 
						|
SELECT JSON_LENGTH(l, '$.foo[bar]') FROM t1;
 | 
						|
JSON_LENGTH(l, '$.foo[bar]')
 | 
						|
NULL
 | 
						|
# wildcards not allowed in path expressions for this function
 | 
						|
TRUNCATE t1;
 | 
						|
INSERT INTO t1 VALUES('true');
 | 
						|
error ER_INVALID_JSON_PATH_WILDCARD
 | 
						|
SELECT JSON_LENGTH(l, '$.*') FROM t1;
 | 
						|
JSON_LENGTH(l, '$.*')
 | 
						|
NULL
 | 
						|
TRUNCATE t1;
 | 
						|
INSERT INTO t1 VALUES('true');
 | 
						|
error ER_INVALID_JSON_PATH_WILDCARD
 | 
						|
SELECT JSON_LENGTH(l, '$.foo**.bar') FROM t1;
 | 
						|
JSON_LENGTH(l, '$.foo**.bar')
 | 
						|
NULL
 | 
						|
# Error ER_INVALID_JSON_TEXT_IN_PARAM
 | 
						|
TRUNCATE t1;
 | 
						|
INSERT INTO t1 VALUES('abc');
 | 
						|
INSERT INTO t1 VALUES('[ "a", true, "b" , { "e" : false }, "c" , null');
 | 
						|
SELECT JSON_LENGTH(l) FROM t1;
 | 
						|
JSON_LENGTH(l)
 | 
						|
NULL
 | 
						|
NULL
 | 
						|
# Path exist
 | 
						|
TRUNCATE t1;
 | 
						|
INSERT INTO t1 VALUES('[ 1, [ 2, 3, 4 ], 5 ]');
 | 
						|
SELECT JSON_LENGTH(l, '$[0]') FROM t1;
 | 
						|
JSON_LENGTH(l, '$[0]')
 | 
						|
1
 | 
						|
SELECT JSON_LENGTH(l, '$[1]') FROM t1;
 | 
						|
JSON_LENGTH(l, '$[1]')
 | 
						|
3
 | 
						|
SELECT JSON_LENGTH(l, '$[2]') FROM t1;
 | 
						|
JSON_LENGTH(l, '$[2]')
 | 
						|
1
 | 
						|
SELECT JSON_LENGTH(l, '$[2][0]') FROM t1;
 | 
						|
JSON_LENGTH(l, '$[2][0]')
 | 
						|
1
 | 
						|
TRUNCATE t1;
 | 
						|
INSERT INTO t1 VALUES('[ 1, [ 2, 3, 4 ], {"a": 1} ]');
 | 
						|
SELECT JSON_LENGTH(l, '$[2][0]') FROM t1;
 | 
						|
JSON_LENGTH(l, '$[2][0]')
 | 
						|
1
 | 
						|
TRUNCATE t1;
 | 
						|
INSERT INTO t1 VALUES('[ 1, { "a": true, "b": false, "c": null }, 5 ]');
 | 
						|
SELECT JSON_LENGTH(l, '$[1]') FROM t1;
 | 
						|
JSON_LENGTH(l, '$[1]')
 | 
						|
3
 | 
						|
TRUNCATE t1;
 | 
						|
INSERT INTO t1 VALUES('{ "a" : 123, "b" : [ 123, 456, 789 ] }');
 | 
						|
SELECT JSON_LENGTH(l) FROM t1;
 | 
						|
JSON_LENGTH(l)
 | 
						|
2
 | 
						|
SELECT JSON_LENGTH(l, '$.b') FROM t1;
 | 
						|
JSON_LENGTH(l, '$.b')
 | 
						|
3
 | 
						|
SELECT JSON_LENGTH(l, '$.c') FROM t1;
 | 
						|
JSON_LENGTH(l, '$.c')
 | 
						|
NULL
 | 
						|
# No-existent path
 | 
						|
TRUNCATE t1;
 | 
						|
INSERT INTO t1 VALUES('[ 1, [ 2, 3, 4 ], 5 ]');
 | 
						|
SELECT JSON_LENGTH(l, '$[2][1]') FROM t1;
 | 
						|
JSON_LENGTH(l, '$[2][1]')
 | 
						|
NULL
 | 
						|
DROP TABLE t1;
 | 
						|
DROP DATABASE json_length_db;
 |