@@ -756,18 +756,29 @@ jsonPathStatsGetTypeFreq(JsonPathStats pstats, JsonbValueType type,
756
756
* When dealing with (object/array) length stats, we only really care about
757
757
* objects and arrays.
758
758
*/
759
- if (pstats -> type == JsonPathStatsLength ||
760
- pstats -> type == JsonPathStatsArrayLength )
759
+ if (pstats -> type == JsonPathStatsLength )
761
760
{
762
- /* XXX Seems more like an error, no? Why ignore it? */
761
+ /*
762
+ * Array/object length is always numeric, so simply return 0 if
763
+ * requested non-numeric frequency.
764
+ */
763
765
if (type != jbvNumeric )
764
766
return 0.0 ;
765
767
766
- /* FIXME This is really hard to read/understand, with two nested ternary operators. */
767
- return pstats -> type == JsonPathStatsArrayLength
768
- ? jsonPathStatsGetFreq (pstats , defaultfreq )
769
- : jsonPathStatsGetFloat (pstats , "freq_array" , defaultfreq ) +
770
- jsonPathStatsGetFloat (pstats , "freq_object" , defaultfreq );
768
+ return jsonPathStatsGetFloat (pstats , "freq_array" , defaultfreq ) +
769
+ jsonPathStatsGetFloat (pstats , "freq_object" , defaultfreq );
770
+ }
771
+
772
+ if (pstats -> type == JsonPathStatsArrayLength )
773
+ {
774
+ /*
775
+ * Array length is always numeric, so simply return 0 if requested
776
+ * non-numeric frequency.
777
+ */
778
+ if (type != jbvNumeric )
779
+ return 0.0 ;
780
+
781
+ return jsonPathStatsGetFreq (pstats , defaultfreq );
771
782
}
772
783
773
784
/* Which JSON type are we interested in? Pick the right freq_type key. */
0 commit comments