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

Commit59fd390

Browse files
committed
Second attempt at organizing jsonpath operators and methods
Second attempt at283a95d. Since we can't reorder the enum valuesof JsonPathItemType, instead reorder the switch cases where they areused to generally follow the order of the enum values, for bettermaintainability.
1 parent0958f8f commit59fd390

File tree

3 files changed

+298
-291
lines changed

3 files changed

+298
-291
lines changed

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

Lines changed: 125 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -519,18 +519,9 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
519519
casejpiNull:
520520
appendStringInfoString(buf,"null");
521521
break;
522-
casejpiKey:
523-
if (inKey)
524-
appendStringInfoChar(buf,'.');
525-
escape_json(buf,jspGetString(v,NULL));
526-
break;
527522
casejpiString:
528523
escape_json(buf,jspGetString(v,NULL));
529524
break;
530-
casejpiVariable:
531-
appendStringInfoChar(buf,'$');
532-
escape_json(buf,jspGetString(v,NULL));
533-
break;
534525
casejpiNumeric:
535526
if (jspHasNext(v))
536527
appendStringInfoChar(buf,'(');
@@ -576,58 +567,6 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
576567
if (printBracketes)
577568
appendStringInfoChar(buf,')');
578569
break;
579-
casejpiLikeRegex:
580-
if (printBracketes)
581-
appendStringInfoChar(buf,'(');
582-
583-
jspInitByBuffer(&elem,v->base,v->content.like_regex.expr);
584-
printJsonPathItem(buf,&elem, false,
585-
operationPriority(elem.type) <=
586-
operationPriority(v->type));
587-
588-
appendStringInfoString(buf," like_regex ");
589-
590-
escape_json(buf,v->content.like_regex.pattern);
591-
592-
if (v->content.like_regex.flags)
593-
{
594-
appendStringInfoString(buf," flag \"");
595-
596-
if (v->content.like_regex.flags&JSP_REGEX_ICASE)
597-
appendStringInfoChar(buf,'i');
598-
if (v->content.like_regex.flags&JSP_REGEX_DOTALL)
599-
appendStringInfoChar(buf,'s');
600-
if (v->content.like_regex.flags&JSP_REGEX_MLINE)
601-
appendStringInfoChar(buf,'m');
602-
if (v->content.like_regex.flags&JSP_REGEX_WSPACE)
603-
appendStringInfoChar(buf,'x');
604-
if (v->content.like_regex.flags&JSP_REGEX_QUOTE)
605-
appendStringInfoChar(buf,'q');
606-
607-
appendStringInfoChar(buf,'"');
608-
}
609-
610-
if (printBracketes)
611-
appendStringInfoChar(buf,')');
612-
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;
625-
casejpiFilter:
626-
appendStringInfoString(buf,"?(");
627-
jspGetArg(v,&elem);
628-
printJsonPathItem(buf,&elem, false, false);
629-
appendStringInfoChar(buf,')');
630-
break;
631570
casejpiNot:
632571
appendStringInfoString(buf,"!(");
633572
jspGetArg(v,&elem);
@@ -640,22 +579,17 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
640579
printJsonPathItem(buf,&elem, false, false);
641580
appendStringInfoString(buf,") is unknown");
642581
break;
643-
casejpiExists:
644-
appendStringInfoString(buf,"exists (");
582+
casejpiPlus:
583+
casejpiMinus:
584+
if (printBracketes)
585+
appendStringInfoChar(buf,'(');
586+
appendStringInfoChar(buf,v->type==jpiPlus ?'+' :'-');
645587
jspGetArg(v,&elem);
646-
printJsonPathItem(buf,&elem, false, false);
647-
appendStringInfoChar(buf,')');
648-
break;
649-
casejpiCurrent:
650-
Assert(!inKey);
651-
appendStringInfoChar(buf,'@');
652-
break;
653-
casejpiRoot:
654-
Assert(!inKey);
655-
appendStringInfoChar(buf,'$');
656-
break;
657-
casejpiLast:
658-
appendStringInfoString(buf,"last");
588+
printJsonPathItem(buf,&elem, false,
589+
operationPriority(elem.type) <=
590+
operationPriority(v->type));
591+
if (printBracketes)
592+
appendStringInfoChar(buf,')');
659593
break;
660594
casejpiAnyArray:
661595
appendStringInfoString(buf,"[*]");
@@ -712,6 +646,35 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
712646
v->content.anybounds.first,
713647
v->content.anybounds.last);
714648
break;
649+
casejpiKey:
650+
if (inKey)
651+
appendStringInfoChar(buf,'.');
652+
escape_json(buf,jspGetString(v,NULL));
653+
break;
654+
casejpiCurrent:
655+
Assert(!inKey);
656+
appendStringInfoChar(buf,'@');
657+
break;
658+
casejpiRoot:
659+
Assert(!inKey);
660+
appendStringInfoChar(buf,'$');
661+
break;
662+
casejpiVariable:
663+
appendStringInfoChar(buf,'$');
664+
escape_json(buf,jspGetString(v,NULL));
665+
break;
666+
casejpiFilter:
667+
appendStringInfoString(buf,"?(");
668+
jspGetArg(v,&elem);
669+
printJsonPathItem(buf,&elem, false, false);
670+
appendStringInfoChar(buf,')');
671+
break;
672+
casejpiExists:
673+
appendStringInfoString(buf,"exists (");
674+
jspGetArg(v,&elem);
675+
printJsonPathItem(buf,&elem, false, false);
676+
appendStringInfoChar(buf,')');
677+
break;
715678
casejpiType:
716679
appendStringInfoString(buf,".type()");
717680
break;
@@ -742,6 +705,43 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
742705
casejpiKeyValue:
743706
appendStringInfoString(buf,".keyvalue()");
744707
break;
708+
casejpiLast:
709+
appendStringInfoString(buf,"last");
710+
break;
711+
casejpiLikeRegex:
712+
if (printBracketes)
713+
appendStringInfoChar(buf,'(');
714+
715+
jspInitByBuffer(&elem,v->base,v->content.like_regex.expr);
716+
printJsonPathItem(buf,&elem, false,
717+
operationPriority(elem.type) <=
718+
operationPriority(v->type));
719+
720+
appendStringInfoString(buf," like_regex ");
721+
722+
escape_json(buf,v->content.like_regex.pattern);
723+
724+
if (v->content.like_regex.flags)
725+
{
726+
appendStringInfoString(buf," flag \"");
727+
728+
if (v->content.like_regex.flags&JSP_REGEX_ICASE)
729+
appendStringInfoChar(buf,'i');
730+
if (v->content.like_regex.flags&JSP_REGEX_DOTALL)
731+
appendStringInfoChar(buf,'s');
732+
if (v->content.like_regex.flags&JSP_REGEX_MLINE)
733+
appendStringInfoChar(buf,'m');
734+
if (v->content.like_regex.flags&JSP_REGEX_WSPACE)
735+
appendStringInfoChar(buf,'x');
736+
if (v->content.like_regex.flags&JSP_REGEX_QUOTE)
737+
appendStringInfoChar(buf,'q');
738+
739+
appendStringInfoChar(buf,'"');
740+
}
741+
742+
if (printBracketes)
743+
appendStringInfoChar(buf,')');
744+
break;
745745
default:
746746
elog(ERROR,"unrecognized jsonpath item type: %d",v->type);
747747
}
@@ -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";
796-
casejpiDouble:
797-
return"double";
798790
casejpiAbs:
799791
return"abs";
800792
casejpiFloor:
801793
return"floor";
802794
casejpiCeiling:
803795
return"ceiling";
796+
casejpiDouble:
797+
return"double";
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;
@@ -900,8 +900,8 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
900900
casejpiKeyValue:
901901
casejpiLast:
902902
break;
903-
casejpiKey:
904903
casejpiString:
904+
casejpiKey:
905905
casejpiVariable:
906906
read_int32(v->content.value.datalen,base,pos);
907907
/* FALLTHROUGH */
@@ -911,30 +911,24 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
911911
break;
912912
casejpiAnd:
913913
casejpiOr:
914-
casejpiAdd:
915-
casejpiSub:
916-
casejpiMul:
917-
casejpiDiv:
918-
casejpiMod:
919914
casejpiEqual:
920915
casejpiNotEqual:
921916
casejpiLess:
922917
casejpiGreater:
923918
casejpiLessOrEqual:
924919
casejpiGreaterOrEqual:
920+
casejpiAdd:
921+
casejpiSub:
922+
casejpiMul:
923+
casejpiDiv:
924+
casejpiMod:
925925
casejpiStartsWith:
926926
read_int32(v->content.args.left,base,pos);
927927
read_int32(v->content.args.right,base,pos);
928928
break;
929-
casejpiLikeRegex:
930-
read_int32(v->content.like_regex.flags,base,pos);
931-
read_int32(v->content.like_regex.expr,base,pos);
932-
read_int32(v->content.like_regex.patternlen,base,pos);
933-
v->content.like_regex.pattern=base+pos;
934-
break;
935929
casejpiNot:
936-
casejpiExists:
937930
casejpiIsUnknown:
931+
casejpiExists:
938932
casejpiPlus:
939933
casejpiMinus:
940934
casejpiFilter:
@@ -950,6 +944,12 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
950944
read_int32(v->content.anybounds.first,base,pos);
951945
read_int32(v->content.anybounds.last,base,pos);
952946
break;
947+
casejpiLikeRegex:
948+
read_int32(v->content.like_regex.flags,base,pos);
949+
read_int32(v->content.like_regex.expr,base,pos);
950+
read_int32(v->content.like_regex.patternlen,base,pos);
951+
v->content.like_regex.pattern=base+pos;
952+
break;
953953
default:
954954
elog(ERROR,"unrecognized jsonpath item type: %d",v->type);
955955
}
@@ -958,12 +958,12 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
958958
void
959959
jspGetArg(JsonPathItem*v,JsonPathItem*a)
960960
{
961-
Assert(v->type==jpiFilter||
962-
v->type==jpiNot||
961+
Assert(v->type==jpiNot||
963962
v->type==jpiIsUnknown||
964-
v->type==jpiExists||
965963
v->type==jpiPlus||
966964
v->type==jpiMinus||
965+
v->type==jpiFilter||
966+
v->type==jpiExists||
967967
v->type==jpiDatetime);
968968

969969
jspInitByBuffer(a,v->base,v->content.arg);
@@ -974,38 +974,37 @@ jspGetNext(JsonPathItem *v, JsonPathItem *a)
974974
{
975975
if (jspHasNext(v))
976976
{
977-
Assert(v->type==jpiString||
977+
Assert(v->type==jpiNull||
978+
v->type==jpiString||
978979
v->type==jpiNumeric||
979980
v->type==jpiBool||
980-
v->type==jpiNull||
981-
v->type==jpiKey||
982-
v->type==jpiAny||
983-
v->type==jpiAnyArray||
984-
v->type==jpiAnyKey||
985-
v->type==jpiIndexArray||
986-
v->type==jpiFilter||
987-
v->type==jpiCurrent||
988-
v->type==jpiExists||
989-
v->type==jpiRoot||
990-
v->type==jpiVariable||
991-
v->type==jpiLast||
981+
v->type==jpiAnd||
982+
v->type==jpiOr||
983+
v->type==jpiNot||
984+
v->type==jpiIsUnknown||
985+
v->type==jpiEqual||
986+
v->type==jpiNotEqual||
987+
v->type==jpiLess||
988+
v->type==jpiGreater||
989+
v->type==jpiLessOrEqual||
990+
v->type==jpiGreaterOrEqual||
992991
v->type==jpiAdd||
993992
v->type==jpiSub||
994993
v->type==jpiMul||
995994
v->type==jpiDiv||
996995
v->type==jpiMod||
997996
v->type==jpiPlus||
998997
v->type==jpiMinus||
999-
v->type==jpiEqual||
1000-
v->type==jpiNotEqual||
1001-
v->type==jpiGreater||
1002-
v->type==jpiGreaterOrEqual||
1003-
v->type==jpiLess||
1004-
v->type==jpiLessOrEqual||
1005-
v->type==jpiAnd||
1006-
v->type==jpiOr||
1007-
v->type==jpiNot||
1008-
v->type==jpiIsUnknown||
998+
v->type==jpiAnyArray||
999+
v->type==jpiAnyKey||
1000+
v->type==jpiIndexArray||
1001+
v->type==jpiAny||
1002+
v->type==jpiKey||
1003+
v->type==jpiCurrent||
1004+
v->type==jpiRoot||
1005+
v->type==jpiVariable||
1006+
v->type==jpiFilter||
1007+
v->type==jpiExists||
10091008
v->type==jpiType||
10101009
v->type==jpiSize||
10111010
v->type==jpiAbs||
@@ -1014,6 +1013,7 @@ jspGetNext(JsonPathItem *v, JsonPathItem *a)
10141013
v->type==jpiDouble||
10151014
v->type==jpiDatetime||
10161015
v->type==jpiKeyValue||
1016+
v->type==jpiLast||
10171017
v->type==jpiStartsWith||
10181018
v->type==jpiLikeRegex);
10191019

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp