Skip to content

Commit a2f116a

Browse files
NikitOS94NikitOS94
authored andcommitted
New tests for parse_mquery
1 parent 7757b7a commit a2f116a

File tree

2 files changed

+368
-0
lines changed

2 files changed

+368
-0
lines changed

expected/jsquery.out

Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,4 +2999,307 @@ select v from test_jsquery where v @@ parse_mquery('{ { $text: { $search: "Flew"
29992999
---
30003000
(0 rows)
30013001

3002+
select '{ "a" : "ssl" }'::jsonb @@ parse_mquery('{ a: { $in: [ "ssl","security"] } }');
3003+
?column?
3004+
----------
3005+
t
3006+
(1 row)
3007+
3008+
select '{ "a" : 1 }'::jsonb @@ parse_mquery('{ a: { $in: [ "ssl","security"] } }');
3009+
?column?
3010+
----------
3011+
f
3012+
(1 row)
3013+
3014+
select '{ "a" : "ssl" }'::jsonb @@ parse_mquery('{ a: { $nin: [ "ssl","security"] } }');
3015+
?column?
3016+
----------
3017+
f
3018+
(1 row)
3019+
3020+
select '{ "a" : "sslqwerty" }'::jsonb @@ parse_mquery('{ a: { $nin: [ "ssl","security"] } }');
3021+
?column?
3022+
----------
3023+
t
3024+
(1 row)
3025+
3026+
select '{ "a" : [ "ssl","security"] }'::jsonb @@ parse_mquery('{ a: { $size: 2 } }');
3027+
?column?
3028+
----------
3029+
t
3030+
(1 row)
3031+
3032+
select '{ "a" : [ "ssl","security"] }'::jsonb @@ parse_mquery('{ a: { $size: 1 } }');
3033+
?column?
3034+
----------
3035+
f
3036+
(1 row)
3037+
3038+
select '{ "a" : [ "ssl","security", "pattern"] }'::jsonb @@ parse_mquery('{ a: { $all: [ "ssl","security"] } }');
3039+
?column?
3040+
----------
3041+
t
3042+
(1 row)
3043+
3044+
select '{ "a" : [ "ssl","pattern"] }'::jsonb @@ parse_mquery('{ a: { $all: [ "ssl","security"] } }');
3045+
?column?
3046+
----------
3047+
f
3048+
(1 row)
3049+
3050+
select '{ "a" : [ "ssl","security"] }'::jsonb @@ parse_mquery('{ a: { $all: [ "ssl","security"] } }');
3051+
?column?
3052+
----------
3053+
t
3054+
(1 row)
3055+
3056+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ a : { $exists : false } }');
3057+
?column?
3058+
----------
3059+
f
3060+
(1 row)
3061+
3062+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ a : { $exists : true } }');
3063+
?column?
3064+
----------
3065+
t
3066+
(1 row)
3067+
3068+
select '{ "b" : 2 }'::jsonb @@ parse_mquery('{ a : { $exists : false } }');
3069+
?column?
3070+
----------
3071+
t
3072+
(1 row)
3073+
3074+
select '{ "b" : 2 }'::jsonb @@ parse_mquery('{ a : { $exists : true } }');
3075+
?column?
3076+
----------
3077+
f
3078+
(1 row)
3079+
3080+
select '{ "b" : 2 }'::jsonb @@ parse_mquery('{ b: { $type: "int" } }');
3081+
?column?
3082+
----------
3083+
t
3084+
(1 row)
3085+
3086+
select '{ "b" : "qwerttyu" }'::jsonb @@ parse_mquery('{ b: { $type: "int" } }');
3087+
?column?
3088+
----------
3089+
f
3090+
(1 row)
3091+
3092+
select '{ "b" : 2 }'::jsonb @@ parse_mquery('{ b: { $type: "long" } }');
3093+
?column?
3094+
----------
3095+
t
3096+
(1 row)
3097+
3098+
select '{ "b" : "qwerttyu" }'::jsonb @@ parse_mquery('{ b: { $type: "long" } }');
3099+
?column?
3100+
----------
3101+
f
3102+
(1 row)
3103+
3104+
select '{ "b" : true }'::jsonb @@ parse_mquery('{ b: { $type: "bool" } }');
3105+
?column?
3106+
----------
3107+
t
3108+
(1 row)
3109+
3110+
select '{ "b" : "fklgjlksdfgsldflsgjslkrjekfjkl" }'::jsonb @@ parse_mquery('{ b: { $type: "bool" } }');
3111+
?column?
3112+
----------
3113+
f
3114+
(1 row)
3115+
3116+
select '{ "b" : "fklgjlksdfgsldflsgjslkrjekfjkl" }'::jsonb @@ parse_mquery('{ b: { $type: "array" } }');
3117+
?column?
3118+
----------
3119+
f
3120+
(1 row)
3121+
3122+
select '{ "b" : [1, 4] }'::jsonb @@ parse_mquery('{ b: { $type: "array" } }');
3123+
?column?
3124+
----------
3125+
t
3126+
(1 row)
3127+
3128+
select '{ "b" : "fklgjlksdfgsldflsgjslkrjekfjkl" }'::jsonb @@ parse_mquery('{ b: { $type: "string" } }');
3129+
?column?
3130+
----------
3131+
t
3132+
(1 row)
3133+
3134+
select '{ "b" : [1, 4] }'::jsonb @@ parse_mquery('{ b: { $type: "string" } }');
3135+
?column?
3136+
----------
3137+
f
3138+
(1 row)
3139+
3140+
select '{ "b" : 2.23432 }'::jsonb @@ parse_mquery('{ b: { $type: "double" } }');
3141+
?column?
3142+
----------
3143+
t
3144+
(1 row)
3145+
3146+
select '{ "b" : 2 }'::jsonb @@ parse_mquery('{ b: { $type: "double" } }');
3147+
?column?
3148+
----------
3149+
t
3150+
(1 row)
3151+
3152+
select '{ "b" : 2 }'::jsonb @@ parse_mquery('{ b: { $type: "decimal" } }');
3153+
?column?
3154+
----------
3155+
t
3156+
(1 row)
3157+
3158+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "maxKey" } }');
3159+
ERROR: Jsquery is not supported MongoDB "maxKey" value type
3160+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "binData" } }');
3161+
ERROR: Jsquery is not supported MongoDB "binData" value type
3162+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "objectId" } }');
3163+
ERROR: Jsquery is not supported MongoDB "objectId" value type
3164+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "javascript" } }');
3165+
ERROR: Jsquery is not supported MongoDB "javascript" value type
3166+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "symbol" } }');
3167+
ERROR: Jsquery is not supported MongoDB "symbol" value type
3168+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "javascriptWithScope" } }');
3169+
ERROR: Jsquery is not supported MongoDB "javascriptWithScope" value type
3170+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "timestamp" } }');
3171+
ERROR: Jsquery is not supported MongoDB "timestamp" value type
3172+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "minKey" } }');
3173+
ERROR: Jsquery is not supported MongoDB "minKey" value type
3174+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "regex" } }');
3175+
ERROR: Jsquery is not supported MongoDB "regex" value type
3176+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "null" } }');
3177+
ERROR: Jsquery is not supported MongoDB "null" value type
3178+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "date" } }');
3179+
ERROR: Jsquery is not supported MongoDB "date" value type
3180+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "undefined" } }');
3181+
ERROR: Jsquery is not supported MongoDB "undefined" value type
3182+
/* Or operator */
3183+
select '{ "quantity" : 2, "price" : 10 }'::jsonb @@ parse_mquery('{ $or: [ { quantity: { $lt: 20 } }, { price: 10 } ] }');
3184+
?column?
3185+
----------
3186+
t
3187+
(1 row)
3188+
3189+
select '{ "quantity" : 200, "price" : 10 }'::jsonb @@ parse_mquery('{ $or: [ { quantity: { $lt: 20 } }, { price: 10 } ] }');
3190+
?column?
3191+
----------
3192+
t
3193+
(1 row)
3194+
3195+
select '{ "quantity" : 200, "price" : 10 }'::jsonb @@ parse_mquery('{ $or: [ { quantity: { $lt: 20 } }, { price: 100 } ] }');
3196+
?column?
3197+
----------
3198+
f
3199+
(1 row)
3200+
3201+
/* Nor operator */
3202+
select '{ "quantity" : 2, "price" : 10 }'::jsonb @@ parse_mquery('{ $nor: [ { quantity: { $lt: 20 } }, { price: 10 } ] }');
3203+
?column?
3204+
----------
3205+
f
3206+
(1 row)
3207+
3208+
select '{ "quantity" : 200, "price" : 10 }'::jsonb @@ parse_mquery('{ $nor: [ { quantity: { $lt: 20 } }, { price: 10 } ] }');
3209+
?column?
3210+
----------
3211+
t
3212+
(1 row)
3213+
3214+
select '{ "quantity" : 200, "price" : 10 }'::jsonb @@ parse_mquery('{ $nor: [ { quantity: { $lt: 20 } }, { price: 100 } ] }');
3215+
?column?
3216+
----------
3217+
t
3218+
(1 row)
3219+
3220+
/* And operator */
3221+
select '{ "quantity" : 200, "price" : 10 }'::jsonb @@ parse_mquery('{ $and: [ { quantity: { $lt: 20 } }, { price: 100 } ] }');
3222+
?column?
3223+
----------
3224+
f
3225+
(1 row)
3226+
3227+
select '{ "quantity" : 5, "price" : 100 }'::jsonb @@ parse_mquery('{ $and: [ { quantity: { $lt: 20 } }, { price: 100 } ] }');
3228+
?column?
3229+
----------
3230+
t
3231+
(1 row)
3232+
3233+
/* Not operator */
3234+
select '{ "quantity" : 5, "price" : 100 }'::jsonb @@ parse_mquery('{ price: { $not: { $gt: 1.99 } } }');
3235+
?column?
3236+
----------
3237+
f
3238+
(1 row)
3239+
3240+
select '{ "quantity" : 5, "price" : 1 }'::jsonb @@ parse_mquery('{ price: { $not: { $gt: 1.99 } } }');
3241+
?column?
3242+
----------
3243+
t
3244+
(1 row)
3245+
3246+
/* Mod operator */
3247+
select '{ "quantity" : 2, "price" : 10 }'::jsonb @@ parse_mquery('{ qty: { $mod: [ 4, 0 ] } } ');
3248+
ERROR: MongoDB module operator is not supported by jsquery
3249+
select '{"a": 5}'::jsonb @@ parse_mquery('{ a: { $eq: 5 } }');
3250+
?column?
3251+
----------
3252+
t
3253+
(1 row)
3254+
3255+
select '{"a": 5}'::jsonb @@ parse_mquery('{ a: { $eq: 6 } }');
3256+
?column?
3257+
----------
3258+
f
3259+
(1 row)
3260+
3261+
select '{ "quantity" : "qw", "price" : 10 }'::jsonb @@ parse_mquery('{ { $where: "qw"} }');
3262+
ERROR: MongoDB where clause is not supported by jsquery
3263+
select '{ "quantity" : "qw", "price" : 10 }'::jsonb @@ parse_mquery('{ { $text: { $search: "qsddjkhjw" } } }');
3264+
?column?
3265+
----------
3266+
f
3267+
(1 row)
3268+
3269+
select '{ "quantity" : "qw", "price" : 10 }'::jsonb @@ parse_mquery('{ { $text: { $search: "qw" } } }');
3270+
?column?
3271+
----------
3272+
t
3273+
(1 row)
3274+
3275+
select '{"a": { "qwerty" : 5} }'::jsonb @@ parse_mquery('{ "a.qwerty" : { $eq: 6 } }');
3276+
?column?
3277+
----------
3278+
f
3279+
(1 row)
3280+
3281+
select '{"a": { "qwerty" : { "asdfgh" : { "fgfhg" : 5 } } } }'::jsonb @@ parse_mquery('{ "a.qwerty.asdfgh.fgfhg" : { $eq: 5 } }');
3282+
?column?
3283+
----------
3284+
t
3285+
(1 row)
3286+
3287+
select '{ "_id" : 3, "results" : [ { "product" : "abc", "score" : 7 }, { "product" : "abc", "score" : 8 } ] }' @@ parse_mquery('{ results: { $elemMatch: { product: "abc" } } }');
3288+
?column?
3289+
----------
3290+
t
3291+
(1 row)
3292+
3293+
select '{ "_id" : 3, "results" : [ 81, 84, 83] }' @@ parse_mquery('{ results: { $elemMatch: { $gte: 80, $lt: 85 } } }');
3294+
?column?
3295+
----------
3296+
t
3297+
(1 row)
3298+
3299+
select '{ "_id" : 3, "results" : [ 81, 86, 83] }' @@ parse_mquery('{ results: { $elemMatch: { $gte: 80, $lt: 85 } } }');
3300+
?column?
3301+
----------
3302+
f
3303+
(1 row)
3304+
30023305
RESET enable_seqscan;

