* Validates if there are the fieldValue is of correct type required for $densify. * Null and EOD values are allowed. * Numbers are allowed only when the `unit` is not provided. * Dates are allowed only when the `unit` is provided. * Any other type is not allowed. */
| 694 | * Any other type is not allowed. |
| 695 | */ |
| 696 | static inline void |
| 697 | CheckFieldValue(const bson_value_t *fieldValue, DensifyWindowState *state) |
| 698 | { |
| 699 | if (fieldValue->value_type == BSON_TYPE_NULL || fieldValue->value_type == |
| 700 | BSON_TYPE_EOD) |
| 701 | { |
| 702 | return; |
| 703 | } |
| 704 | |
| 705 | bool isDateUnitPresent = state->arguments.timeUnit != DateUnit_Invalid; |
| 706 | |
| 707 | if (!BsonValueIsNumber(fieldValue) && fieldValue->value_type != BSON_TYPE_DATE_TIME) |
| 708 | { |
| 709 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5733201), |
| 710 | errmsg( |
| 711 | "Expected a numeric or date type for densify."))); |
| 712 | } |
| 713 | |
| 714 | if (isDateUnitPresent && BsonValueIsNumber(fieldValue)) |
| 715 | { |
| 716 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION6053600), |
| 717 | errmsg( |
| 718 | "Encountered numeric densify value in collection when step has a date unit."))); |
| 719 | } |
| 720 | |
| 721 | if (!isDateUnitPresent && fieldValue->value_type == BSON_TYPE_DATE_TIME) |
| 722 | { |
| 723 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION6053600), |
| 724 | errmsg( |
| 725 | "Encountered date densify value in collection when step does not have a date unit."))); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | |
| 730 | /* |
no test coverage detected