Skip to content

Commit 0958f8f

Browse files
committed
Revert "Reorganise jsonpath operators and methods"
This reverts commit 283a95d. The reordering of JsonPathItemType affects the binary on-disk compatibility of the jsonpath type, so we must not change it. Revert for now and consider.
1 parent 76ba8a8 commit 0958f8f

File tree

5 files changed

+112
-119
lines changed

5 files changed

+112
-119
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>abs()</literal>
17694+
<replaceable>number</replaceable> <literal>.</literal> <literal>ceiling()</literal>
1769517695
<returnvalue><replaceable>number</replaceable></returnvalue>
1769617696
</para>
1769717697
<para>
17698-
Absolute value of the given number
17698+
Nearest integer greater than or equal to the given number
1769917699
</para>
1770017700
<para>
17701-
<literal>jsonb_path_query('{"z": -0.3}', '$.z.abs()')</literal>
17702-
<returnvalue>0.3</returnvalue>
17701+
<literal>jsonb_path_query('{"h": 1.3}', '$.h.ceiling()')</literal>
17702+
<returnvalue>2</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>ceiling()</literal>
17708+
<replaceable>number</replaceable> <literal>.</literal> <literal>floor()</literal>
1770917709
<returnvalue><replaceable>number</replaceable></returnvalue>
1771017710
</para>
1771117711
<para>
17712-
Nearest integer greater than or equal to the given number
17712+
Nearest integer less than or equal to the given number
1771317713
</para>
1771417714
<para>
17715-
<literal>jsonb_path_query('{"h": 1.3}', '$.h.ceiling()')</literal>
17716-
<returnvalue>2</returnvalue>
17715+
<literal>jsonb_path_query('{"h": 1.7}', '$.h.floor()')</literal>
17716+
<returnvalue>1</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>floor()</literal>
17722+
<replaceable>number</replaceable> <literal>.</literal> <literal>abs()</literal>
1772317723
<returnvalue><replaceable>number</replaceable></returnvalue>
1772417724
</para>
1772517725
<para>
17726-
Nearest integer less than or equal to the given number
17726+
Absolute value of the given number
1772717727
</para>
1772817728
<para>
17729-
<literal>jsonb_path_query('{"h": 1.7}', '$.h.floor()')</literal>
17730-
<returnvalue>1</returnvalue>
17729+
<literal>jsonb_path_query('{"z": -0.3}', '$.z.abs()')</literal>
17730+
<returnvalue>0.3</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
case jpiType:
441441
case jpiSize:
442-
case jpiDouble:
443442
case jpiAbs:
444-
case jpiCeiling:
445443
case jpiFloor:
444+
case jpiCeiling:
445+
case jpiDouble:
446446
case jpiKeyValue:
447447
break;
448448
default:
@@ -610,6 +610,18 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
610610
if (printBracketes)
611611
appendStringInfoChar(buf, ')');
612612
break;
613+
case jpiPlus:
614+
case jpiMinus:
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;
613625
case jpiFilter:
614626
appendStringInfoString(buf, "?(");
615627
jspGetArg(v, &elem);
@@ -700,35 +712,23 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
700712
v->content.anybounds.first,
701713
v->content.anybounds.last);
702714
break;
703-
case jpiPlus:
704-
case jpiMinus:
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
case jpiType:
716716
appendStringInfoString(buf, ".type()");
717717
break;
718718
case jpiSize:
719719
appendStringInfoString(buf, ".size()");
720720
break;
721-
case jpiDouble:
722-
appendStringInfoString(buf, ".double()");
723-
break;
724721
case jpiAbs:
725722
appendStringInfoString(buf, ".abs()");
726723
break;
724+
case jpiFloor:
725+
appendStringInfoString(buf, ".floor()");
726+
break;
727727
case jpiCeiling:
728728
appendStringInfoString(buf, ".ceiling()");
729729
break;
730-
case jpiFloor:
731-
appendStringInfoString(buf, ".floor()");
730+
case jpiDouble:
731+
appendStringInfoString(buf, ".double()");
732732
break;
733733
case jpiDatetime:
734734
appendStringInfoString(buf, ".datetime(");
@@ -771,38 +771,38 @@ jspOperationName(JsonPathItemType type)
771771
return "<=";
772772
case jpiGreaterOrEqual:
773773
return ">=";
774-
case jpiAdd:
775774
case jpiPlus:
775+
case jpiAdd:
776776
return "+";
777-
case jpiSub:
778777
case jpiMinus:
778+
case jpiSub:
779779
return "-";
780780
case jpiMul:
781781
return "*";
782782
case jpiDiv:
783783
return "/";
784784
case jpiMod:
785785
return "%";
786+
case jpiStartsWith:
787+
return "starts with";
788+
case jpiLikeRegex:
789+
return "like_regex";
786790
case jpiType:
787791
return "type";
788792
case jpiSize:
789793
return "size";
794+
case jpiKeyValue:
795+
return "keyvalue";
790796
case jpiDouble:
791797
return "double";
792798
case jpiAbs:
793799
return "abs";
794-
case jpiCeiling:
795-
return "ceiling";
796800
case jpiFloor:
797801
return "floor";
802+
case jpiCeiling:
803+
return "ceiling";
798804
case jpiDatetime:
799805
return "datetime";
800-
case jpiKeyValue:
801-
return "keyvalue";
802-
case jpiStartsWith:
803-
return "starts with";
804-
case jpiLikeRegex:
805-
return "like_regex";
806806
default:
807807
elog(ERROR, "unrecognized jsonpath item type: %d", type);
808808
return NULL;
@@ -893,10 +893,10 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
893893
case jpiAnyKey:
894894
case jpiType:
895895
case jpiSize:
896-
case jpiDouble:
897896
case jpiAbs:
898-
case jpiCeiling:
899897
case jpiFloor:
898+
case jpiCeiling:
899+
case jpiDouble:
900900
case jpiKeyValue:
901901
case jpiLast:
902902
break;
@@ -935,9 +935,9 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
935935
case jpiNot:
936936
case jpiExists:
937937
case jpiIsUnknown:
938-
case jpiFilter:
939938
case jpiPlus:
940939
case jpiMinus:
940+
case jpiFilter:
941941
case jpiDatetime:
942942
read_int32(v->content.arg, base, pos);
943943
break;
@@ -989,6 +989,13 @@ 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 ||
992999
v->type == jpiEqual ||
9931000
v->type == jpiNotEqual ||
9941001
v->type == jpiGreater ||
@@ -999,19 +1006,12 @@ jspGetNext(JsonPathItem *v, JsonPathItem *a)
9991006
v->type == jpiOr ||
10001007
v->type == jpiNot ||
10011008
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 ||
10121011
v->type == jpiAbs ||
1013-
v->type == jpiCeiling ||
10141012
v->type == jpiFloor ||
1013+
v->type == jpiCeiling ||
1014+
v->type == jpiDouble ||
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,6 +874,33 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
874874
}
875875
break;
876876

