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

Function array_agg_serialize

src/backend/utils/adt/array_userfuncs.c:655–743  ·  view source on GitHub ↗

* array_agg_serialize * Serialize ArrayBuildState into bytea. */

Source from the content-addressed store, hash-verified

653 * Serialize ArrayBuildState into bytea.
654 */
655Datum
656array_agg_serialize(PG_FUNCTION_ARGS)
657{
658 ArrayBuildState *state;
659 StringInfoData buf;
660 bytea *result;
661
662 /* cannot be called directly because of internal-type argument */
663 Assert(AggCheckCallContext(fcinfo, NULL));
664
665 state = (ArrayBuildState *) PG_GETARG_POINTER(0);
666
667 pq_begintypsend(&buf);
668
669 /*
670 * element_type. Putting this first is more convenient in deserialization
671 */
672 pq_sendint(&buf, state->element_type, sizeof(Oid));
673
674 /*
675 * nelems -- send first so we know how large to make the dvalues and
676 * dnulls array during deserialization.
677 */
678 pq_sendint64(&buf, state->nelems);
679
680 /* alen can be decided during deserialization */
681
682 /* typlen */
683 pq_sendint(&buf, state->typlen, sizeof(int16));
684
685 /* typbyval */
686 pq_sendbyte(&buf, state->typbyval);
687
688 /* typalign */
689 pq_sendbyte(&buf, state->typalign);
690
691 /* dnulls */
692 pq_sendbytes(&buf, (char *) state->dnulls, sizeof(bool) * state->nelems);
693
694 /*
695 * dvalues. By agreement with array_agg_deserialize, when the element
696 * type is byval, we just transmit the Datum array as-is, including any
697 * null elements. For by-ref types, we must invoke the element type's
698 * send function, and we skip null elements (which is why the nulls flags
699 * must be sent first).
700 */
701 if (state->typbyval)
702 pq_sendbytes(&buf, (char *) state->dvalues,
703 sizeof(Datum) * state->nelems);
704 else
705 {
706 SerialIOData *iodata;
707 int i;
708
709 /* Avoid repeat catalog lookups for typsend function */
710 iodata = (SerialIOData *) fcinfo->flinfo->fn_extra;
711 if (iodata == NULL)
712 {

Callers

nothing calls this directly

Calls 11

AggCheckCallContextFunction · 0.85
pq_begintypsendFunction · 0.85
pq_sendint64Function · 0.85
pq_sendbyteFunction · 0.85
pq_sendbytesFunction · 0.85
MemoryContextAllocFunction · 0.85
getTypeBinaryOutputInfoFunction · 0.85
fmgr_info_cxtFunction · 0.85
SendFunctionCallFunction · 0.85
pq_endtypsendFunction · 0.85
pq_sendintFunction · 0.50

Tested by

no test coverage detected