* command_coll_stats is the implementation of the internal logic for * dbcommand/collStats. */
| 104 | * dbcommand/collStats. |
| 105 | */ |
| 106 | Datum |
| 107 | command_coll_stats(PG_FUNCTION_ARGS) |
| 108 | { |
| 109 | if (PG_ARGISNULL(0)) |
| 110 | { |
| 111 | ereport(ERROR, (errmsg("Database name must not be NULL"))); |
| 112 | } |
| 113 | Datum databaseName = PG_GETARG_DATUM(0); |
| 114 | |
| 115 | if (PG_ARGISNULL(1)) |
| 116 | { |
| 117 | ereport(ERROR, (errmsg("collection name cannot be NULL"))); |
| 118 | } |
| 119 | Datum collectionName = PG_GETARG_DATUM(1); |
| 120 | |
| 121 | if (PG_ARGISNULL(2)) |
| 122 | { |
| 123 | /* Scale is optional in the collStats command but here |
| 124 | * the sql method must provide scale to this C func */ |
| 125 | ereport(ERROR, (errmsg("scale cannot be NULL"))); |
| 126 | } |
| 127 | double scaleDouble = PG_GETARG_FLOAT8(2); |
| 128 | |
| 129 | ReportFeatureUsage(FEATURE_COMMAND_COLLSTATS); |
| 130 | |
| 131 | /* Truncate the fractional part of the scale */ |
| 132 | scaleDouble = trunc(scaleDouble); |
| 133 | |
| 134 | /* The 'scale' value is capped to int32 for compatibility with expected behavior */ |
| 135 | int32 scale = scaleDouble > INT32_MAX ? INT32_MAX : |
| 136 | scaleDouble < INT32_MIN ? INT32_MIN : |
| 137 | (int32) scaleDouble; |
| 138 | |
| 139 | pgbson *response = CollStatsCoordinator(databaseName, collectionName, scale); |
| 140 | PG_RETURN_POINTER(response); |
| 141 | } |
| 142 | |
| 143 | |
| 144 | /* |
nothing calls this directly
no test coverage detected