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

Go to the source code of this file.

Functions

PGDLLEXPORT Datum _pgr_withpointsdd (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (_pgr_withpointsdd)
 
static void process (char *edges_sql, char *points_sql, ArrayType *starts, double distance, bool directed, char *driving_side, bool details, bool equicost, General_path_element_t **result_tuples, size_t *result_count)
 

Function Documentation

◆ _pgr_withpointsdd()

PGDLLEXPORT Datum _pgr_withpointsdd ( PG_FUNCTION_ARGS  )

Definition at line 145 of file many_to_dist_withPointsDD.c.

145  {
146  FuncCallContext *funcctx;
147  TupleDesc tuple_desc;
148 
149  /**********************************************************************/
150  General_path_element_t *result_tuples = 0;
151  size_t result_count = 0;
152  /**********************************************************************/
153 
154 
155  if (SRF_IS_FIRSTCALL()) {
156  MemoryContext oldcontext;
157  funcctx = SRF_FIRSTCALL_INIT();
158  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
159 
160 
161  /**********************************************************************/
162  // CREATE OR REPLACE FUNCTION pgr_withPointsDD(
163  // edges_sql TEXT,
164  // points_sql TEXT,
165  // start_pids anyarray,
166  // distance FLOAT,
167  //
168  // directed BOOLEAN -- DEFAULT true,
169  // driving_side CHAR -- DEFAULT 'b',
170  // details BOOLEAN -- DEFAULT false,
171  // equicost BOOLEAN -- DEFAULT false,
172 
173 
174  PGR_DBG("Calling driving_many_to_dist_driver");
175  process(
176  text_to_cstring(PG_GETARG_TEXT_P(0)),
177  text_to_cstring(PG_GETARG_TEXT_P(1)),
178  PG_GETARG_ARRAYTYPE_P(2),
179  PG_GETARG_FLOAT8(3),
180 
181  PG_GETARG_BOOL(4),
182  text_to_cstring(PG_GETARG_TEXT_P(5)),
183  PG_GETARG_BOOL(6),
184  PG_GETARG_BOOL(7),
185  &result_tuples, &result_count);
186 
187  /**********************************************************************/
188 
189 #if PGSQL_VERSION > 95
190  funcctx->max_calls = result_count;
191 #else
192  funcctx->max_calls = (uint32_t)result_count;
193 #endif
194  funcctx->user_fctx = result_tuples;
195  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
196  != TYPEFUNC_COMPOSITE)
197  ereport(ERROR,
198  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
199  errmsg("function returning record called in context "
200  "that cannot accept type record")));
201 
202  funcctx->tuple_desc = tuple_desc;
203 
204  MemoryContextSwitchTo(oldcontext);
205  }
206 
207  funcctx = SRF_PERCALL_SETUP();
208 
209  tuple_desc = funcctx->tuple_desc;
210  result_tuples = (General_path_element_t*) funcctx->user_fctx;
211 
212  if (funcctx->call_cntr < funcctx->max_calls) {
213  HeapTuple tuple;
214  Datum result;
215  Datum *values;
216  bool* nulls;
217 
218  /**********************************************************************/
219  size_t numb = 6;
220  values = palloc(numb * sizeof(Datum));
221  nulls = palloc(numb * sizeof(bool));
222 
223  size_t i;
224  for (i = 0; i < numb; ++i) {
225  nulls[i] = false;
226  }
227 
228  values[0] = Int32GetDatum(funcctx->call_cntr + 1);
229  values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id);
230  values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].node);
231  values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge);
232  values[4] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost);
233  values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost);
234 
235  /**********************************************************************/
236 
237  tuple = heap_form_tuple(tuple_desc, values, nulls);
238  result = HeapTupleGetDatum(tuple);
239 
240  pfree(values);
241  pfree(nulls);
242 
243  SRF_RETURN_NEXT(funcctx, result);
244  } else {
245  SRF_RETURN_DONE(funcctx);
246  }
247 }

References General_path_element_t::agg_cost, General_path_element_t::cost, General_path_element_t::edge, if(), General_path_element_t::node, PGR_DBG, process(), and General_path_element_t::start_id.

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( _pgr_withpointsdd  )

◆ process()

static void process ( char *  edges_sql,
char *  points_sql,
ArrayType *  starts,
double  distance,
bool  directed,
char *  driving_side,
bool  details,
bool  equicost,
General_path_element_t **  result_tuples,
size_t *  result_count 
)
static

Definition at line 45 of file many_to_dist_withPointsDD.c.

