MCPcopy Create free account
hub / github.com/documentdb/documentdb / BsonValueHoldsNumberArray

Function BsonValueHoldsNumberArray

pg_documentdb_core/src/io/pgbson_utils.c:66–92  ·  view source on GitHub ↗

* Checks if the bson value is of type array and all the elements are numbers. */

Source from the content-addressed store, hash-verified

64 * Checks if the bson value is of type array and all the elements are numbers.
65 */
66bool
67BsonValueHoldsNumberArray(const bson_value_t *currentValue, int32_t *numElements)
68{
69 if (currentValue->value_type != BSON_TYPE_ARRAY)
70 {
71 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
72 errmsg(
73 "Invalid type: expected an array type field, but received %s instead",
74 BsonTypeName(currentValue->value_type))));
75 }
76 bson_iter_t arrayIter;
77 BsonValueInitIterator(currentValue, &arrayIter);
78
79 *numElements = 0;
80 bool is_number_array = true;
81 while (bson_iter_next(&arrayIter))
82 {
83 if (!BSON_ITER_HOLDS_NUMBER(&arrayIter))
84 {
85 is_number_array = false;
86 break;
87 }
88 *numElements = *numElements + 1;
89 }
90
91 return is_number_array;
92}
93
94
95List *

Calls 2

BsonTypeNameFunction · 0.85
BsonValueInitIteratorFunction · 0.85

Tested by

no test coverage detected