* bsonaggvalue_in: Parse text input to BsonAggValue. * Accepts both hex (BSONHEX...) and extended JSON formats, wrapped as {"": value} * with an optional "collation" field. */
| 2580 | * with an optional "collation" field. |
| 2581 | */ |
| 2582 | Datum |
| 2583 | bsonaggvalue_in(PG_FUNCTION_ARGS) |
| 2584 | { |
| 2585 | char *inputStr = PG_GETARG_CSTRING(0); |
| 2586 | |
| 2587 | if (inputStr == NULL) |
| 2588 | { |
| 2589 | PG_RETURN_NULL(); |
| 2590 | } |
| 2591 | |
| 2592 | pgbson *bson = NULL; |
| 2593 | if (IsBsonHexadecimalString(inputStr)) |
| 2594 | { |
| 2595 | bson = PgbsonInitFromHexadecimalString(inputStr); |
| 2596 | } |
| 2597 | else |
| 2598 | { |
| 2599 | bson = PgbsonInitFromJson(inputStr); |
| 2600 | } |
| 2601 | |
| 2602 | pgbsonelement element; |
| 2603 | const char *collationString = |
| 2604 | PgbsonToSinglePgbsonElementWithCollation(bson, &element); |
| 2605 | |
| 2606 | /* Allocate BsonAggValue and collation and deep-copy their values */ |
| 2607 | BsonAggValue *state = (BsonAggValue *) palloc0(sizeof(BsonAggValue)); |
| 2608 | SET_VARSIZE(state, sizeof(BsonAggValue)); |
| 2609 | bson_value_copy(&element.bsonValue, &state->value); |
| 2610 | state->collationString = collationString != NULL ? |
| 2611 | pstrdup(collationString) : NULL; |
| 2612 | |
| 2613 | PG_RETURN_POINTER(state); |
| 2614 | } |
| 2615 | |
| 2616 | |
| 2617 | /* |
nothing calls this directly
no test coverage detected