Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1b55c15

Browse files
author
Nikita Glukhov
committed
Simplify jsonPathStatsGetTypeFreq()
1 parent 908128f commit 1b55c15

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/backend/utils/adt/jsonb_selfuncs.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -756,18 +756,29 @@ jsonPathStatsGetTypeFreq(JsonPathStats pstats, JsonbValueType type,
756756
* When dealing with (object/array) length stats, we only really care about
757757
* objects and arrays.
758758
*/
759-
if (pstats->type == JsonPathStatsLength ||
760-
pstats->type == JsonPathStatsArrayLength)
759+
if (pstats->type == JsonPathStatsLength)
761760
{
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+
*/
763765
if (type != jbvNumeric)
764766
return 0.0;
765767

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);
771782
}
772783

773784
/* Which JSON type are we interested in? Pick the right freq_type key. */

0 commit comments

Comments
 (0)