MCPcopy Create free account
hub / github.com/apache/cloudberry / array_send

Function array_send

src/backend/utils/adt/arrayfuncs.c:1561–1659  ·  view source on GitHub ↗

* array_send : * takes the internal representation of an array and returns a bytea * containing the array in its external binary format. */

Source from the content-addressed store, hash-verified

1559 * containing the array in its external binary format.
1560 */
1561Datum
1562array_send(PG_FUNCTION_ARGS)
1563{
1564 AnyArrayType *v = PG_GETARG_ANY_ARRAY_P(0);
1565 Oid element_type = AARR_ELEMTYPE(v);
1566 int typlen;
1567 bool typbyval;
1568 char typalign;
1569 int nitems,
1570 i;
1571 int ndim,
1572 *dim,
1573 *lb;
1574 StringInfoData buf;
1575 array_iter iter;
1576 ArrayMetaState *my_extra;
1577
1578 /*
1579 * We arrange to look up info about element type, including its send
1580 * conversion proc, only once per series of calls, assuming the element
1581 * type doesn't change underneath us.
1582 */
1583 my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
1584 if (my_extra == NULL)
1585 {
1586 fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
1587 sizeof(ArrayMetaState));
1588 my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
1589 my_extra->element_type = ~element_type;
1590 }
1591
1592 if (my_extra->element_type != element_type)
1593 {
1594 /* Get info about element type, including its send proc */
1595 get_type_io_data(element_type, IOFunc_send,
1596 &my_extra->typlen, &my_extra->typbyval,
1597 &my_extra->typalign, &my_extra->typdelim,
1598 &my_extra->typioparam, &my_extra->typiofunc);
1599 if (!OidIsValid(my_extra->typiofunc))
1600 ereport(ERROR,
1601 (errcode(ERRCODE_UNDEFINED_FUNCTION),
1602 errmsg("no binary output function available for type %s",
1603 format_type_be(element_type))));
1604 fmgr_info_cxt(my_extra->typiofunc, &my_extra->proc,
1605 fcinfo->flinfo->fn_mcxt);
1606 my_extra->element_type = element_type;
1607 }
1608 typlen = my_extra->typlen;
1609 typbyval = my_extra->typbyval;
1610 typalign = my_extra->typalign;
1611
1612 ndim = AARR_NDIM(v);
1613 dim = AARR_DIMS(v);
1614 lb = AARR_LBOUND(v);
1615 nitems = ArrayGetNItems(ndim, dim);
1616
1617 pq_begintypsend(&buf);
1618

Callers 4

oidvectorsendFunction · 0.85
int2vectorsendFunction · 0.85
anyarray_sendFunction · 0.85
anycompatiblearray_sendFunction · 0.85

Calls 15

MemoryContextAllocFunction · 0.85
get_type_io_dataFunction · 0.85
format_type_beFunction · 0.85
fmgr_info_cxtFunction · 0.85
ArrayGetNItemsFunction · 0.85
pq_begintypsendFunction · 0.85
pq_sendint32Function · 0.85
array_iter_setupFunction · 0.85
array_iter_nextFunction · 0.85
SendFunctionCallFunction · 0.85
pq_sendbytesFunction · 0.85
pq_endtypsendFunction · 0.85

Tested by

no test coverage detected