sql/jsquery.sql

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,4 +563,69 @@ select v from test_jsquery where v @@ parse_mquery('{ array : { $all: [2,3] } }'
563563

564564
select v from test_jsquery where v @@ parse_mquery('{ { $text: { $search: "Flew" } } }');
565565

566+
select '{ "a" : "ssl" }'::jsonb @@ parse_mquery('{ a: { $in: [ "ssl","security"] } }');
567+
select '{ "a" : 1 }'::jsonb @@ parse_mquery('{ a: { $in: [ "ssl","security"] } }');
568+
select '{ "a" : "ssl" }'::jsonb @@ parse_mquery('{ a: { $nin: [ "ssl","security"] } }');
569+
select '{ "a" : "sslqwerty" }'::jsonb @@ parse_mquery('{ a: { $nin: [ "ssl","security"] } }');
570+
select '{ "a" : [ "ssl","security"] }'::jsonb @@ parse_mquery('{ a: { $size: 2 } }');
571+
select '{ "a" : [ "ssl","security"] }'::jsonb @@ parse_mquery('{ a: { $size: 1 } }');
572+
select '{ "a" : [ "ssl","security", "pattern"] }'::jsonb @@ parse_mquery('{ a: { $all: [ "ssl","security"] } }');
573+
select '{ "a" : [ "ssl","pattern"] }'::jsonb @@ parse_mquery('{ a: { $all: [ "ssl","security"] } }');
574+
select '{ "a" : [ "ssl","security"] }'::jsonb @@ parse_mquery('{ a: { $all: [ "ssl","security"] } }');
575+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ a : { $exists : false } }');
576+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ a : { $exists : true } }');
577+
select '{ "b" : 2 }'::jsonb @@ parse_mquery('{ a : { $exists : false } }');
578+
select '{ "b" : 2 }'::jsonb @@ parse_mquery('{ a : { $exists : true } }');
579+
select '{ "b" : 2 }'::jsonb @@ parse_mquery('{ b: { $type: "int" } }');
580+
select '{ "b" : "qwerttyu" }'::jsonb @@ parse_mquery('{ b: { $type: "int" } }');
581+
select '{ "b" : 2 }'::jsonb @@ parse_mquery('{ b: { $type: "long" } }');
582+
select '{ "b" : "qwerttyu" }'::jsonb @@ parse_mquery('{ b: { $type: "long" } }');
583+
select '{ "b" : true }'::jsonb @@ parse_mquery('{ b: { $type: "bool" } }');
584+
select '{ "b" : "fklgjlksdfgsldflsgjslkrjekfjkl" }'::jsonb @@ parse_mquery('{ b: { $type: "bool" } }');
585+
select '{ "b" : "fklgjlksdfgsldflsgjslkrjekfjkl" }'::jsonb @@ parse_mquery('{ b: { $type: "array" } }');
586+
select '{ "b" : [1, 4] }'::jsonb @@ parse_mquery('{ b: { $type: "array" } }');
587+
select '{ "b" : "fklgjlksdfgsldflsgjslkrjekfjkl" }'::jsonb @@ parse_mquery('{ b: { $type: "string" } }');
588+
select '{ "b" : [1, 4] }'::jsonb @@ parse_mquery('{ b: { $type: "string" } }');
589+
select '{ "b" : 2.23432 }'::jsonb @@ parse_mquery('{ b: { $type: "double" } }');
590+
select '{ "b" : 2 }'::jsonb @@ parse_mquery('{ b: { $type: "double" } }');
591+
select '{ "b" : 2 }'::jsonb @@ parse_mquery('{ b: { $type: "decimal" } }');
592+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "maxKey" } }');
593+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "binData" } }');
594+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "objectId" } }');
595+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "javascript" } }');
596+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "symbol" } }');
597+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "javascriptWithScope" } }');
598+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "timestamp" } }');
599+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "minKey" } }');
600+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "regex" } }');
601+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "null" } }');
602+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "date" } }');
603+
select '{ "a" : 2 }'::jsonb @@ parse_mquery('{ y: { $type: "undefined" } }');
604+
/* Or operator */
605+
select '{ "quantity" : 2, "price" : 10 }'::jsonb @@ parse_mquery('{ $or: [ { quantity: { $lt: 20 } }, { price: 10 } ] }');
606+
select '{ "quantity" : 200, "price" : 10 }'::jsonb @@ parse_mquery('{ $or: [ { quantity: { $lt: 20 } }, { price: 10 } ] }');
607+
select '{ "quantity" : 200, "price" : 10 }'::jsonb @@ parse_mquery('{ $or: [ { quantity: { $lt: 20 } }, { price: 100 } ] }');
608+
/* Nor operator */
609+
select '{ "quantity" : 2, "price" : 10 }'::jsonb @@ parse_mquery('{ $nor: [ { quantity: { $lt: 20 } }, { price: 10 } ] }');
610+
select '{ "quantity" : 200, "price" : 10 }'::jsonb @@ parse_mquery('{ $nor: [ { quantity: { $lt: 20 } }, { price: 10 } ] }');
611+
select '{ "quantity" : 200, "price" : 10 }'::jsonb @@ parse_mquery('{ $nor: [ { quantity: { $lt: 20 } }, { price: 100 } ] }');
612+
/* And operator */
613+
select '{ "quantity" : 200, "price" : 10 }'::jsonb @@ parse_mquery('{ $and: [ { quantity: { $lt: 20 } }, { price: 100 } ] }');
614+
select '{ "quantity" : 5, "price" : 100 }'::jsonb @@ parse_mquery('{ $and: [ { quantity: { $lt: 20 } }, { price: 100 } ] }');
615+
/* Not operator */
616+
select '{ "quantity" : 5, "price" : 100 }'::jsonb @@ parse_mquery('{ price: { $not: { $gt: 1.99 } } }');
617+
select '{ "quantity" : 5, "price" : 1 }'::jsonb @@ parse_mquery('{ price: { $not: { $gt: 1.99 } } }');
618+
/* Mod operator */
619+
select '{ "quantity" : 2, "price" : 10 }'::jsonb @@ parse_mquery('{ qty: { $mod: [ 4, 0 ] } } ');
620+
select '{"a": 5}'::jsonb @@ parse_mquery('{ a: { $eq: 5 } }');
621+
select '{"a": 5}'::jsonb @@ parse_mquery('{ a: { $eq: 6 } }');
622+
select '{ "quantity" : "qw", "price" : 10 }'::jsonb @@ parse_mquery('{ { $where: "qw"} }');
623+
select '{ "quantity" : "qw", "price" : 10 }'::jsonb @@ parse_mquery('{ { $text: { $search: "qsddjkhjw" } } }');
624+
select '{ "quantity" : "qw", "price" : 10 }'::jsonb @@ parse_mquery('{ { $text: { $search: "qw" } } }');
625+
select '{"a": { "qwerty" : 5} }'::jsonb @@ parse_mquery('{ "a.qwerty" : { $eq: 6 } }');
626+
select '{"a": { "qwerty" : { "asdfgh" : { "fgfhg" : 5 } } } }'::jsonb @@ parse_mquery('{ "a.qwerty.asdfgh.fgfhg" : { $eq: 5 } }');
627+
select '{ "_id" : 3, "results" : [ { "product" : "abc", "score" : 7 }, { "product" : "abc", "score" : 8 } ] }' @@ parse_mquery('{ results: { $elemMatch: { product: "abc" } } }');
628+
select '{ "_id" : 3, "results" : [ 81, 84, 83] }' @@ parse_mquery('{ results: { $elemMatch: { $gte: 80, $lt: 85 } } }');
629+
select '{ "_id" : 3, "results" : [ 81, 86, 83] }' @@ parse_mquery('{ results: { $elemMatch: { $gte: 80, $lt: 85 } } }');
630+
566631
RESET enable_seqscan;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy