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

Commit283a95d

Browse files
committed
Reorganise jsonpath operators and methods
Various jsonpath operators and methods add various keywords, switchcases, and documentation entries in some order. However, they are notconsistent; reorder them for better maintainability or readability.Author: Jeevan Chalke <jeevan.chalke@enterprisedb.com>Discussion:https://www.postgresql.org/message-id/flat/CAM2+6=XjTyqrrqHAOj80r0wVQxJSxc0iyib9bPC55uFO9VKatg@mail.gmail.com
1 parentc1b9e1e commit283a95d

File tree

5 files changed

+119
-112
lines changed

5 files changed

+119
-112
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17691,43 +17691,43 @@ strict $.**.HR
1769117691

1769217692
<row>
1769317693
<entry role="func_table_entry"><para role="func_signature">
17694-
<replaceable>number</replaceable> <literal>.</literal> <literal>ceiling()</literal>
17694+
<replaceable>number</replaceable> <literal>.</literal> <literal>abs()</literal>
1769517695
<returnvalue><replaceable>number</replaceable></returnvalue>
1769617696
</para>
1769717697
<para>
17698-
Nearest integer greater than or equal to the given number
17698+
Absolute value of the given number
1769917699
</para>
1770017700
<para>
17701-
<literal>jsonb_path_query('{"h":1.3}', '$.h.ceiling()')</literal>
17702-
<returnvalue>2</returnvalue>
17701+
<literal>jsonb_path_query('{"z":-0.3}', '$.z.abs()')</literal>
17702+
<returnvalue>0.3</returnvalue>
1770317703
</para></entry>
1770417704
</row>
1770517705

1770617706
<row>
1770717707
<entry role="func_table_entry"><para role="func_signature">
17708-
<replaceable>number</replaceable> <literal>.</literal> <literal>floor()</literal>
17708+
<replaceable>number</replaceable> <literal>.</literal> <literal>ceiling()</literal>
1770917709
<returnvalue><replaceable>number</replaceable></returnvalue>
1771017710
</para>
1771117711
<para>
17712-
Nearest integerless than or equal to the given number
17712+
Nearest integergreater than or equal to the given number
1771317713
</para>
1771417714
<para>
17715-
<literal>jsonb_path_query('{"h": 1.7}', '$.h.floor()')</literal>
17716-
<returnvalue>1</returnvalue>
17715+
<literal>jsonb_path_query('{"h": 1.3}', '$.h.ceiling()')</literal>
17716+
<returnvalue>2</returnvalue>
1771717717
</para></entry>
1771817718
</row>
1771917719

1772017720
<row>
1772117721
<entry role="func_table_entry"><para role="func_signature">
17722-
<replaceable>number</replaceable> <literal>.</literal> <literal>abs()</literal>
17722+
<replaceable>number</replaceable> <literal>.</literal> <literal>floor()</literal>
1772317723
<returnvalue><replaceable>number</replaceable></returnvalue>
1772417724
</para>
1772517725
<para>
17726-
Absolute value of the given number
17726+
Nearest integer less than or equal to the given number
1772717727
</para>
1772817728
<para>
17729-
<literal>jsonb_path_query('{"z":-0.3}', '$.z.abs()')</literal>
17730-
<returnvalue>0.3</returnvalue>
17729+
<literal>jsonb_path_query('{"h":1.7}', '$.h.floor()')</literal>
17730+
<returnvalue>1</returnvalue>
1773117731
</para></entry>
1773217732
</row>
1773317733

‎src/backend/utils/adt/jsonpath.c

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,10 @@ flattenJsonPathParseItem(StringInfo buf, int *result, struct Node *escontext,
439439
break;
440440
casejpiType:
441441
casejpiSize:
442+
casejpiDouble:
442443
casejpiAbs:
443-
casejpiFloor:
444444
casejpiCeiling:
445-
casejpiDouble:
445+
casejpiFloor:
446446
casejpiKeyValue:
447447
break;
448448
default:
@@ -610,18 +610,6 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
610610
if (printBracketes)
611611
appendStringInfoChar(buf,')');
612612
break;
613-
casejpiPlus:
614-
casejpiMinus:
615-
if (printBracketes)
616-
appendStringInfoChar(buf,'(');
617-
appendStringInfoChar(buf,v->type==jpiPlus ?'+' :'-');
618-
jspGetArg(v,&elem);
619-
printJsonPathItem(buf,&elem, false,
620-
operationPriority(elem.type) <=
621-
operationPriority(v->type));
622-
if (printBracketes)
623-
appendStringInfoChar(buf,')');
624-
break;
625613
casejpiFilter:
626614
appendStringInfoString(buf,"?(");
627615
jspGetArg(v,&elem);
@@ -712,23 +700,35 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
712700
v->content.anybounds.first,
713701
v->content.anybounds.last);
714702
break;
703+
casejpiPlus:
704+
casejpiMinus:
705+
if (printBracketes)
706+
appendStringInfoChar(buf,'(');
707+
appendStringInfoChar(buf,v->type==jpiPlus ?'+' :'-');
708+
jspGetArg(v,&elem);
709+
printJsonPathItem(buf,&elem, false,
710+
operationPriority(elem.type) <=
711+
operationPriority(v->type));
712+
if (printBracketes)
713+
appendStringInfoChar(buf,')');
714+
break;
715715
casejpiType:
716716
appendStringInfoString(buf,".type()");
717717
break;
718718
casejpiSize:
719719
appendStringInfoString(buf,".size()");
720720
break;
721+
casejpiDouble:
722+
appendStringInfoString(buf,".double()");
723+
break;
721724
casejpiAbs:
722725
appendStringInfoString(buf,".abs()");
723726
break;
724-
casejpiFloor:
725-
appendStringInfoString(buf,".floor()");
726-
break;
727727
casejpiCeiling:
728728
appendStringInfoString(buf,".ceiling()");
729729
break;
730-
casejpiDouble:
731-
appendStringInfoString(buf,".double()");
730+
casejpiFloor:
731+
appendStringInfoString(buf,".floor()");
732732
break;
733733
casejpiDatetime:
734734
appendStringInfoString(buf,".datetime(");
@@ -771,38 +771,38 @@ jspOperationName(JsonPathItemType type)
771771
return"<=";
772772
casejpiGreaterOrEqual:
773773
return">=";
774-
casejpiPlus:
775774
casejpiAdd:
775+
casejpiPlus:
776776
return"+";
777-
casejpiMinus:
778777
casejpiSub:
778+
casejpiMinus:
779779
return"-";
780780
casejpiMul:
781781
return"*";
782782
casejpiDiv:
783783
return"/";
784784
casejpiMod:
785785
return"%";
786-
casejpiStartsWith:
787-
return"starts with";
788-
casejpiLikeRegex:
789-
return"like_regex";
790786
casejpiType:
791787
return"type";
792788
casejpiSize:
793789
return"size";
794-
casejpiKeyValue:
795-
return"keyvalue";
796790
casejpiDouble:
797791
return"double";
798792
casejpiAbs:
799793
return"abs";
800-
casejpiFloor:
801-
return"floor";
802794
casejpiCeiling:
803795
return"ceiling";
796+
casejpiFloor:
797+
return"floor";
804798
casejpiDatetime:
805799
return"datetime";
800+
casejpiKeyValue:
801+
return"keyvalue";
802+
casejpiStartsWith:
803+
return"starts with";
804+
casejpiLikeRegex:
805+
return"like_regex";
806806
default:
807807
elog(ERROR,"unrecognized jsonpath item type: %d",type);
808808
returnNULL;
@@ -893,10 +893,10 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
893893
casejpiAnyKey:
894894
casejpiType:
895895
casejpiSize:
896+
casejpiDouble:
896897
casejpiAbs:
897-
casejpiFloor:
898898
casejpiCeiling:
899-
casejpiDouble:
899+
casejpiFloor:
900900
casejpiKeyValue:
901901
casejpiLast:
902902
break;
@@ -935,9 +935,9 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
935935
casejpiNot:
936936
casejpiExists:
937937
casejpiIsUnknown:
938+
casejpiFilter:
938939
casejpiPlus:
939940
casejpiMinus:
940-
casejpiFilter:
941941
casejpiDatetime:
942942
read_int32(v->content.arg,base,pos);
943943
break;
@@ -989,13 +989,6 @@ jspGetNext(JsonPathItem *v, JsonPathItem *a)
989989
v->type==jpiRoot||
990990
v->type==jpiVariable||
991991
v->type==jpiLast||
992-
v->type==jpiAdd||
993-
v->type==jpiSub||
994-
v->type==jpiMul||
995-
v->type==jpiDiv||
996-
v->type==jpiMod||
997-
v->type==jpiPlus||
998-
v->type==jpiMinus||
999992
v->type==jpiEqual||
1000993
v->type==jpiNotEqual||
1001994
v->type==jpiGreater||
@@ -1006,12 +999,19 @@ jspGetNext(JsonPathItem *v, JsonPathItem *a)
1006999
v->type==jpiOr||
10071000
v->type==jpiNot||
10081001
v->type==jpiIsUnknown||
1002+
v->type==jpiAdd||
1003+
v->type==jpiPlus||
1004+
v->type==jpiSub||
1005+
v->type==jpiMinus||
1006+
v->type==jpiMul||
1007+
v->type==jpiDiv||
1008+
v->type==jpiMod||
10091009
v->type==jpiType||
10101010
v->type==jpiSize||
1011+
v->type==jpiDouble||
10111012
v->type==jpiAbs||
1012-
v->type==jpiFloor||
10131013
v->type==jpiCeiling||
1014-
v->type==jpiDouble||
1014+
v->type==jpiFloor||
10151015
v->type==jpiDatetime||
10161016
v->type==jpiKeyValue||
10171017
v->type==jpiStartsWith||

