Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit60c0c71

Browse files
author
Nikita Glukhov
committed
Add jsonpath @@ support
1 parentadece56 commit60c0c71

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

‎jsonb_gin_ops.c‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ typedef struct
6161
#defineJsonbNestedContainsStrategyNumber13
6262
#defineJsQueryMatchStrategyNumber14
6363
#defineJsonpathExistsStrategyNumber15
64+
#defineJsonpathMatchStrategyNumber16
6465

6566
typedefstruct
6667
{
@@ -587,7 +588,8 @@ gin_compare_partial_jsonb_value_path(PG_FUNCTION_ARGS)
587588
int32result;
588589

589590
if (strategy==JsQueryMatchStrategyNumber||
590-
strategy==JsonpathExistsStrategyNumber)
591+
strategy==JsonpathExistsStrategyNumber||
592+
strategy==JsonpathMatchStrategyNumber)
591593
{
592594
KeyExtra*extra= (KeyExtra*)PG_GETARG_POINTER(3);
593595
ExtractedNode*node=extra->node;
@@ -809,8 +811,10 @@ gin_extract_jsonb_query_value_path(PG_FUNCTION_ARGS)
809811
caseJsQueryMatchStrategyNumber:
810812
#ifndefNO_JSONPATH
811813
caseJsonpathExistsStrategyNumber:
812-
if (strategy==JsonpathExistsStrategyNumber)
814+
caseJsonpathMatchStrategyNumber:
815+
if (strategy!=JsQueryMatchStrategyNumber)
813816
root=extractJsonPath(PG_GETARG_JSONPATH_P(0),
817+
strategy==JsonpathExistsStrategyNumber,
814818
make_value_path_entry_handler,
815819
check_value_path_entry_handler,
816820
(Pointer)&e);
@@ -878,6 +882,7 @@ gin_consistent_jsonb_value_path(PG_FUNCTION_ARGS)
878882

879883
caseJsQueryMatchStrategyNumber:
880884
caseJsonpathExistsStrategyNumber:
885+
caseJsonpathMatchStrategyNumber:
881886
if (nkeys==0)
882887
res= true;
883888
else
@@ -940,6 +945,7 @@ gin_triconsistent_jsonb_value_path(PG_FUNCTION_ARGS)
940945

941946
caseJsQueryMatchStrategyNumber:
942947
caseJsonpathExistsStrategyNumber:
948+
caseJsonpathMatchStrategyNumber:
943949
if (nkeys==0)
944950
res=GIN_MAYBE;
945951
else
@@ -1063,7 +1069,8 @@ gin_compare_partial_jsonb_path_value(PG_FUNCTION_ARGS)
10631069
result= (key->hash>partial_key->hash) ?1 :-1;
10641070
}
10651071
elseif (strategy==JsQueryMatchStrategyNumber||
1066-
strategy==JsonpathExistsStrategyNumber)
1072+
strategy==JsonpathExistsStrategyNumber||
1073+
strategy==JsonpathMatchStrategyNumber)
10671074
{
10681075
KeyExtra*extra= (KeyExtra*)PG_GETARG_POINTER(3);
10691076
ExtractedNode*node=extra->node;
@@ -1276,8 +1283,10 @@ gin_extract_jsonb_query_path_value_internal(FunctionCallInfo fcinfo, bool lax)
12761283
caseJsQueryMatchStrategyNumber:
12771284
#ifndefNO_JSONPATH
12781285
caseJsonpathExistsStrategyNumber:
1279-
if (strategy==JsonpathExistsStrategyNumber)
1286+
caseJsonpathMatchStrategyNumber:
1287+
if (strategy!=JsQueryMatchStrategyNumber)
12801288
root=extractJsonPath(PG_GETARG_JSONPATH_P(0),
1289+
strategy==JsonpathExistsStrategyNumber,
12811290
make_path_value_entry_handler,
12821291
check_path_value_entry_handler,
12831292
(Pointer)&extra);
@@ -1356,6 +1365,7 @@ gin_consistent_jsonb_path_value(PG_FUNCTION_ARGS)
13561365

13571366
caseJsQueryMatchStrategyNumber:
13581367
caseJsonpathExistsStrategyNumber:
1368+
caseJsonpathMatchStrategyNumber:
13591369
if (nkeys==0)
13601370
res= true;
13611371
else
@@ -1418,6 +1428,7 @@ gin_triconsistent_jsonb_path_value(PG_FUNCTION_ARGS)
14181428

14191429
caseJsQueryMatchStrategyNumber:
14201430
caseJsonpathExistsStrategyNumber:
1431+
caseJsonpathMatchStrategyNumber:
14211432
if (nkeys==0)
14221433
res=GIN_MAYBE;
14231434
else

‎jsquery--1.1.sql‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ CREATE OR REPLACE FUNCTION gin_debug_query_laxpath_value(jsquery)
330330
AS'MODULE_PATHNAME'
331331
LANGUAGE C STRICT IMMUTABLE;
332332

333-
-- add support foroperator @? (jsonb, jsonpath) if type jsonpath exists in catalog
333+
-- add support foroperators @?, @@ (jsonb, jsonpath) if type jsonpath exists in catalog
334334
DO LANGUAGE plpgsql
335335
$$
336336
BEGIN
@@ -346,10 +346,16 @@ BEGIN
346346
IF FOUND THEN
347347
ALTEROPERATOR FAMILY jsonb_path_value_ops USING gin
348348
ADD OPERATOR15 @? (jsonb, jsonpath);
349+
ALTEROPERATOR FAMILY jsonb_path_value_ops USING gin
350+
ADD OPERATOR16 @@ (jsonb, jsonpath);
349351
ALTEROPERATOR FAMILY jsonb_laxpath_value_ops USING gin
350352
ADD OPERATOR15 @? (jsonb, jsonpath);
353+
ALTEROPERATOR FAMILY jsonb_laxpath_value_ops USING gin
354+
ADD OPERATOR16 @@ (jsonb, jsonpath);
351355
ALTEROPERATOR FAMILY jsonb_value_path_ops USING gin
352356
ADD OPERATOR15 @? (jsonb, jsonpath);
357+
ALTEROPERATOR FAMILY jsonb_value_path_ops USING gin
358+
ADD OPERATOR16 @@ (jsonb, jsonpath);
353359
END IF;
354360
END
355361
$$;

‎jsquery.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ bool isLogicalNodeType(ExtractedNodeType type);
245245
ExtractedNode*extractJsQuery(JsQuery*jq,MakeEntryHandlermakeHandler,
246246
CheckEntryHandlercheckHandler,Pointerextra);
247247
#ifndefNO_JSONPATH
248-
ExtractedNode*extractJsonPath(JsonPath*jp,MakeEntryHandlermakeHandler,
248+
ExtractedNode*extractJsonPath(JsonPath*jp,boolexists,
249+
MakeEntryHandlermakeHandler,
249250
CheckEntryHandlercheckHandler,Pointerextra);
250251
#endif
251252
char*debugJsQuery(JsQuery*jq,MakeEntryHandlermakeHandler,

‎jsquery_extract.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,15 +1346,17 @@ extractJsQuery(JsQuery *jq, MakeEntryHandler makeHandler,
13461346
* Turn jsonpath into tree of entries using user-provided handler.
13471347
*/
13481348
ExtractedNode*
1349-
extractJsonPath(JsonPath*jp,MakeEntryHandlermakeHandler,
1349+
extractJsonPath(JsonPath*jp,boolexists,MakeEntryHandlermakeHandler,
13501350
CheckEntryHandlercheckHandler,Pointerextra)
13511351
{
13521352
ExtractedNode*root;
13531353
JsonPathItemjsp;
1354-
boollax= (jp->header&JSONPATH_LAX)!=0;
1354+
boollax= (jp->header&JSONPATH_LAX)!=0;
13551355

13561356
jspInit(&jsp,jp);
1357-
root=recursiveExtractJsonPathExpr(&jsp,lax, false,NULL);
1357+
root=exists
1358+
?extractJsonPathExists(&jsp,lax,NULL)
1359+
:recursiveExtractJsonPathExpr(&jsp,lax, false,NULL);
13581360
if (root)
13591361
{
13601362
flatternTree(root);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp