1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-04-20 09:07:44 +03:00
Sergey Zefirov b53c231ca6 MCOL-271 empty strings should not be NULLs (#2794)
This patch improves handling of NULLs in textual fields in ColumnStore.
Previously empty strings were considered NULLs and it could be a problem
if data scheme allows for empty strings. It was also one of major
reasons of behavior difference between ColumnStore and other engines in
MariaDB family.

Also, this patch fixes some other bugs and incorrect behavior, for
example, incorrect comparison for "column <= ''" which evaluates to
constant True for all purposes before this patch.
2023-03-30 21:18:29 +03:00

82 lines
1.8 KiB
Plaintext

DROP DATABASE IF EXISTS json_contains_db;
CREATE DATABASE json_contains_db;
USE json_contains_db;
# ----------------------------------------------------------------------
# Test of JSON_CONTAINS function.
# ----------------------------------------------------------------------
CREATE TABLE t1(j LONGTEXT, v LONGTEXT, p LONGTEXT) ENGINE = columnstore;
INSERT INTO
t1
VALUES
('{"k1":123, "k2":345}', '123', '$.k1'),
('', '', '$'),
('null', 'null', '$'),
('"10"', '"10"', '$'),
('"10"', '10', '$'),
('10.1', '10', '$'),
('10.0', '10', '$');
SELECT
j AS json,
v AS value,
p AS path,
JSON_CONTAINS(j, v, p) AS result
FROM
t1;
json value path result
{"k1":123, "k2":345} 123 $.k1 1
$ NULL
null null $ 1
"10" "10" $ 1
"10" 10 $ 0
10.1 10 $ 0
10.0 10 $ 1
CREATE TABLE t2(j LONGTEXT, v LONGTEXT) ENGINE = columnstore;
INSERT INTO
t2
VALUES
('"you"', '"you"'),
('"youth"', '"you"'),
('[1]', '1'),
('[2, 1]', '1'),
('[2, [2, 3], 1]', '1'),
('[4, [2, 3], 1]', '2'),
('[2, 1]', '[1, 2]'),
('[2, 1]', '[1, 0, 2]'),
('[2, 0, 3, 1]', '[1, 2]'),
('{"b":[1,2], "a":1}', '{"a":1, "b":2}'),
('{"a":1}', '{}'),
('[1, {"a":1}]', '{}'),
('[1, {"a":1}]', '{"a":1}'),
('[{"abc":"def", "def":"abc"}]', '["foo","bar"]'),
(
'[{"abc":"def", "def":"abc"}, "bar"]',
'["bar", {}]'
),
('[{"a":"b"},{"c":"d"}]', '{"c":"d"}');
SELECT
j AS json,
v AS value,
JSON_CONTAINS(j, v) AS result
FROM
t2;
json value result
"you" "you" 1
"youth" "you" 0
[1] 1 1
[2, 1] 1 1
[2, [2, 3], 1] 1 1
[4, [2, 3], 1] 2 1
[2, 1] [1, 2] 1
[2, 1] [1, 0, 2] 0
[2, 0, 3, 1] [1, 2] 1
{"b":[1,2], "a":1} {"a":1, "b":2} 1
{"a":1} {} 1
[1, {"a":1}] {} 1
[1, {"a":1}] {"a":1} 1
[{"abc":"def", "def":"abc"}] ["foo","bar"] 0
[{"abc":"def", "def":"abc"}, "bar"] ["bar", {}] 1
[{"a":"b"},{"c":"d"}] {"c":"d"} 1
DROP TABLE t2;
DROP TABLE t1;
DROP DATABASE json_contains_db;