* Truncate an entry that is present in an object or array. * For types that don't support truncation mark the outer entry as definitely * not truncated. */
| 1383 | * not truncated. |
| 1384 | */ |
| 1385 | static bool |
| 1386 | TruncateNestedEntry(pgbson_element_writer *elementWriter, const |
| 1387 | bson_value_t *currentValue, |
| 1388 | bool *forceAsNotTruncated, int32_t sizeBudgetForElementWriter, int32_t |
| 1389 | currentLength) |
| 1390 | { |
| 1391 | switch (currentValue->value_type) |
| 1392 | { |
| 1393 | /* Fixed size values - just write it out */ |
| 1394 | case BSON_TYPE_MAXKEY: |
| 1395 | case BSON_TYPE_MINKEY: |
| 1396 | case BSON_TYPE_BOOL: |
| 1397 | case BSON_TYPE_DATE_TIME: |
| 1398 | case BSON_TYPE_NULL: |
| 1399 | case BSON_TYPE_OID: |
| 1400 | case BSON_TYPE_TIMESTAMP: |
| 1401 | case BSON_TYPE_UNDEFINED: |
| 1402 | { |
| 1403 | /* Primitive values aren't truncated */ |
| 1404 | PgbsonElementWriterWriteValue(elementWriter, currentValue); |
| 1405 | return false; |
| 1406 | } |
| 1407 | |
| 1408 | case BSON_TYPE_DECIMAL128: |
| 1409 | case BSON_TYPE_DOUBLE: |
| 1410 | case BSON_TYPE_INT32: |
| 1411 | case BSON_TYPE_INT64: |
| 1412 | { |
| 1413 | /* These are variable length but can be compared together |
| 1414 | * To ensure we have proper comparison in the middle of an array, |
| 1415 | * Convert them to a unified type. This is needed to handle |
| 1416 | * terms that come after the number. |
| 1417 | * e.g. if you had an array |
| 1418 | * [ Int32(1), "123456789012345" ] |
| 1419 | * and |
| 1420 | * [ Decimal128(1), "123456789012345" ] |
| 1421 | * |
| 1422 | * These 2 arrays are and should be able to be read via a query of |
| 1423 | * $eq: [ Double(1), "1234567890123456789" ] |
| 1424 | * |
| 1425 | * If the truncation limit was say 18 bytes we would get |
| 1426 | * (ignoring structural overhead): |
| 1427 | * [ Int32(1), "123456789012345"] (not truncated) |
| 1428 | * [ Decimal128(1), "12" ] (truncated) |
| 1429 | * which can produce incorrect results. |
| 1430 | * |
| 1431 | * So we convert all numerics to a common value. |
| 1432 | */ |
| 1433 | bson_value_t numericValue = *currentValue; |
| 1434 | bool checkFixedInteger = true; |
| 1435 | if (IsBsonValue32BitInteger(currentValue, checkFixedInteger)) |
| 1436 | { |
| 1437 | numericValue.value.v_int32 = BsonValueAsInt32(currentValue); |
| 1438 | numericValue.value_type = BSON_TYPE_INT32; |
| 1439 | } |
| 1440 | else if (IsBsonValue64BitInteger(currentValue, checkFixedInteger)) |
| 1441 | { |
| 1442 | numericValue.value.v_int64 = BsonValueAsInt64(currentValue); |
no test coverage detected