30 #include "utils/array.h"
50 size_t *result_count) {
53 size_t size_via_vidsArr = 0;
57 size_t total_edges = 0;
60 if (total_edges == 0) {
61 if (via_vidsArr) pfree(via_vidsArr);
67 clock_t start_t = clock();
69 char* notice_msg = NULL;
73 via_vidsArr, size_via_vidsArr,
82 time_msg(
"processing pgr_dijkstraVia", start_t, clock());
84 if (err_msg && (*result_tuples)) {
85 pfree(*result_tuples);
86 (*result_tuples) = NULL;
92 if (log_msg) pfree(log_msg);
93 if (notice_msg) pfree(notice_msg);
94 if (err_msg) pfree(err_msg);
95 if (edges) pfree(edges);
96 if (via_vidsArr) pfree(via_vidsArr);
103 FuncCallContext *funcctx;
104 TupleDesc tuple_desc;
108 size_t result_count = 0;
111 if (SRF_IS_FIRSTCALL()) {
112 MemoryContext oldcontext;
113 funcctx = SRF_FIRSTCALL_INIT();
114 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
126 text_to_cstring(PG_GETARG_TEXT_P(0)),
127 PG_GETARG_ARRAYTYPE_P(1),
136 #if PGSQL_VERSION > 95
137 funcctx->max_calls = result_count;
139 funcctx->max_calls = (uint32_t)result_count;
141 funcctx->user_fctx = result_tuples;
142 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
143 != TYPEFUNC_COMPOSITE)
145 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
146 errmsg(
"function returning record called in context "
147 "that cannot accept type record")));
149 funcctx->tuple_desc = tuple_desc;
150 MemoryContextSwitchTo(oldcontext);
153 funcctx = SRF_PERCALL_SETUP();
154 tuple_desc = funcctx->tuple_desc;
155 result_tuples = (
Routes_t*) funcctx->user_fctx;
157 if (funcctx->call_cntr < funcctx->max_calls) {
162 size_t call_cntr = funcctx->call_cntr;
178 size_t numb_out = 10;
179 values = palloc(numb_out *
sizeof(Datum));
180 nulls = palloc(numb_out *
sizeof(
bool));
182 for (i = 0; i< numb_out; ++i) {
187 values[0] = Int32GetDatum(call_cntr + 1);
188 values[1] = Int32GetDatum(result_tuples[call_cntr].path_id);
189 values[2] = Int32GetDatum(result_tuples[call_cntr].path_seq + 1);
190 values[3] = Int64GetDatum(result_tuples[call_cntr].start_vid);
191 values[4] = Int64GetDatum(result_tuples[call_cntr].end_vid);
192 values[5] = Int64GetDatum(result_tuples[call_cntr].node);
193 values[6] = Int64GetDatum(result_tuples[call_cntr].
edge);
194 values[7] = Float8GetDatum(result_tuples[call_cntr].cost);
195 values[8] = Float8GetDatum(result_tuples[call_cntr].agg_cost);
196 values[9] = Float8GetDatum(result_tuples[call_cntr].route_agg_cost);
200 tuple = heap_form_tuple(tuple_desc, values, nulls);
201 result = HeapTupleGetDatum(tuple);
202 SRF_RETURN_NEXT(funcctx, result);
204 SRF_RETURN_DONE(funcctx);