From a04ec8ea005be94de9ed28683198f7e1c1dd664b Mon Sep 17 00:00:00 2001 From: Jinrui Zhang Date: Wed, 2 Jul 2025 16:45:43 +0000 Subject: [PATCH] Merged PR 1713380: [oss][test cleanup] test check for regex related case ### Description [oss][test cleanup] test check for regex related case ---- #### AI description (iteration 1) #### PR Classification This pull request performs test cleanup by standardizing regex test cases. #### PR Summary The PR refactors multiple regex test files to improve consistency by renaming JSON keys and updating test string values and patterns. - Files like `oss/internal/pg_documentdb_distributed/src/test/regress/expected/regex_options_index.out` and `.../sql/regex_options_core.sql` now use the key `msg` with updated regex patterns in place of the old key. - Files such as `oss/internal/pg_documentdb_distributed/src/test/regress/expected/regex.out` (and the corresponding `/pgmongo` versions) change the key from `sku` to `b` and adjust description texts and Unicode values. - SQL scripts in `.../sql/regex.sql` are updated accordingly to reflect these key renames and ensure accurate index creation and count validations. --- .../src/test/regress/expected/regex.out | 82 +++++++++---------- .../regress/expected/regex_options_index.out | 56 ++++++------- .../expected/regex_options_runtime.out | 56 ++++++------- .../src/test/regress/sql/regex.sql | 30 +++---- .../test/regress/sql/regex_options_core.sql | 54 ++++++------ 5 files changed, 139 insertions(+), 139 deletions(-) diff --git a/internal/pg_documentdb_distributed/src/test/regress/expected/regex.out b/internal/pg_documentdb_distributed/src/test/regress/expected/regex.out index a5903515..65d20a20 100644 --- a/internal/pg_documentdb_distributed/src/test/regress/expected/regex.out +++ b/internal/pg_documentdb_distributed/src/test/regress/expected/regex.out @@ -9,43 +9,43 @@ NOTICE: creating collection t (1 row) -SELECT insert_one('db','regex', '{"_id" : 99, "sku": "abc123"}'); +SELECT insert_one('db','regex', '{"_id" : 99, "b": "abc123"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex', '{"_id" : 100, "sku" : "abc123", "description" : "Single line description." }'); +SELECT insert_one('db','regex', '{"_id" : 100, "b" : "abc123", "description" : "this is single line " }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex', '{"_id" : 101, "sku" : "abc789", "description" : "single line\nSecond line" }'); +SELECT insert_one('db','regex', '{"_id" : 101, "b" : "abc789", "description" : "this is tow-line. single line\nSecond line" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex', '{"_id" : 102, "sku" : "xyz456", "description" : "Many spaces before line" }'); +SELECT insert_one('db','regex', '{"_id" : 102, "b" : "xyz456", "description" : "there are some spaces. Many spaces before line" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex', '{"_id" : 103, "sku" : "xyz789", "description" : "Multiple\nline description" }'); +SELECT insert_one('db','regex', '{"_id" : 103, "b" : "xyz789", "description" : "this is Multiple\nline description" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex', '{"_id" : 104, "sku" : "xyz790", "description" : "Multiple\n incline description" }'); +SELECT insert_one('db','regex', '{"_id" : 104, "b" : "xyz790", "description" : "this is Multiple\n incline description" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex', '{"_id" : 105, "sku" : "xyz800", "description" : "Multiple\n in\bcline \bdescription" }'); +SELECT insert_one('db','regex', '{"_id" : 105, "b" : "xyz800", "description" : "this is Multiple\n in\bcline \bdescription" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } @@ -69,7 +69,7 @@ SELECT insert_one('db','regex', '{"_id" : 108, "a" : {"$regularExpression" : {"p { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex', '{"_id" : 109, "sku" : "xyz810", "description" : "Multiple\n in\\ycline \bdescription"}'); +SELECT insert_one('db','regex', '{"_id" : 109, "b" : "xyz810", "description" : "Multiple\n in\\ycline \bdescription"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } @@ -124,7 +124,7 @@ SELECT insert_one('db','regex', '{"_id" : 117, "a" : "a value7", "b": "b value7" (1 row) -- Some unicodes & mixed numerical -SELECT insert_one('db','regex', '{"_id" : 120, "number" : "༢༣༤༥"}'); +SELECT insert_one('db','regex', '{"_id" : 120, "number" : "୩༢༣༤༥"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } @@ -136,7 +136,7 @@ SELECT insert_one('db','regex', '{"_id" : 121, "number" : "02191996"}'); { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex', '{"_id" : 122, "number" : "9୩୪୬୯6"}'); +SELECT insert_one('db','regex', '{"_id" : 122, "number" : "9୩୪୬୯678"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } @@ -155,17 +155,17 @@ SELECT insert_one('db','regex', '{"_id" : 131, "text" : "박정수"}'); { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex', '{"_id" : 132, "text" : "suárez"}'); +SELECT insert_one('db','regex', '{"_id" : 132, "text" : "Fernández"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT document from collection('db', 'regex') where document @@ '{"sku": {"$regex": true} }'; +SELECT document from collection('db', 'regex') where document @@ '{"b": {"$regex": true} }'; ERROR: invalid input syntax JSON for BSON: Code: '2', Message 'Invalid read of boolean in state IN_BSON_TYPE' -LINE 1: ... from collection('db', 'regex') where document @@ '{"sku": {... +LINE 1: ... from collection('db', 'regex') where document @@ '{"b": {"$... ^ -SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"sku": 1}, "name": "index_on_sku"}]}', true); +SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"b": 1}, "name": "index_on_sku"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } @@ -196,25 +196,25 @@ SELECT documentdb_distributed_test_helpers.drop_primary_key('db','regex'); (1 row) -SELECT document from collection('db', 'regex') where document @@ '{"sku": {"$regex": true} }'; +SELECT document from collection('db', 'regex') where document @@ '{"b": {"$regex": true} }'; ERROR: invalid input syntax JSON for BSON: Code: '2', Message 'Invalid read of boolean in state IN_BSON_TYPE' -LINE 1: ... from collection('db', 'regex') where document @@ '{"sku": {... +LINE 1: ... from collection('db', 'regex') where document @@ '{"b": {"$... ^ -- SELECT sku -SELECT count(*) sku from collection('db', 'regex') where document @@ '{"sku": {"$regex": "", "$options": ""} }'; +SELECT count(*) sku from collection('db', 'regex') where document @@ '{"b": {"$regex": "", "$options": ""} }'; sku --------------------------------------------------------------------- - 8 + 15 (1 row) -- 100 to 103 SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "\\bline\\b", "$options" : "" } }'; - document + document --------------------------------------------------------------------- - { "_id" : { "$numberInt" : "100" }, "sku" : "abc123", "description" : "Single line description." } - { "_id" : { "$numberInt" : "101" }, "sku" : "abc789", "description" : "single line\nSecond line" } - { "_id" : { "$numberInt" : "102" }, "sku" : "xyz456", "description" : "Many spaces before line" } - { "_id" : { "$numberInt" : "103" }, "sku" : "xyz789", "description" : "Multiple\nline description" } + { "_id" : { "$numberInt" : "100" }, "b" : "abc123", "description" : "this is single line " } + { "_id" : { "$numberInt" : "101" }, "b" : "abc789", "description" : "this is tow-line. single line\nSecond line" } + { "_id" : { "$numberInt" : "102" }, "b" : "xyz456", "description" : "there are some spaces. Many spaces before line" } + { "_id" : { "$numberInt" : "103" }, "b" : "xyz789", "description" : "this is Multiple\nline description" } (4 rows) -- No records. Will try to match \\y (as a char) in the document @@ -225,9 +225,9 @@ SELECT document from collection('db', 'regex') where document @@ '{ "description -- 109 Match \y as a char. For libbson \y is a special char. So to \y it needs to be escaped as \\y and for \\y, we need to provide as \\\\y SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "in\\\\ycline", "$options" : "" } }'; - document + document --------------------------------------------------------------------- - { "_id" : { "$numberInt" : "109" }, "sku" : "xyz810", "description" : "Multiple\n in\\ycline \bdescription" } + { "_id" : { "$numberInt" : "109" }, "b" : "xyz810", "description" : "Multiple\n in\\ycline \bdescription" } (1 row) -- 107 Match a where a's value was inserted as a Regular expression object. Here \b will not be used as a flag. This entire regular expression object (/a\bcde\b/) will be compared (as such) against the regular expression object that was inserted. This is like regex is compared with another regex. @@ -241,31 +241,31 @@ SELECT document from collection('db', 'regex') where document @@ '{"a" : { "$reg --SELECT document from collection('db', 'regex') where document @@ '{"a" : { "$regularExpression" : { "pattern": "a\\ycde\\y", "options" : ""} } }'; -- 100 and 101 SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "le.*\\bline\\b", "$options" : "" } }'; - document + document --------------------------------------------------------------------- - { "_id" : { "$numberInt" : "100" }, "sku" : "abc123", "description" : "Single line description." } - { "_id" : { "$numberInt" : "101" }, "sku" : "abc789", "description" : "single line\nSecond line" } + { "_id" : { "$numberInt" : "100" }, "b" : "abc123", "description" : "this is single line " } + { "_id" : { "$numberInt" : "101" }, "b" : "abc789", "description" : "this is tow-line. single line\nSecond line" } (2 rows) -- 105 Matching \b as a normal char inside the string. SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "in\bcline \bdescription", "$options" : "" } }'; - document + document --------------------------------------------------------------------- - { "_id" : { "$numberInt" : "105" }, "sku" : "xyz800", "description" : "Multiple\n in\bcline \bdescription" } + { "_id" : { "$numberInt" : "105" }, "b" : "xyz800", "description" : "this is Multiple\n in\bcline \bdescription" } (1 row) -- 100 SELECT document from collection('db', 'regex') where document @@ '{"description": { "$options": "i", "$regex": " line " } }'; - document + document --------------------------------------------------------------------- - { "_id" : { "$numberInt" : "100" }, "sku" : "abc123", "description" : "Single line description." } + { "_id" : { "$numberInt" : "100" }, "b" : "abc123", "description" : "this is single line " } (1 row) -- 100 SELECT document from collection('db', 'regex') where document @@ '{"description": {"$regex": " line ","$options": "i"}}'; - document + document --------------------------------------------------------------------- - { "_id" : { "$numberInt" : "100" }, "sku" : "abc123", "description" : "Single line description." } + { "_id" : { "$numberInt" : "100" }, "b" : "abc123", "description" : "this is single line " } (1 row) -- 106 108 @@ -278,9 +278,9 @@ SELECT document from collection('db', 'regex') where document @@ '{ "a" : { "$re -- 120 SELECT document from collection('db', 'regex') where document @@ '{ "number" : { "$regularExpression" : { "pattern" : "༣", "options" : "" } } } '; - document + document --------------------------------------------------------------------- - { "_id" : { "$numberInt" : "120" }, "number" : "༢༣༤༥" } + { "_id" : { "$numberInt" : "120" }, "number" : "୩༢༣༤༥" } (1 row) -- 121 122 if ascii digits are present @@ -288,7 +288,7 @@ SELECT document from collection('db', 'regex') where document @@ '{ "number" : { document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "121" }, "number" : "02191996" } - { "_id" : { "$numberInt" : "122" }, "number" : "9୩୪୬୯6" } + { "_id" : { "$numberInt" : "122" }, "number" : "9୩୪୬୯678" } (2 rows) -- 131 @@ -307,19 +307,19 @@ SELECT document from collection('db', 'regex') where document @@ '{ "text" : { " -- 130 131 132 SELECT document from collection('db', 'regex') where document @@ '{ "text" : { "$regularExpression" : { "pattern" : "^\\p{Xan}+$", "options" : "" } } } '; - document + document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "130" }, "text" : "kyle" } { "_id" : { "$numberInt" : "131" }, "text" : "박정수" } - { "_id" : { "$numberInt" : "132" }, "text" : "suárez" } + { "_id" : { "$numberInt" : "132" }, "text" : "Fernández" } (3 rows) -- 130 132 SELECT document from collection('db', 'regex') where document @@ '{ "text" : { "$regularExpression" : { "pattern" : "^\\p{Latin}", "options" : "" } } } '; - document + document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "130" }, "text" : "kyle" } - { "_id" : { "$numberInt" : "132" }, "text" : "suárez" } + { "_id" : { "$numberInt" : "132" }, "text" : "Fernández" } (2 rows) diff --git a/internal/pg_documentdb_distributed/src/test/regress/expected/regex_options_index.out b/internal/pg_documentdb_distributed/src/test/regress/expected/regex_options_index.out index dbbc5153..3c9f0e4f 100644 --- a/internal/pg_documentdb_distributed/src/test/regress/expected/regex_options_index.out +++ b/internal/pg_documentdb_distributed/src/test/regress/expected/regex_options_index.out @@ -30,55 +30,55 @@ BEGIN END IF; END; $$; -SELECT insert_one('db','regex_options', '{"a": "hregex New"}'); +SELECT insert_one('db','regex_options', '{"msg": "hpattern New"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "regeX New"}'); +SELECT insert_one('db','regex_options', '{"msg": "pattX New"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "regeX\nNew"}'); +SELECT insert_one('db','regex_options', '{"msg": "pattX\nNew"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "regex\nNew"}'); +SELECT insert_one('db','regex_options', '{"msg": "pattx\nNew"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "regex_New"}'); +SELECT insert_one('db','regex_options', '{"msg": "pattx_New"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "hello\nregex\nNewLineStart"}'); +SELECT insert_one('db','regex_options', '{"msg": "hello\npattx\nNewLineStart"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "hello\nregex NewWord"}'); +SELECT insert_one('db','regex_options', '{"msg": "hello\npattx NewWord"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "hello\nregeX NewWord"}'); +SELECT insert_one('db','regex_options', '{"msg": "hello\npattx NewWord"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "hello\nregex New\nWord"}'); +SELECT insert_one('db','regex_options', '{"msg": "hello\npattX New\nWord"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } @@ -100,107 +100,107 @@ SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'regex_options (1 row) -SELECT assert_count_regex_options(8, '{"a": {"$options": "ims", "$regex": "^regeX.New"}}'); +SELECT assert_count_regex_options(8, '{"msg": {"$options": "ims", "$regex": "^pattX.New"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -SELECT assert_count_regex_options(5, '{"a": {"$regex": "^regeX.New$", "$options": "mis"}}'); +SELECT assert_count_regex_options(5, '{"msg": {"$regex": "^pattX.New$", "$options": "mis"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -SELECT assert_count_regex_options(8, '{"a": {"$regex": "^regeX.New", "$options": "ims"}}'); +SELECT assert_count_regex_options(8, '{"msg": {"$regex": "^pattX.New", "$options": "ims"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- With comment and space in pattern and without extended match flag (x) -SELECT assert_count_regex_options(0, '{"a": {"$regex": "^regeX.N#COMMENT\n ew", "$options": "ims"}}'); +SELECT assert_count_regex_options(0, '{"msg": {"$regex": "^pattX.N#COMMENT\n ew", "$options": "ims"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- With comment and space in pattern and with extended match flag (x) -SELECT assert_count_regex_options(8, '{"a": {"$regex": "^regeX.N#COMMENT\n ew", "$options": "ixms"}}'); +SELECT assert_count_regex_options(8, '{"msg": {"$regex": "^pattX.N#COMMENT\n ew", "$options": "ixms"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -SELECT assert_count_regex_options(1, '{"a": {"$regex": "^regeX.New", "$options": ""}}'); +SELECT assert_count_regex_options(1, '{"msg": {"$regex": "^pattX.New", "$options": ""}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -SELECT assert_count_regex_options(2, '{"a": {"$regex": "^regeX.New", "$options": "i"}}'); +SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "i"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- . matches new line when s flag is set. -SELECT assert_count_regex_options(2, '{"a": {"$regex": "^regeX.New", "$options": "s"}}'); +SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "s"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- multiline match flag -SELECT assert_count_regex_options(2, '{"a": {"$regex": "^regeX.New", "$options": "m"}}'); +SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "m"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- . matches new line and case insensitive match -SELECT assert_count_regex_options(4, '{"a": {"$regex": "^regeX.New", "$options": "si"}}'); +SELECT assert_count_regex_options(4, '{"msg": {"$regex": "^pattX.New", "$options": "si"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -SELECT assert_count_regex_options(5, '{"a": {"$regex": "^regeX.New", "$options": "mi"}}'); +SELECT assert_count_regex_options(5, '{"msg": {"$regex": "^pattX.New", "$options": "mi"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -SELECT assert_count_regex_options(3, '{"a": {"$regex": "^regeX.New", "$options": "ms"}}'); +SELECT assert_count_regex_options(3, '{"msg": {"$regex": "^pattX.New", "$options": "ms"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- This will work as an implicit AND. TODO. To make the behavior same as from Mongo shell through GW : Mongo on Citus --- SELECT assert_count_regex_options(1,'{"a": {"$regex": "hregex.new", "$eq": "hregex New", "$options": "i"}}'); +-- SELECT assert_count_regex_options(1,'{"msg": {"$regex": "hpattern.new", "$eq": "hpattern New", "$options": "i"}}'); -- eq does not match ---SELECT assert_count_regex_options(0,'{"a": {"$regex": "hregex.new", "$eq": "hregexNew", "$options": "i"}}'); +--SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$eq": "hpatternNew", "$options": "i"}}'); -- Regex options does not make the document to match query spec. ---SELECT assert_count_regex_options(0,'{"a": {"$regex": "hregex.new", "$eq": "hregex New", "$options": ""}}'); +--SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$eq": "hpattern New", "$options": ""}}'); -- When there are duplicate keys, the last one of each will be considered. -SELECT assert_count_regex_options(1,'{"a": {"$regex": "hregex.new", "$options": "i", "$regex": "^word$", "$options": "mi"}}'); +SELECT assert_count_regex_options(1,'{"msg": {"$regex": "hpattern.new", "$options": "i", "$regex": "^word$", "$options": "mi"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- In continuation with the above tests: To ensure that the last regex options pair is really getting taken. -SELECT assert_count_regex_options(0,'{"a": {"$regex": "hregex.new", "$options": "i", "$regex": "^word$", "$options": "i"}}'); +SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$options": "i", "$regex": "^word$", "$options": "i"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- This will error out because $options needed a $regex. -SELECT document FROM collection('db','regex_options') WHERE document @@ '{"a": {"$options": "i"}}'; +SELECT document FROM collection('db','regex_options') WHERE document @@ '{"msg": {"$options": "i"}}'; psql:sql/regex_options_core.sql:79: ERROR: invalid input syntax JSON for BSON: Code: '2', Message 'Missing "$regex" after "$options"' -LINE 1: ...ollection('db','regex_options') WHERE document @@ '{"a": {"$... +LINE 1: ...ollection('db','regex_options') WHERE document @@ '{"msg": {... ^ ROLLBACK; SELECT drop_collection('db','regex_options'); diff --git a/internal/pg_documentdb_distributed/src/test/regress/expected/regex_options_runtime.out b/internal/pg_documentdb_distributed/src/test/regress/expected/regex_options_runtime.out index 644cbd36..a66c659b 100644 --- a/internal/pg_documentdb_distributed/src/test/regress/expected/regex_options_runtime.out +++ b/internal/pg_documentdb_distributed/src/test/regress/expected/regex_options_runtime.out @@ -27,55 +27,55 @@ BEGIN END IF; END; $$; -SELECT insert_one('db','regex_options', '{"a": "hregex New"}'); +SELECT insert_one('db','regex_options', '{"msg": "hpattern New"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "regeX New"}'); +SELECT insert_one('db','regex_options', '{"msg": "pattX New"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "regeX\nNew"}'); +SELECT insert_one('db','regex_options', '{"msg": "pattX\nNew"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "regex\nNew"}'); +SELECT insert_one('db','regex_options', '{"msg": "pattx\nNew"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "regex_New"}'); +SELECT insert_one('db','regex_options', '{"msg": "pattx_New"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "hello\nregex\nNewLineStart"}'); +SELECT insert_one('db','regex_options', '{"msg": "hello\npattx\nNewLineStart"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "hello\nregex NewWord"}'); +SELECT insert_one('db','regex_options', '{"msg": "hello\npattx NewWord"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "hello\nregeX NewWord"}'); +SELECT insert_one('db','regex_options', '{"msg": "hello\npattx NewWord"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -SELECT insert_one('db','regex_options', '{"a": "hello\nregex New\nWord"}'); +SELECT insert_one('db','regex_options', '{"msg": "hello\npattX New\nWord"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } @@ -97,107 +97,107 @@ SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'regex_options (1 row) -SELECT assert_count_regex_options(8, '{"a": {"$options": "ims", "$regex": "^regeX.New"}}'); +SELECT assert_count_regex_options(8, '{"msg": {"$options": "ims", "$regex": "^pattX.New"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -SELECT assert_count_regex_options(5, '{"a": {"$regex": "^regeX.New$", "$options": "mis"}}'); +SELECT assert_count_regex_options(5, '{"msg": {"$regex": "^pattX.New$", "$options": "mis"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -SELECT assert_count_regex_options(8, '{"a": {"$regex": "^regeX.New", "$options": "ims"}}'); +SELECT assert_count_regex_options(8, '{"msg": {"$regex": "^pattX.New", "$options": "ims"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- With comment and space in pattern and without extended match flag (x) -SELECT assert_count_regex_options(0, '{"a": {"$regex": "^regeX.N#COMMENT\n ew", "$options": "ims"}}'); +SELECT assert_count_regex_options(0, '{"msg": {"$regex": "^pattX.N#COMMENT\n ew", "$options": "ims"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- With comment and space in pattern and with extended match flag (x) -SELECT assert_count_regex_options(8, '{"a": {"$regex": "^regeX.N#COMMENT\n ew", "$options": "ixms"}}'); +SELECT assert_count_regex_options(8, '{"msg": {"$regex": "^pattX.N#COMMENT\n ew", "$options": "ixms"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -SELECT assert_count_regex_options(1, '{"a": {"$regex": "^regeX.New", "$options": ""}}'); +SELECT assert_count_regex_options(1, '{"msg": {"$regex": "^pattX.New", "$options": ""}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -SELECT assert_count_regex_options(2, '{"a": {"$regex": "^regeX.New", "$options": "i"}}'); +SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "i"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- . matches new line when s flag is set. -SELECT assert_count_regex_options(2, '{"a": {"$regex": "^regeX.New", "$options": "s"}}'); +SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "s"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- multiline match flag -SELECT assert_count_regex_options(2, '{"a": {"$regex": "^regeX.New", "$options": "m"}}'); +SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "m"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- . matches new line and case insensitive match -SELECT assert_count_regex_options(4, '{"a": {"$regex": "^regeX.New", "$options": "si"}}'); +SELECT assert_count_regex_options(4, '{"msg": {"$regex": "^pattX.New", "$options": "si"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -SELECT assert_count_regex_options(5, '{"a": {"$regex": "^regeX.New", "$options": "mi"}}'); +SELECT assert_count_regex_options(5, '{"msg": {"$regex": "^pattX.New", "$options": "mi"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -SELECT assert_count_regex_options(3, '{"a": {"$regex": "^regeX.New", "$options": "ms"}}'); +SELECT assert_count_regex_options(3, '{"msg": {"$regex": "^pattX.New", "$options": "ms"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- This will work as an implicit AND. TODO. To make the behavior same as from Mongo shell through GW : Mongo on Citus --- SELECT assert_count_regex_options(1,'{"a": {"$regex": "hregex.new", "$eq": "hregex New", "$options": "i"}}'); +-- SELECT assert_count_regex_options(1,'{"msg": {"$regex": "hpattern.new", "$eq": "hpattern New", "$options": "i"}}'); -- eq does not match ---SELECT assert_count_regex_options(0,'{"a": {"$regex": "hregex.new", "$eq": "hregexNew", "$options": "i"}}'); +--SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$eq": "hpatternNew", "$options": "i"}}'); -- Regex options does not make the document to match query spec. ---SELECT assert_count_regex_options(0,'{"a": {"$regex": "hregex.new", "$eq": "hregex New", "$options": ""}}'); +--SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$eq": "hpattern New", "$options": ""}}'); -- When there are duplicate keys, the last one of each will be considered. -SELECT assert_count_regex_options(1,'{"a": {"$regex": "hregex.new", "$options": "i", "$regex": "^word$", "$options": "mi"}}'); +SELECT assert_count_regex_options(1,'{"msg": {"$regex": "hpattern.new", "$options": "i", "$regex": "^word$", "$options": "mi"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- In continuation with the above tests: To ensure that the last regex options pair is really getting taken. -SELECT assert_count_regex_options(0,'{"a": {"$regex": "hregex.new", "$options": "i", "$regex": "^word$", "$options": "i"}}'); +SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$options": "i", "$regex": "^word$", "$options": "i"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- This will error out because $options needed a $regex. -SELECT document FROM collection('db','regex_options') WHERE document @@ '{"a": {"$options": "i"}}'; +SELECT document FROM collection('db','regex_options') WHERE document @@ '{"msg": {"$options": "i"}}'; psql:sql/regex_options_core.sql:79: ERROR: invalid input syntax JSON for BSON: Code: '2', Message 'Missing "$regex" after "$options"' -LINE 1: ...ollection('db','regex_options') WHERE document @@ '{"a": {"$... +LINE 1: ...ollection('db','regex_options') WHERE document @@ '{"msg": {... ^ ROLLBACK; SELECT drop_collection('db','regex_options'); diff --git a/internal/pg_documentdb_distributed/src/test/regress/sql/regex.sql b/internal/pg_documentdb_distributed/src/test/regress/sql/regex.sql index 607bbdaf..7d97cfc4 100644 --- a/internal/pg_documentdb_distributed/src/test/regress/sql/regex.sql +++ b/internal/pg_documentdb_distributed/src/test/regress/sql/regex.sql @@ -7,17 +7,17 @@ SET documentdb.next_collection_index_id TO 3350; SELECT create_collection('db','regex'); -SELECT insert_one('db','regex', '{"_id" : 99, "sku": "abc123"}'); -SELECT insert_one('db','regex', '{"_id" : 100, "sku" : "abc123", "description" : "Single line description." }'); -SELECT insert_one('db','regex', '{"_id" : 101, "sku" : "abc789", "description" : "single line\nSecond line" }'); -SELECT insert_one('db','regex', '{"_id" : 102, "sku" : "xyz456", "description" : "Many spaces before line" }'); -SELECT insert_one('db','regex', '{"_id" : 103, "sku" : "xyz789", "description" : "Multiple\nline description" }'); -SELECT insert_one('db','regex', '{"_id" : 104, "sku" : "xyz790", "description" : "Multiple\n incline description" }'); -SELECT insert_one('db','regex', '{"_id" : 105, "sku" : "xyz800", "description" : "Multiple\n in\bcline \bdescription" }'); +SELECT insert_one('db','regex', '{"_id" : 99, "b": "abc123"}'); +SELECT insert_one('db','regex', '{"_id" : 100, "b" : "abc123", "description" : "this is single line " }'); +SELECT insert_one('db','regex', '{"_id" : 101, "b" : "abc789", "description" : "this is tow-line. single line\nSecond line" }'); +SELECT insert_one('db','regex', '{"_id" : 102, "b" : "xyz456", "description" : "there are some spaces. Many spaces before line" }'); +SELECT insert_one('db','regex', '{"_id" : 103, "b" : "xyz789", "description" : "this is Multiple\nline description" }'); +SELECT insert_one('db','regex', '{"_id" : 104, "b" : "xyz790", "description" : "this is Multiple\n incline description" }'); +SELECT insert_one('db','regex', '{"_id" : 105, "b" : "xyz800", "description" : "this is Multiple\n in\bcline \bdescription" }'); SELECT insert_one('db','regex', '{"_id" : 106, "a" : "hello a\bcde world" }'); SELECT insert_one('db','regex', '{"_id" : 107, "a" : {"$regularExpression" : {"pattern" : "a\bcde\b", "options" : ""}}}'); SELECT insert_one('db','regex', '{"_id" : 108, "a" : {"$regularExpression" : {"pattern" : "hello", "options" : ""}} }'); -SELECT insert_one('db','regex', '{"_id" : 109, "sku" : "xyz810", "description" : "Multiple\n in\\ycline \bdescription"}'); +SELECT insert_one('db','regex', '{"_id" : 109, "b" : "xyz810", "description" : "Multiple\n in\\ycline \bdescription"}'); SELECT insert_one('db','regex', '{"_id" : 110, "a" : {"$regularExpression" : {"pattern" : "a\\ycde\\y", "options" : ""}}}'); SELECT insert_one('db','regex', '{"_id" : 111, "a" : "a value", "b": "b value"}'); SELECT insert_one('db','regex', '{"_id" : 112, "a" : "v2", "b": "bv2"}'); @@ -28,17 +28,17 @@ SELECT insert_one('db','regex', '{"_id" : 116, "a" : "v6", "b": "bv6"}'); SELECT insert_one('db','regex', '{"_id" : 117, "a" : "a value7", "b": "b value7"}'); -- Some unicodes & mixed numerical -SELECT insert_one('db','regex', '{"_id" : 120, "number" : "༢༣༤༥"}'); +SELECT insert_one('db','regex', '{"_id" : 120, "number" : "୩༢༣༤༥"}'); SELECT insert_one('db','regex', '{"_id" : 121, "number" : "02191996"}'); -SELECT insert_one('db','regex', '{"_id" : 122, "number" : "9୩୪୬୯6"}'); +SELECT insert_one('db','regex', '{"_id" : 122, "number" : "9୩୪୬୯678"}'); -- Some unicode text SELECT insert_one('db','regex', '{"_id" : 130, "text" : "kyle"}'); SELECT insert_one('db','regex', '{"_id" : 131, "text" : "박정수"}'); -SELECT insert_one('db','regex', '{"_id" : 132, "text" : "suárez"}'); +SELECT insert_one('db','regex', '{"_id" : 132, "text" : "Fernández"}'); -SELECT document from collection('db', 'regex') where document @@ '{"sku": {"$regex": true} }'; +SELECT document from collection('db', 'regex') where document @@ '{"b": {"$regex": true} }'; -SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"sku": 1}, "name": "index_on_sku"}]}', true); +SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"b": 1}, "name": "index_on_sku"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"x": 1}, "name": "index_on_x" }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"F1": 1}, "name": "index_on_F1" }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"a": 1, "b": 1}, "name": "Compound_index_on_a_and_b" }]}', true); @@ -46,10 +46,10 @@ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIn -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','regex'); -SELECT document from collection('db', 'regex') where document @@ '{"sku": {"$regex": true} }'; +SELECT document from collection('db', 'regex') where document @@ '{"b": {"$regex": true} }'; -- SELECT sku -SELECT count(*) sku from collection('db', 'regex') where document @@ '{"sku": {"$regex": "", "$options": ""} }'; +SELECT count(*) sku from collection('db', 'regex') where document @@ '{"b": {"$regex": "", "$options": ""} }'; -- 100 to 103 SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "\\bline\\b", "$options" : "" } }'; diff --git a/internal/pg_documentdb_distributed/src/test/regress/sql/regex_options_core.sql b/internal/pg_documentdb_distributed/src/test/regress/sql/regex_options_core.sql index 2ba670be..655d0ea3 100644 --- a/internal/pg_documentdb_distributed/src/test/regress/sql/regex_options_core.sql +++ b/internal/pg_documentdb_distributed/src/test/regress/sql/regex_options_core.sql @@ -13,15 +13,15 @@ BEGIN END; $$; -SELECT insert_one('db','regex_options', '{"a": "hregex New"}'); -SELECT insert_one('db','regex_options', '{"a": "regeX New"}'); -SELECT insert_one('db','regex_options', '{"a": "regeX\nNew"}'); -SELECT insert_one('db','regex_options', '{"a": "regex\nNew"}'); -SELECT insert_one('db','regex_options', '{"a": "regex_New"}'); -SELECT insert_one('db','regex_options', '{"a": "hello\nregex\nNewLineStart"}'); -SELECT insert_one('db','regex_options', '{"a": "hello\nregex NewWord"}'); -SELECT insert_one('db','regex_options', '{"a": "hello\nregeX NewWord"}'); -SELECT insert_one('db','regex_options', '{"a": "hello\nregex New\nWord"}'); +SELECT insert_one('db','regex_options', '{"msg": "hpattern New"}'); +SELECT insert_one('db','regex_options', '{"msg": "pattX New"}'); +SELECT insert_one('db','regex_options', '{"msg": "pattX\nNew"}'); +SELECT insert_one('db','regex_options', '{"msg": "pattx\nNew"}'); +SELECT insert_one('db','regex_options', '{"msg": "pattx_New"}'); +SELECT insert_one('db','regex_options', '{"msg": "hello\npattx\nNewLineStart"}'); +SELECT insert_one('db','regex_options', '{"msg": "hello\npattx NewWord"}'); +SELECT insert_one('db','regex_options', '{"msg": "hello\npattx NewWord"}'); +SELECT insert_one('db','regex_options', '{"msg": "hello\npattX New\nWord"}'); do $$ DECLARE @@ -36,44 +36,44 @@ $$; -- DROP PRIMARY KEY SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'regex_options'); -SELECT assert_count_regex_options(8, '{"a": {"$options": "ims", "$regex": "^regeX.New"}}'); -SELECT assert_count_regex_options(5, '{"a": {"$regex": "^regeX.New$", "$options": "mis"}}'); -SELECT assert_count_regex_options(8, '{"a": {"$regex": "^regeX.New", "$options": "ims"}}'); +SELECT assert_count_regex_options(8, '{"msg": {"$options": "ims", "$regex": "^pattX.New"}}'); +SELECT assert_count_regex_options(5, '{"msg": {"$regex": "^pattX.New$", "$options": "mis"}}'); +SELECT assert_count_regex_options(8, '{"msg": {"$regex": "^pattX.New", "$options": "ims"}}'); -- With comment and space in pattern and without extended match flag (x) -SELECT assert_count_regex_options(0, '{"a": {"$regex": "^regeX.N#COMMENT\n ew", "$options": "ims"}}'); +SELECT assert_count_regex_options(0, '{"msg": {"$regex": "^pattX.N#COMMENT\n ew", "$options": "ims"}}'); -- With comment and space in pattern and with extended match flag (x) -SELECT assert_count_regex_options(8, '{"a": {"$regex": "^regeX.N#COMMENT\n ew", "$options": "ixms"}}'); +SELECT assert_count_regex_options(8, '{"msg": {"$regex": "^pattX.N#COMMENT\n ew", "$options": "ixms"}}'); -SELECT assert_count_regex_options(1, '{"a": {"$regex": "^regeX.New", "$options": ""}}'); -SELECT assert_count_regex_options(2, '{"a": {"$regex": "^regeX.New", "$options": "i"}}'); +SELECT assert_count_regex_options(1, '{"msg": {"$regex": "^pattX.New", "$options": ""}}'); +SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "i"}}'); -- . matches new line when s flag is set. -SELECT assert_count_regex_options(2, '{"a": {"$regex": "^regeX.New", "$options": "s"}}'); +SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "s"}}'); -- multiline match flag -SELECT assert_count_regex_options(2, '{"a": {"$regex": "^regeX.New", "$options": "m"}}'); +SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "m"}}'); -- . matches new line and case insensitive match -SELECT assert_count_regex_options(4, '{"a": {"$regex": "^regeX.New", "$options": "si"}}'); -SELECT assert_count_regex_options(5, '{"a": {"$regex": "^regeX.New", "$options": "mi"}}'); -SELECT assert_count_regex_options(3, '{"a": {"$regex": "^regeX.New", "$options": "ms"}}'); +SELECT assert_count_regex_options(4, '{"msg": {"$regex": "^pattX.New", "$options": "si"}}'); +SELECT assert_count_regex_options(5, '{"msg": {"$regex": "^pattX.New", "$options": "mi"}}'); +SELECT assert_count_regex_options(3, '{"msg": {"$regex": "^pattX.New", "$options": "ms"}}'); -- This will work as an implicit AND. TODO. To make the behavior same as from Mongo shell through GW : Mongo on Citus --- SELECT assert_count_regex_options(1,'{"a": {"$regex": "hregex.new", "$eq": "hregex New", "$options": "i"}}'); +-- SELECT assert_count_regex_options(1,'{"msg": {"$regex": "hpattern.new", "$eq": "hpattern New", "$options": "i"}}'); -- eq does not match ---SELECT assert_count_regex_options(0,'{"a": {"$regex": "hregex.new", "$eq": "hregexNew", "$options": "i"}}'); +--SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$eq": "hpatternNew", "$options": "i"}}'); -- Regex options does not make the document to match query spec. ---SELECT assert_count_regex_options(0,'{"a": {"$regex": "hregex.new", "$eq": "hregex New", "$options": ""}}'); +--SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$eq": "hpattern New", "$options": ""}}'); -- When there are duplicate keys, the last one of each will be considered. -SELECT assert_count_regex_options(1,'{"a": {"$regex": "hregex.new", "$options": "i", "$regex": "^word$", "$options": "mi"}}'); +SELECT assert_count_regex_options(1,'{"msg": {"$regex": "hpattern.new", "$options": "i", "$regex": "^word$", "$options": "mi"}}'); -- In continuation with the above tests: To ensure that the last regex options pair is really getting taken. -SELECT assert_count_regex_options(0,'{"a": {"$regex": "hregex.new", "$options": "i", "$regex": "^word$", "$options": "i"}}'); +SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$options": "i", "$regex": "^word$", "$options": "i"}}'); -- This will error out because $options needed a $regex. -SELECT document FROM collection('db','regex_options') WHERE document @@ '{"a": {"$options": "i"}}'; +SELECT document FROM collection('db','regex_options') WHERE document @@ '{"msg": {"$options": "i"}}';