877+
case jpiAdd:
878+
return executeBinaryArithmExpr(cxt, jsp, jb,
879+
numeric_add_opt_error, found);
880+
881+
case jpiSub:
882+
return executeBinaryArithmExpr(cxt, jsp, jb,
883+
numeric_sub_opt_error, found);
884+
885+
case jpiMul:
886+
return executeBinaryArithmExpr(cxt, jsp, jb,
887+
numeric_mul_opt_error, found);
888+
889+
case jpiDiv:
890+
return executeBinaryArithmExpr(cxt, jsp, jb,
891+
numeric_div_opt_error, found);
892+
893+
case jpiMod:
894+
return executeBinaryArithmExpr(cxt, jsp, jb,
895+
numeric_mod_opt_error, found);
896+
897+
case jpiPlus:
898+
return executeUnaryArithmExpr(cxt, jsp, jb, NULL, found);
899+
900+
case jpiMinus:
901+
return executeUnaryArithmExpr(cxt, jsp, jb, numeric_uminus,
902+
found);
903+
877904
case jpiFilter:
878905
{
879906
JsonPathBool st;
@@ -953,33 +980,6 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
953980
}
954981
break;
955982

956-
case jpiAdd:
957-
return executeBinaryArithmExpr(cxt, jsp, jb,
958-
numeric_add_opt_error, found);
959-
960-
case jpiPlus:
961-
return executeUnaryArithmExpr(cxt, jsp, jb, NULL, found);
962-
963-
case jpiSub:
964-
return executeBinaryArithmExpr(cxt, jsp, jb,
965-
numeric_sub_opt_error, found);
966-
967-
case jpiMinus:
968-
return executeUnaryArithmExpr(cxt, jsp, jb, numeric_uminus,
969-
found);
970-
971-
case jpiMul:
972-
return executeBinaryArithmExpr(cxt, jsp, jb,
973-
numeric_mul_opt_error, found);
974-
975-
case jpiDiv:
976-
return executeBinaryArithmExpr(cxt, jsp, jb,
977-
numeric_div_opt_error, found);
978-
979-
case jpiMod:
980-
return executeBinaryArithmExpr(cxt, jsp, jb,
981-
numeric_mod_opt_error, found);
982-
983983
case jpiType:
984984
{
985985
JsonbValue *jbv = palloc(sizeof(*jbv));
@@ -1021,6 +1021,18 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
10211021
}
10221022
break;
10231023

1024+
case jpiAbs:
1025+
return executeNumericItemMethod(cxt, jsp, jb, unwrap, numeric_abs,
1026+
found);
1027+
1028+
case jpiFloor:
1029+
return executeNumericItemMethod(cxt, jsp, jb, unwrap, numeric_floor,
1030+
found);
1031+
1032+
case jpiCeiling:
1033+
return executeNumericItemMethod(cxt, jsp, jb, unwrap, numeric_ceil,
1034+
found);
1035+
10241036
case jpiDouble:
10251037
{
10261038
JsonbValue jbv;
@@ -1086,18 +1098,6 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
10861098
}
10871099
break;
10881100

1089-
case jpiAbs:
1090-
return executeNumericItemMethod(cxt, jsp, jb, unwrap, numeric_abs,
1091-
found);
1092-
1093-
case jpiCeiling:
1094-
return executeNumericItemMethod(cxt, jsp, jb, unwrap, numeric_ceil,
1095-
found);
1096-
1097-
case jpiFloor:
1098-
return executeNumericItemMethod(cxt, jsp, jb, unwrap, numeric_floor,
1099-
found);
1100-
11011101
case jpiDatetime:
11021102
if (unwrap && JsonbType(jb) == jbvArray)
11031103
return executeItemUnwrapTargetArray(cxt, jsp, jb, found, false);

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