PGROUTING  2.6
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 many_withPointsDD (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (many_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

PGDLLEXPORT Datum many_withPointsDD ( PG_FUNCTION_ARGS  )

Definition at line 144 of file many_to_dist_withPointsDD.c.

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.

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

Here is the call graph for this function:

PG_FUNCTION_INFO_V1 ( many_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 
)
static

Definition at line 44 of file many_to_dist_withPointsDD.c.

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 many_withPointsDD().

56  {
57  driving_side[0] = estimate_drivingSide(driving_side[0]);
58  PGR_DBG("estimated driving side:%c", driving_side[0]);
59 
61 
62  size_t total_starts = 0;
63  int64_t* start_pidsArr = pgr_get_bigIntArray(&total_starts, starts);
64  PGR_DBG("sourcesArr size %ld ", total_starts);
65 
66  Point_on_edge_t *points = NULL;
67  size_t total_points = 0;
68  pgr_get_points(points_sql, &points, &total_points);
69 
70  char *edges_of_points_query = NULL;
71  char *edges_no_points_query = NULL;
73  edges_sql, points_sql,
74  &edges_of_points_query,
75  &edges_no_points_query);
76 
77 
78  pgr_edge_t *edges_of_points = NULL;
79  size_t total_edges_of_points = 0;
81  edges_of_points_query, &edges_of_points, &total_edges_of_points);
82 
83  pgr_edge_t *edges = NULL;
84  size_t total_edges = 0;
85  pgr_get_edges(edges_no_points_query, &edges, &total_edges);
86 
87  PGR_DBG("freeing allocated memory not used anymore");
88  pfree(edges_of_points_query);
89  pfree(edges_no_points_query);
90 
91  if ((total_edges + total_edges_of_points) == 0) {
92  if (edges) pfree(edges);
93  if (edges_of_points) pfree(edges_of_points);
94  if (points) pfree(points);
96  return;
97  }
98 
99  PGR_DBG("Starting timer");
100  clock_t start_t = clock();
101  char* log_msg = NULL;
102  char* notice_msg = NULL;
103  char* err_msg = NULL;
105  edges, total_edges,
106  points, total_points,
107  edges_of_points, total_edges_of_points,
108  start_pidsArr, total_starts,
109  distance,
110 
111  directed,
112  driving_side[0],
113  details,
114  equicost,
115 
116  result_tuples,
117  result_count,
118  &log_msg,
119  &notice_msg,
120  &err_msg);
121  time_msg(" processing withPointsDD many starts", start_t, clock());
122 
123  if (err_msg && (*result_tuples)) {
124  pfree(*result_tuples);
125  (*result_count) = 0;
126  (*result_tuples) = NULL;
127  }
128 
129  pgr_global_report(log_msg, notice_msg, err_msg);
130 
131  if (log_msg) pfree(log_msg);
132  if (notice_msg) pfree(notice_msg);
133  if (err_msg) pfree(err_msg);
134  if (edges) pfree(edges);
135  if (edges_of_points) pfree(edges_of_points);
136  if (points) pfree(points);
137  if (start_pidsArr) pfree(start_pidsArr);
138  pgr_SPI_finish();
139 }
char estimate_drivingSide(char driving_side)
#define PGR_DBG(...)
Definition: debug_macro.h:34
void pgr_get_edges(char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
basic edge_sql
Definition: edges_input.c:545
void pgr_get_points(char *points_sql, Point_on_edge_t **points, size_t *total_points)
pgr_get_points
Definition: points_input.c:63
int64_t * pgr_get_bigIntArray(size_t *arrlen, ArrayType *input)
enforces the input array to be NOT empty
Definition: arrays_input.c:124
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93
void pgr_SPI_finish(void)
void get_new_queries(char *edges_sql, char *points_sql, char **edges_of_points_query, char **edges_no_points_query)
void pgr_SPI_connect(void)
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)

Here is the call graph for this function:

Here is the caller graph for this function: