-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MDEV-39998 Fix JSON_OVERLAPS asymmetry for nested array comparison #5239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # | ||
| # MDEV-39998: JSON_OVERLAPS asymmetry for ordered array comparison | ||
| # | ||
| SELECT JSON_OVERLAPS('[[1,2]]', '[[1]]') AS must_be_0; | ||
| must_be_0 | ||
| 0 | ||
| SELECT JSON_OVERLAPS('[[1]]', '[[1,2]]') AS must_be_0_too; | ||
| must_be_0_too | ||
| 0 | ||
| SELECT JSON_OVERLAPS('[[1,2]]', '[[1,2]]') AS must_be_1; | ||
| must_be_1 | ||
| 1 | ||
| SELECT JSON_OVERLAPS('[[1,2,3]]', '[[1,2]]') AS r1, | ||
| JSON_OVERLAPS('[[1,2]]', '[[1,2,3]]') AS r2; | ||
| r1 r2 | ||
| 0 0 | ||
| SELECT JSON_OVERLAPS('[1,2,3]', '[3,4,5]') AS scalar_overlap; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not needed too. |
||
| scalar_overlap | ||
| 1 | ||
| SELECT JSON_OVERLAPS('[[]]', '[[]]') AS empty_match; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed. There's more that are not needed below. Please keep only the one(s) that exercise the new code in unique ways. |
||
| empty_match | ||
| 1 | ||
| SELECT JSON_OVERLAPS('[[1]]', '[[]]') AS r1, | ||
| JSON_OVERLAPS('[[]]', '[[1]]') AS r2; | ||
| r1 r2 | ||
| 0 0 | ||
| SELECT JSON_OVERLAPS('[{"a":1}]', '[{"a":1}]') AS obj_match; | ||
| obj_match | ||
| 1 | ||
| SELECT JSON_OVERLAPS('[{"a":1,"b":2}]', '[{"a":1}]') AS r1, | ||
| JSON_OVERLAPS('[{"a":1}]', '[{"a":1,"b":2}]') AS r2; | ||
| r1 r2 | ||
| 0 0 | ||
| SELECT JSON_OVERLAPS('[[[1,2]]]', '[[[1]]]') AS r1, | ||
| JSON_OVERLAPS('[[[1]]]', '[[[1,2]]]') AS r2; | ||
| r1 r2 | ||
| 0 0 | ||
| SELECT JSON_OVERLAPS('[[[1,2]]]', '[[[1,2]]]') AS deep_match; | ||
| deep_match | ||
| 1 | ||
| SELECT JSON_OVERLAPS(NULL, '[[1]]') AS r1, | ||
| JSON_OVERLAPS('[[1]]', NULL) AS r2; | ||
| r1 r2 | ||
| NULL NULL | ||
| SELECT JSON_OVERLAPS('[1,[1,2]]', '[[1,2],1]') AS mixed_match; | ||
| mixed_match | ||
| 1 | ||
| SELECT JSON_OVERLAPS('[1,[1,2]]', '[[1],1]') AS r1, | ||
| JSON_OVERLAPS('[[1],1]', '[1,[1,2]]') AS r2; | ||
| r1 r2 | ||
| 1 1 | ||
| SELECT JSON_OVERLAPS('[[1]]', '[[1]]') AS single_match; | ||
| single_match | ||
| 1 | ||
| SELECT JSON_OVERLAPS('[["a"]]', '[["a","b"]]') AS r1, | ||
| JSON_OVERLAPS('[["a","b"]]', '[["a"]]') AS r2; | ||
| r1 r2 | ||
| 0 0 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # | ||
| # MDEV-39998: JSON_OVERLAPS must be symmetric for nested arrays | ||
| # | ||
|
|
||
| --echo # | ||
| --echo # MDEV-39998: JSON_OVERLAPS asymmetry for ordered array comparison | ||
| --echo # | ||
|
|
||
| # Original reported bug: prefix of nested array falsely matches | ||
| SELECT JSON_OVERLAPS('[[1,2]]', '[[1]]') AS must_be_0; | ||
| SELECT JSON_OVERLAPS('[[1]]', '[[1,2]]') AS must_be_0_too; | ||
|
|
||
| # Exact match must still work | ||
| SELECT JSON_OVERLAPS('[[1,2]]', '[[1,2]]') AS must_be_1; | ||
|
|
||
| # Both directions must agree (symmetry) | ||
| SELECT JSON_OVERLAPS('[[1,2,3]]', '[[1,2]]') AS r1, | ||
| JSON_OVERLAPS('[[1,2]]', '[[1,2,3]]') AS r2; | ||
|
|
||
| # Scalar overlap still works | ||
| SELECT JSON_OVERLAPS('[1,2,3]', '[3,4,5]') AS scalar_overlap; | ||
|
|
||
| # Empty nested arrays | ||
| SELECT JSON_OVERLAPS('[[]]', '[[]]') AS empty_match; | ||
| SELECT JSON_OVERLAPS('[[1]]', '[[]]') AS r1, | ||
| JSON_OVERLAPS('[[]]', '[[1]]') AS r2; | ||
|
|
||
| # Nested objects inside arrays | ||
| SELECT JSON_OVERLAPS('[{"a":1}]', '[{"a":1}]') AS obj_match; | ||
| SELECT JSON_OVERLAPS('[{"a":1,"b":2}]', '[{"a":1}]') AS r1, | ||
| JSON_OVERLAPS('[{"a":1}]', '[{"a":1,"b":2}]') AS r2; | ||
|
|
||
| # Deeply nested arrays | ||
| SELECT JSON_OVERLAPS('[[[1,2]]]', '[[[1]]]') AS r1, | ||
| JSON_OVERLAPS('[[[1]]]', '[[[1,2]]]') AS r2; | ||
| SELECT JSON_OVERLAPS('[[[1,2]]]', '[[[1,2]]]') AS deep_match; | ||
|
|
||
| # NULL handling | ||
| SELECT JSON_OVERLAPS(NULL, '[[1]]') AS r1, | ||
| JSON_OVERLAPS('[[1]]', NULL) AS r2; | ||
|
|
||
| # Mixed types in outer array | ||
| SELECT JSON_OVERLAPS('[1,[1,2]]', '[[1,2],1]') AS mixed_match; | ||
| SELECT JSON_OVERLAPS('[1,[1,2]]', '[[1],1]') AS r1, | ||
| JSON_OVERLAPS('[[1],1]', '[1,[1,2]]') AS r2; | ||
|
|
||
| # Single element arrays | ||
| SELECT JSON_OVERLAPS('[[1]]', '[[1]]') AS single_match; | ||
| SELECT JSON_OVERLAPS('[["a"]]', '[["a","b"]]') AS r1, | ||
| JSON_OVERLAPS('[["a","b"]]', '[["a"]]') AS r2; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5071,8 +5071,8 @@ bool json_compare_arrays_in_order(json_engine_t *js, json_engine_t *value, | |
| return FALSE; | ||
| } | ||
| } | ||
| res= (value->state == JST_ARRAY_END || value->state == JST_OBJ_END ? | ||
| TRUE : FALSE); | ||
| res= (value->state == JST_ARRAY_END || value->state == JST_OBJ_END) && | ||
| (js->state == JST_ARRAY_END || js->state == JST_OBJ_END); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of your tests are with arrays. But there's also the same issue with JST_OBJ_END. Can you maybe add few tests that exercise that? Is it at all possible that value->state is JST_OBJ_END and js->state is JST_ARRAY_END? I'd guess not. So how about comparing the two states? |
||
| json_skip_current_level(js, value); | ||
| return res; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep the tests to the minimum required to fully cover the new functionality. This one is not needed. There's a very extensive test in func_json.test already.