33 #include "utils/array.h"
34 #include "catalog/pg_type.h"
35 #include "utils/lsyscache.h"
38 #define INT8ARRAYOID 1016
58 size_t *result_count) {
61 size_t total_edges = 0;
64 if (total_edges == 0) {
70 clock_t start_t = clock();
72 char* notice_msg = NULL;
77 result_tuples, result_count,
82 time_msg(
"processing pgr_transitiveClosure()", start_t, clock());
85 if (err_msg && (*result_tuples)) {
86 pfree(*result_tuples);
87 (*result_tuples) = NULL;
93 if (log_msg) pfree(log_msg);
94 if (notice_msg) pfree(notice_msg);
95 if (err_msg) pfree(err_msg);
96 if (edges) pfree(edges);
102 FuncCallContext *funcctx;
103 TupleDesc tuple_desc;
107 size_t result_count = 0;
110 if (SRF_IS_FIRSTCALL()) {
111 MemoryContext oldcontext;
112 funcctx = SRF_FIRSTCALL_INIT();
113 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
121 text_to_cstring(PG_GETARG_TEXT_P(0)),
127 #if PGSQL_VERSION > 95
128 funcctx->max_calls = result_count;
130 funcctx->max_calls = (uint32_t)result_count;
132 funcctx->user_fctx = result_tuples;
133 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
134 != TYPEFUNC_COMPOSITE)
136 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
137 errmsg(
"function returning record called in context "
138 "that cannot accept type record")));
139 funcctx->tuple_desc = tuple_desc;
140 MemoryContextSwitchTo(oldcontext);
143 funcctx = SRF_PERCALL_SETUP();
144 tuple_desc = funcctx->tuple_desc;
147 if (funcctx->call_cntr < funcctx->max_calls) {
153 size_t call_cntr = funcctx->call_cntr;
157 values =(Datum *)palloc(numb *
sizeof(Datum));
158 nulls = palloc(numb *
sizeof(
bool));
160 for (i = 0; i < numb; ++i) {
164 size_t target_array_size =
165 (size_t)result_tuples[call_cntr].target_array_size;
167 Datum* target_array_array;
168 target_array_array = (Datum*) palloc(
sizeof(Datum) *
169 (size_t)target_array_size);
171 for (i = 0; i < target_array_size; ++i) {
172 PGR_DBG(
"Storing target_array vertex %ld",
173 result_tuples[call_cntr].target_array[i]);
174 target_array_array[i] =
175 Int64GetDatum(result_tuples[call_cntr].target_array[i]);
180 get_typlenbyvalalign(INT8OID, &typlen, &typbyval, &typalign);
181 ArrayType* arrayType;
191 arrayType = construct_array(
193 (
int)target_array_size,
194 INT8OID, typlen, typbyval, typalign);
205 TupleDescInitEntry(tuple_desc, (AttrNumber) 3,
"target_array",
208 values[0] = Int32GetDatum(call_cntr + 1);
209 values[1] = Int64GetDatum(result_tuples[call_cntr].vid);
210 values[2] = PointerGetDatum(arrayType);
213 tuple = heap_form_tuple(tuple_desc, values, nulls);
214 result = HeapTupleGetDatum(tuple);
222 SRF_RETURN_NEXT(funcctx, result);
224 SRF_RETURN_DONE(funcctx);