MCPcopy Create free account
hub / github.com/activeloopai/deeplake / parse_special_datum

Function parse_special_datum

cpp/deeplake_pg/utils.hpp:554–712  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

552}
553
554inline parsed_special_datum_result parse_special_datum(Datum d, Oid attr_typeid)
555{
556 parsed_special_datum_result result;
557
558 if (!can_make_special_datum(attr_typeid)) {
559 return result;
560 }
561
562 if (is_string_type(attr_typeid)) {
563 // For string types, parse the formatted string: "magic table_id row_id column_id"
564 text* txt = DatumGetTextP(d);
565 if (txt == nullptr) {
566 return result;
567 }
568
569 const char* data = VARDATA(txt);
570 size_t len = VARSIZE(txt) - VARHDRSZ;
571
572 result = parse_space_separated_values(data, len);
573
574 } else if (type_is_array(attr_typeid)) {
575 // For array types, check the first element for magic and parse accordingly
576 ArrayType* arr = DatumGetArrayTypeP(d);
577 if (arr == nullptr) {
578 return result;
579 }
580
581 int ndims = ARR_NDIM(arr);
582 if (ndims != 1) {
583 return result;
584 }
585
586 int* dims = ARR_DIMS(arr);
587 if (dims[0] < 4) {
588 return result;
589 }
590
591 switch (attr_typeid) {
592 case INT2ARRAYOID: {
593 if (dims[0] != 8)
594 return result;
595
596 int16* data = (int16*)ARR_DATA_PTR(arr);
597
598 // Reconstruct magic number from first two elements
599 int32_t magic = static_cast<int32_t>(data[0]) | (static_cast<int32_t>(data[1]) << 16);
600 if (magic != g_not_fetched_magic) {
601 return result;
602 }
603
604 // Reconstruct table_id and row_id from split parts
605 uint32_t table_id = static_cast<uint32_t>(data[2]) | (static_cast<uint32_t>(data[3]) << 16);
606 int64_t row_id = static_cast<int64_t>(data[4]) | (static_cast<int64_t>(data[5]) << 16) |
607 (static_cast<int64_t>(data[6]) << 32);
608
609 result.is_valid = true;
610 result.table_id = table_id;
611 result.row_id = row_id;

Callers 1

receive_slotFunction · 0.85

Calls 4

can_make_special_datumFunction · 0.85
is_string_typeFunction · 0.85
parse_bytea_elementFunction · 0.85

Tested by

no test coverage detected