‎src/backend/utils/adt/jsonpath_exec.c

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -874,33 +874,6 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
874874
}
875875
break;
876876

877-
casejpiAdd:
878-
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
879-
numeric_add_opt_error,found);
880-
881-
casejpiSub:
882-
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
883-
numeric_sub_opt_error,found);
884-
885-
casejpiMul:
886-
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
887-
numeric_mul_opt_error,found);
888-
889-
casejpiDiv:
890-
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
891-
numeric_div_opt_error,found);
892-
893-
casejpiMod:
894-
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
895-
numeric_mod_opt_error,found);
896-
897-
casejpiPlus:
898-
returnexecuteUnaryArithmExpr(cxt,jsp,jb,NULL,found);
899-
900-
casejpiMinus:
901-
returnexecuteUnaryArithmExpr(cxt,jsp,jb,numeric_uminus,
902-
found);
903-
904877
casejpiFilter:
905878
{
906879
JsonPathBoolst;
@@ -980,6 +953,33 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
980953
}
981954
break;
982955

956+
casejpiAdd:
957+
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
958+
numeric_add_opt_error,found);
959+
960+
casejpiPlus:
961+
returnexecuteUnaryArithmExpr(cxt,jsp,jb,NULL,found);
962+
963+
casejpiSub:
964+
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
965+
numeric_sub_opt_error,found);
966+
967+
casejpiMinus:
968+
returnexecuteUnaryArithmExpr(cxt,jsp,jb,numeric_uminus,
969+
found);
970+
971+
casejpiMul:
972+
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
973+
numeric_mul_opt_error,found);
974+
975+
casejpiDiv:
976+
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
977+
numeric_div_opt_error,found);
978+
979+
casejpiMod:
980+
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
981+
numeric_mod_opt_error,found);
982+
983983
casejpiType:
984984
{
985985
JsonbValue*jbv=palloc(sizeof(*jbv));
@@ -1021,18 +1021,6 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
10211021
}
10221022
break;
10231023

1024-
casejpiAbs:
1025-
returnexecuteNumericItemMethod(cxt,jsp,jb,unwrap,numeric_abs,
1026-
found);
1027-
1028-
casejpiFloor:
1029-
returnexecuteNumericItemMethod(cxt,jsp,jb,unwrap,numeric_floor,
1030-
found);
1031-
1032-
casejpiCeiling:
1033-
returnexecuteNumericItemMethod(cxt,jsp,jb,unwrap,numeric_ceil,
1034-
found);
1035-
10361024
casejpiDouble:
10371025
{
10381026
JsonbValuejbv;
@@ -1098,6 +1086,18 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
10981086
}
10991087
break;
11001088

1089+
casejpiAbs:
1090+
returnexecuteNumericItemMethod(cxt,jsp,jb,unwrap,numeric_abs,
1091+
found);
1092+
1093+
casejpiCeiling:
1094+
returnexecuteNumericItemMethod(cxt,jsp,jb,unwrap,numeric_ceil,
1095+
found);
1096+
1097+
casejpiFloor:
1098+
returnexecuteNumericItemMethod(cxt,jsp,jb,unwrap,numeric_floor,
1099+
found);
1100+
11011101
casejpiDatetime:
11021102
if (unwrap&&JsonbType(jb)==jbvArray)
11031103
returnexecuteItemUnwrapTargetArray(cxt,jsp,jb,found, false);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp