PGROUTING  3.2
lineGraphFull.c File Reference
Include dependency graph for lineGraphFull.c:

Go to the source code of this file.

Functions

PGDLLEXPORT Datum _pgr_linegraphfull (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (_pgr_linegraphfull)
 
static void process (char *edges_sql, Line_graph_full_rt **result_tuples, size_t *result_count)
 

Function Documentation

◆ _pgr_linegraphfull()

PGDLLEXPORT Datum _pgr_linegraphfull ( PG_FUNCTION_ARGS  )

Definition at line 101 of file lineGraphFull.c.

101  {
102  FuncCallContext *funcctx;
103  TupleDesc tuple_desc;
104 
105  Line_graph_full_rt *result_tuples = NULL;
106  size_t result_count = 0;
107 
108  if (SRF_IS_FIRSTCALL()) {
109  MemoryContext oldcontext;
110  funcctx = SRF_FIRSTCALL_INIT();
111  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
112 
113  PGR_DBG("Calling process");
114  process(text_to_cstring(PG_GETARG_TEXT_P(0)),
115  &result_tuples,
116  &result_count);
117 
118 #if PGSQL_VERSION > 95
119  funcctx->max_calls = result_count;
120 #else
121  funcctx->max_calls = (uint32_t)result_count;
122 #endif
123  funcctx->user_fctx = result_tuples;
124  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
125  != TYPEFUNC_COMPOSITE) {
126  ereport(ERROR,
127  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
128  errmsg("function returning record called in context "
129  "that cannot accept type record")));
130  }
131 
132  funcctx->tuple_desc = tuple_desc;
133  MemoryContextSwitchTo(oldcontext);
134  }
135 
136  funcctx = SRF_PERCALL_SETUP();
137  tuple_desc = funcctx->tuple_desc;
138  result_tuples = (Line_graph_full_rt*) funcctx->user_fctx;
139 
140  if (funcctx->call_cntr < funcctx->max_calls) {
141  HeapTuple tuple;
142  Datum result;
143  Datum *values;
144  bool* nulls;
145 
146  values = palloc(5 * sizeof(Datum));
147  nulls = palloc(5 * sizeof(bool));
148 
149 
150  size_t i;
151  for (i = 0; i < 5; ++i) {
152  nulls[i] = false;
153  }
154 
155  size_t c_cntr = funcctx->call_cntr;
156 
157  values[0] = Int32GetDatum(c_cntr + 1);
158  values[1] = Int64GetDatum(result_tuples[c_cntr].source);
159  values[2] = Int64GetDatum(result_tuples[c_cntr].target);
160  values[3] = Float8GetDatum(result_tuples[c_cntr].cost);
161  values[4] = Int64GetDatum(result_tuples[c_cntr].edge);
162 
163  tuple = heap_form_tuple(tuple_desc, values, nulls);
164  result = HeapTupleGetDatum(tuple);
165  SRF_RETURN_NEXT(funcctx, result);
166  } else {
167  PGR_DBG("Clean up code");
168  SRF_RETURN_DONE(funcctx);
169  }
170 }

References if(), PGR_DBG, and process().

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( _pgr_linegraphfull  )

◆ process()

static void process ( char *  edges_sql,
Line_graph_full_rt **  result_tuples,
size_t *  result_count 
)
static

Definition at line 44 of file lineGraphFull.c.

47  {
48  PGR_DBG("\nSQL QUERY: %s\n", edges_sql);
49  PGR_DBG("\nDirectedGraph\n");
51 
52  (*result_tuples) = NULL;
53  (*result_count) = 0;
54 
55  PGR_DBG("Load data");
56  pgr_edge_t *edges = NULL;
57  size_t total_edges = 0;
58 
59  pgr_get_edges(edges_sql, &edges, &total_edges);
60  PGR_DBG("Total %ld edges in query:", total_edges);
61 
62  if (total_edges == 0) {
63  PGR_DBG("No edges found");
65  return;
66  }
67 
68  PGR_DBG("Starting processing");
69  clock_t start_t = clock();
70  char *log_msg = NULL;
71  char *notice_msg = NULL;
72  char *err_msg = NULL;
74  edges,
75  total_edges,
76  result_tuples,
77  result_count,
78  &log_msg,
79  &notice_msg,
80  &err_msg);
81 
82  time_msg(" processing pgr_lineGraphFull", start_t, clock());
83  PGR_DBG("Returning %ld tuples", *result_count);
84 
85  if (err_msg) {
86  if (*result_tuples) pfree(*result_tuples);
87  }
88 
89  pgr_global_report(log_msg, notice_msg, err_msg);
90 
91  if (edges) pfree(edges);
92  if (log_msg) pfree(log_msg);
93  if (notice_msg) pfree(notice_msg);
94  if (err_msg) pfree(err_msg);
95 
97 }

References do_pgr_lineGraphFull(), PGR_DBG, pgr_get_edges(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by _pgr_linegraphfull().

pgr_edge_t
Definition: pgr_edge_t.h:37
pgr_SPI_connect
void pgr_SPI_connect(void)
Definition: postgres_connection.c:82
pgr_SPI_finish
void pgr_SPI_finish(void)
Definition: postgres_connection.c:71
process
static void process(char *edges_sql, Line_graph_full_rt **result_tuples, size_t *result_count)
Definition: lineGraphFull.c:44
edge
Definition: trsp.h:41
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
pgr_get_edges
void pgr_get_edges(char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
basic edge_sql
Definition: edges_input.c:711
if
if(DOXYGEN_FOUND) configure_file($
Definition: doxygen/CMakeLists.txt:13
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
do_pgr_lineGraphFull
void do_pgr_lineGraphFull(pgr_edge_t *data_edges, size_t total_edges, Line_graph_full_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: lineGraphFull_driver.cpp:62
pgr_global_report
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93
Line_graph_full_rt
Definition: line_graph_full_rt.h:42