* Compares two bson values. * Please DO NOT expose this method beyond this file. * CODESYNC: This needs to match the behavior of HashBsonValueCompare in bson_hash.c */
| 1035 | * CODESYNC: This needs to match the behavior of HashBsonValueCompare in bson_hash.c |
| 1036 | */ |
| 1037 | static int |
| 1038 | CompareBsonValue(const bson_value_t *left, const bson_value_t *right, |
| 1039 | bool *isComparisonValid, const char *collationString) |
| 1040 | { |
| 1041 | *isComparisonValid = true; |
| 1042 | if (CompareBsonSortOrderType(left, right) != 0) |
| 1043 | { |
| 1044 | ereport(ERROR, errmsg("left & right sort data types must match")); |
| 1045 | } |
| 1046 | |
| 1047 | /* same type, same path. now compare value. */ |
| 1048 | switch (left->value_type) |
| 1049 | { |
| 1050 | case BSON_TYPE_EOD: |
| 1051 | case BSON_TYPE_MINKEY: |
| 1052 | case BSON_TYPE_UNDEFINED: |
| 1053 | case BSON_TYPE_NULL: |
| 1054 | case BSON_TYPE_MAXKEY: |
| 1055 | { |
| 1056 | return 0; |
| 1057 | } |
| 1058 | |
| 1059 | case BSON_TYPE_DOUBLE: |
| 1060 | case BSON_TYPE_INT32: |
| 1061 | case BSON_TYPE_INT64: |
| 1062 | case BSON_TYPE_DECIMAL128: |
| 1063 | case BSON_TYPE_BOOL: |
| 1064 | { |
| 1065 | return CompareNumbers(left, right, isComparisonValid); |
| 1066 | } |
| 1067 | |
| 1068 | case BSON_TYPE_UTF8: |
| 1069 | { |
| 1070 | return CompareStrings( |
| 1071 | left->value.v_utf8.str, |
| 1072 | left->value.v_utf8.len, |
| 1073 | right->value.v_utf8.str, |
| 1074 | right->value.v_utf8.len, collationString); |
| 1075 | } |
| 1076 | |
| 1077 | case BSON_TYPE_SYMBOL: |
| 1078 | { |
| 1079 | return CompareStrings( |
| 1080 | left->value.v_symbol.symbol, |
| 1081 | left->value.v_symbol.len, |
| 1082 | right->value.v_symbol.symbol, |
| 1083 | right->value.v_symbol.len, collationString); |
| 1084 | } |
| 1085 | |
| 1086 | case BSON_TYPE_DOCUMENT: |
| 1087 | case BSON_TYPE_ARRAY: |
| 1088 | { |
| 1089 | bson_iter_t leftInnerIt, rightInnerIt; |
| 1090 | if (!bson_iter_init_from_data( |
| 1091 | &leftInnerIt, |
| 1092 | left->value.v_doc.data, |
| 1093 | left->value.v_doc.data_len)) |
| 1094 | { |
no test coverage detected