57  {
58  driving_side[0] = estimate_drivingSide(driving_side[0]);
59  PGR_DBG("estimated driving side:%c", driving_side[0]);
60 
62 
63  size_t total_starts = 0;
64  int64_t* start_pidsArr = pgr_get_bigIntArray(&total_starts, starts);
65  PGR_DBG("sourcesArr size %ld ", total_starts);
66 
67  Point_on_edge_t *points = NULL;
68  size_t total_points = 0;
69  pgr_get_points(points_sql, &points, &total_points);
70 
71  char *edges_of_points_query = NULL;
72  char *edges_no_points_query = NULL;
74  edges_sql, points_sql,
75  &edges_of_points_query,
76  &edges_no_points_query);
77 
78 
79  pgr_edge_t *edges_of_points = NULL;
80  size_t total_edges_of_points = 0;
82  edges_of_points_query, &edges_of_points, &total_edges_of_points);
83 
84  pgr_edge_t *edges = NULL;
85  size_t total_edges = 0;
86  pgr_get_edges(edges_no_points_query, &edges, &total_edges);
87 
88  PGR_DBG("freeing allocated memory not used anymore");
89  pfree(edges_of_points_query);
90  pfree(edges_no_points_query);
91 
92  if ((total_edges + total_edges_of_points) == 0) {
93  if (edges) pfree(edges);
94  if (edges_of_points) pfree(edges_of_points);
95  if (points) pfree(points);
97  return;
98  }
99 
100  PGR_DBG("Starting timer");
101  clock_t start_t = clock();
102  char* log_msg = NULL;
103  char* notice_msg = NULL;
104  char* err_msg = NULL;
106  edges, total_edges,
107  points, total_points,
108  edges_of_points, total_edges_of_points,
109  start_pidsArr, total_starts,
110  distance,
111 
112  directed,
113  driving_side[0],
114  details,
115  equicost,
116 
117  result_tuples,
118  result_count,
119  &log_msg,
120  &notice_msg,
121  &err_msg);
122  time_msg(" processing withPointsDD many starts", start_t, clock());
123 
124  if (err_msg && (*result_tuples)) {
125  pfree(*result_tuples);
126  (*result_count) = 0;
127  (*result_tuples) = NULL;
128  }
129 
130  pgr_global_report(log_msg, notice_msg, err_msg);
131 
132  if (log_msg) pfree(log_msg);
133  if (notice_msg) pfree(notice_msg);
134  if (err_msg) pfree(err_msg);
135  if (edges) pfree(edges);
136  if (edges_of_points) pfree(edges_of_points);
137  if (points) pfree(points);
138  if (start_pidsArr) pfree(start_pidsArr);
139  pgr_SPI_finish();
140 }

References do_pgr_many_withPointsDD(), estimate_drivingSide(), get_new_queries(), PGR_DBG, pgr_get_bigIntArray(), pgr_get_edges(), pgr_get_points(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by _pgr_withpointsdd().

estimate_drivingSide
char estimate_drivingSide(char driving_side)
Definition: get_new_queries.cpp:36
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
do_pgr_many_withPointsDD
void do_pgr_many_withPointsDD(pgr_edge_t *edges, size_t total_edges, Point_on_edge_t *points_p, size_t total_points, pgr_edge_t *edges_of_points, size_t total_edges_of_points, int64_t *start_pidsArr, size_t s_len, double distance, bool directed, char driving_side, bool details, bool equiCost, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: withPoints_dd_driver.cpp:59
pgr_get_points
void pgr_get_points(char *points_sql, Point_on_edge_t **points, size_t *total_points)
pgr_get_points
Definition: points_input.c:69
pgr_get_bigIntArray
int64_t * pgr_get_bigIntArray(size_t *arrlen, ArrayType *input)
Enforces the input array to be NOT empty.
Definition: arrays_input.c:146
get_new_queries
void get_new_queries(char *edges_sql, char *points_sql, char **edges_of_points_query, char **edges_no_points_query)
Definition: get_new_queries.cpp:46
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
Point_on_edge_t
Definition: point_on_edge_t.h:37
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
General_path_element_t
Definition: general_path_element_t.h:37
if
if(DOXYGEN_FOUND) configure_file($
Definition: doxygen/CMakeLists.txt:13
process
static void process(char *edges_sql, char *points_sql, ArrayType *starts, double distance, bool directed, char *driving_side, bool details, bool equicost, General_path_element_t **result_tuples, size_t *result_count)
Definition: many_to_dist_withPointsDD.c:45
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
pgr_global_report
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93