* Checks if the bson value is of type array and all the elements are numbers. */
| 64 | * Checks if the bson value is of type array and all the elements are numbers. |
| 65 | */ |
| 66 | bool |
| 67 | BsonValueHoldsNumberArray(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 | |
| 95 | List * |
no test coverage detected