PGROUTING  3.2
edges_input.c File Reference
#include "c_common/edges_input.h"
#include <math.h>
#include <float.h>
#include <limits.h>
#include <stddef.h>
#include "c_types/column_info_t.h"
#include "c_common/debug_macro.h"
#include "c_common/get_check_data.h"
#include "c_common/time_msg.h"
Include dependency graph for edges_input.c:

Go to the source code of this file.

Functions

static void fetch_basic_edge (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[5], int64_t *default_id, pgr_basic_edge_t *edge, size_t *valid_edges)
 
static void fetch_costFlow_edge (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[7], int64_t *default_id, int64_t default_rcapacity, float8 default_rcost, pgr_costFlow_t *edge, size_t *valid_edges, bool normal)
 
static void fetch_edge (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[5], int64_t *default_id, float8 default_rcost, pgr_edge_t *edge, size_t *valid_edges, bool normal)
 
static void fetch_edge_with_xy (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[9], int64_t *default_id, float8 default_rcost, Pgr_edge_xy_t *edge, size_t *valid_edges, bool normal)
 
static void get_edges_5_columns (char *sql, pgr_edge_t **edges, size_t *totalTuples, bool ignore_id, bool normal)
 
static void get_edges_9_columns (char *sql, Pgr_edge_xy_t **edges, size_t *total_edges, bool normal)
 
static void get_edges_basic (char *sql, pgr_basic_edge_t **edges, size_t *totalTuples, bool ignore_id)
 
static void get_edges_costFlow (char *sql, pgr_costFlow_t **edges, size_t *totalTuples, bool ignore_id)
 
static void get_edges_flow (char *sql, pgr_edge_t **edges, size_t *totalTuples, bool ignore_id)
 
void pgr_get_basic_edges (char *sql, pgr_basic_edge_t **edges, size_t *total_edges)
 read basic edges More...
 
void pgr_get_costFlow_edges (char *sql, pgr_costFlow_t **edges, size_t *total_edges)
 read edges for cost flow More...
 
void pgr_get_edges (char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
 basic edge_sql More...
 
void pgr_get_edges_no_id (char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
 edges_sql without id parameter More...
 
void pgr_get_edges_reversed (char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
 
void pgr_get_edges_xy (char *edges_sql, Pgr_edge_xy_t **edges, size_t *total_edges)
 Edges with x, y vertices values. More...
 
void pgr_get_edges_xy_reversed (char *edges_sql, Pgr_edge_xy_t **edges, size_t *total_edges)
 for many to 1 on aStar More...
 
void pgr_get_flow_edges (char *sql, pgr_edge_t **edges, size_t *total_edges)
 read edges for flow More...
 

Function Documentation

◆ fetch_basic_edge()

static void fetch_basic_edge ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info[5],
int64_t *  default_id,
pgr_basic_edge_t edge,
size_t *  valid_edges 
)
static

Definition at line 44 of file edges_input.c.

50  {
51  if (column_found(info[0].colNumber)) {
52  edge->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
53  } else {
54  edge->id = *default_id;
55  ++(*default_id);
56  }
57 
58  edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
59  edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[2]);
60  edge->going = pgr_SPI_getFloat8(tuple, tupdesc, info[3]) > 0 ?
61  true : false;
62  edge->coming = (column_found(info[4].colNumber)
63  && pgr_SPI_getFloat8(tuple, tupdesc, info[4]) > 0) ?
64  true : false;
65 
66  (*valid_edges)++;
67 }

References column_found(), edge::id, pgr_SPI_getBigInt(), pgr_SPI_getFloat8(), edge::source, and edge::target.

Referenced by get_edges_basic().

◆ fetch_costFlow_edge()

static void fetch_costFlow_edge ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info[7],
int64_t *  default_id,
int64_t  default_rcapacity,
float8  default_rcost,
pgr_costFlow_t edge,
size_t *  valid_edges,
bool  normal 
)
static

Definition at line 113 of file edges_input.c.

122  {
123  if (column_found(info[0].colNumber)) {
124  edge->edge_id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
125  } else {
126  edge->edge_id = *default_id;
127  ++(*default_id);
128  }
129 
130  if (normal) {
131  edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
132  edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[2]);
133  } else {
134  edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
135  edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[2]);
136  }
137 
138  edge->capacity = pgr_SPI_getBigInt(tuple, tupdesc, info[3]);
139  if (column_found(info[4].colNumber)) {
140  edge->reverse_capacity = pgr_SPI_getBigInt(tuple, tupdesc, info[4]);
141  } else {
142  edge->reverse_capacity = default_rcapacity;
143  }
144 
145  edge->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[5]);
146  if (column_found(info[6].colNumber)) {
147  edge->reverse_cost = pgr_SPI_getFloat8(tuple, tupdesc, info[6]);
148  } else {
149  edge->reverse_cost = default_rcost;
150  }
151 
152  *valid_edges = edge->capacity < 0? *valid_edges: *valid_edges + 1;
153  *valid_edges = edge->reverse_capacity < 0? *valid_edges: *valid_edges + 1;
154 }

References column_found(), edge::cost, pgr_SPI_getBigInt(), pgr_SPI_getFloat8(), edge::reverse_cost, edge::source, and edge::target.

Referenced by get_edges_costFlow().

◆ fetch_edge()

static void fetch_edge ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info[5],
int64_t *  default_id,
float8  default_rcost,
pgr_edge_t edge,
size_t *  valid_edges,
bool  normal 
)
static

Definition at line 70 of file edges_input.c.

78  {
79  if (column_found(info[0].colNumber)) {
80  edge->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
81  } else {
82  edge->id = *default_id;
83  ++(*default_id);
84  }
85 
86  if (normal) {
87  edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
88  edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[2]);
89  } else {
90  edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
91  edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[2]);
92  }
93 
94  edge->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[3]);
95 
96  if (column_found(info[4].colNumber)) {
97  edge->reverse_cost = pgr_SPI_getFloat8(tuple, tupdesc, info[4]);
98  } else {
99  edge->reverse_cost = default_rcost;
100  }
101 
102  edge->cost = isinf(edge->cost)?
103  DBL_MAX : edge->cost;
104 
105  edge->reverse_cost = isinf(edge->reverse_cost)?
106  DBL_MAX : edge->reverse_cost;
107 
108  *valid_edges = edge->cost < 0? *valid_edges: *valid_edges + 1;
109  *valid_edges = edge->reverse_cost < 0? *valid_edges: *valid_edges + 1;
110 }

References column_found(), edge::cost, edge::id, pgr_SPI_getBigInt(), pgr_SPI_getFloat8(), edge::reverse_cost, edge::source, and edge::target.

Referenced by get_edges_5_columns(), and get_edges_flow().

◆ fetch_edge_with_xy()

static void fetch_edge_with_xy ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info[9],
int64_t *  default_id,
float8  default_rcost,
Pgr_edge_xy_t edge,
size_t *  valid_edges,
bool  normal 
)
static

Definition at line 157 of file edges_input.c.

165  {
166  if (column_found(info[0].colNumber)) {
167  edge->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
168  } else {
169  edge->id = *default_id;
170  ++(*default_id);
171  }
172 
173  if (normal) {
174  edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
175  edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[2]);
176  } else {
177  edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
178  edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[2]);
179  }
180  edge->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[3]);
181 
182  if (column_found(info[4].colNumber)) {
183  edge->reverse_cost = pgr_SPI_getFloat8(tuple, tupdesc, info[4]);
184  } else {
185  edge->reverse_cost = default_rcost;
186  }
187 
188  edge->x1 = pgr_SPI_getFloat8(tuple, tupdesc, info[5]);
189  edge->y1 = pgr_SPI_getFloat8(tuple, tupdesc, info[6]);
190  edge->x2 = pgr_SPI_getFloat8(tuple, tupdesc, info[7]);
191  edge->y2 = pgr_SPI_getFloat8(tuple, tupdesc, info[8]);
192 #if 0
193  PGR_DBG("%ld", edge->id);
194  PGR_DBG("x1=%f y1=%.15lf", edge->x1, edge->y1);
195  PGR_DBG("x2=%f y2=%.15lf", edge->x2, edge->y2);
196 #endif
197 
198 
199  *valid_edges = edge->cost < 0? *valid_edges: *valid_edges + 1;
200  *valid_edges = edge->reverse_cost < 0? *valid_edges: *valid_edges + 1;
201 }

References column_found(), edge::cost, edge::id, PGR_DBG, pgr_SPI_getBigInt(), pgr_SPI_getFloat8(), edge::reverse_cost, edge::source, and edge::target.

Referenced by get_edges_9_columns().

◆ get_edges_5_columns()

static void get_edges_5_columns ( char *  sql,
pgr_edge_t **  edges,
size_t *  totalTuples,
bool  ignore_id,
bool  normal 
)
static

Definition at line 310 of file edges_input.c.

315  {
316  clock_t start_t = clock();
317 
318  const int tuple_limit = 1000000;
319 
320  size_t total_tuples;
321  size_t valid_edges;
322 
323  Column_info_t info[5];
324 
325  int i;
326  for (i = 0; i < 5; ++i) {
327  info[i].colNumber = -1;
328  info[i].type = 0;
329  info[i].strict = true;
330  info[i].eType = ANY_INTEGER;
331  }
332  info[0].name = "id";
333  info[1].name = "source";
334  info[2].name = "target";
335  info[3].name = "cost";
336  info[4].name = "reverse_cost";
337 
338  info[0].strict = !ignore_id;
339  info[4].strict = false;
340 
341  info[3].eType = ANY_NUMERICAL;
342  info[4].eType = ANY_NUMERICAL;
343 
344 
345  void *SPIplan;
346  SPIplan = pgr_SPI_prepare(sql);
347 
348  Portal SPIportal;
349  SPIportal = pgr_SPI_cursor_open(SPIplan);
350 
351 
352  bool moredata = true;
353  (*totalTuples) = total_tuples = valid_edges = 0;
354 
355 
356  int64_t default_id = 0;
357  while (moredata == true) {
358  SPI_cursor_fetch(SPIportal, true, tuple_limit);
359  if (total_tuples == 0)
360  pgr_fetch_column_info(info, 5);
361 
362  size_t ntuples = SPI_processed;
363  total_tuples += ntuples;
364 
365  if (ntuples > 0) {
366  if ((*edges) == NULL)
367  (*edges) = (pgr_edge_t *)
368  palloc0(total_tuples * sizeof(pgr_edge_t));
369  else
370  (*edges) = (pgr_edge_t *)
371  repalloc((*edges), total_tuples * sizeof(pgr_edge_t));
372 
373  if ((*edges) == NULL) {
374  elog(ERROR, "Out of memory");
375  }
376 
377  size_t t;
378  SPITupleTable *tuptable = SPI_tuptable;
379  TupleDesc tupdesc = SPI_tuptable->tupdesc;
380  for (t = 0; t < ntuples; t++) {
381  HeapTuple tuple = tuptable->vals[t];
382  fetch_edge(&tuple, &tupdesc, info,
383  &default_id, -1,
384  &(*edges)[total_tuples - ntuples + t],
385  &valid_edges,
386  normal);
387  }
388  SPI_freetuptable(tuptable);
389  } else {
390  moredata = false;
391  }
392  }
393 
394  SPI_cursor_close(SPIportal);
395 
396  if (total_tuples == 0 || valid_edges == 0) {
397  PGR_DBG("No edges found");
398  }
399 
400  (*totalTuples) = total_tuples;
401  time_msg("reading edges", start_t, clock());
402 }

References ANY_INTEGER, ANY_NUMERICAL, Column_info_t::colNumber, Column_info_t::eType, fetch_edge(), Column_info_t::name, PGR_DBG, pgr_fetch_column_info(), pgr_SPI_cursor_open(), pgr_SPI_prepare(), Column_info_t::strict, time_msg(), and Column_info_t::type.

Referenced by pgr_get_edges(), pgr_get_edges_no_id(), and pgr_get_edges_reversed().

◆ get_edges_9_columns()

static void get_edges_9_columns ( char *  sql,
Pgr_edge_xy_t **  edges,
size_t *  total_edges,
bool  normal 
)
static

Definition at line 205 of file edges_input.c.

209  {
210  clock_t start_t = clock();
211 
212  const int tuple_limit = 1000000;
213 
214  size_t total_tuples;
215  size_t valid_edges;
216 
217  Column_info_t info[9];
218 
219  info[0].name = "id";
220  info[1].name = "source";
221  info[2].name = "target";
222  info[3].name = "cost";
223  info[4].name = "reverse_cost";
224  info[5].name = "x1";
225  info[6].name = "y1";
226  info[7].name = "x2";
227  info[8].name = "y2";
228 
229  int i;
230  for (i = 0; i < 3; ++i) {
231  info[i].colNumber = -1;
232  info[i].type = 0;
233  info[i].strict = true;
234  info[i].eType = ANY_INTEGER;
235  }
236  for (i = 3; i < 9; ++i) {
237  info[i].colNumber = -1;
238  info[i].type = 0;
239  info[i].strict = true;
240  info[i].eType = ANY_NUMERICAL;
241  }
242  /*
243  * reverse_cost is optional
244  */
245  info[4].strict = false;
246 
247 
248  void *SPIplan;
249  SPIplan = pgr_SPI_prepare(sql);
250 
251  Portal SPIportal;
252  SPIportal = pgr_SPI_cursor_open(SPIplan);
253 
254 
255  bool moredata = true;
256  (*total_edges) = total_tuples = valid_edges = 0;
257 
258 
259  int64_t default_id = 0;
260  while (moredata == true) {
261  SPI_cursor_fetch(SPIportal, true, tuple_limit);
262  if (total_tuples == 0)
263  pgr_fetch_column_info(info, 9);
264 
265  size_t ntuples = SPI_processed;
266  total_tuples += ntuples;
267 
268  if (ntuples > 0) {
269  if ((*edges) == NULL)
270  (*edges) = (Pgr_edge_xy_t *)
271  palloc0(total_tuples * sizeof(Pgr_edge_xy_t));
272  else
273  (*edges) = (Pgr_edge_xy_t *)
274  repalloc((*edges), total_tuples * sizeof(Pgr_edge_xy_t));
275 
276  if ((*edges) == NULL) {
277  elog(ERROR, "Out of memory");
278  }
279 
280  size_t t;
281  SPITupleTable *tuptable = SPI_tuptable;
282  TupleDesc tupdesc = SPI_tuptable->tupdesc;
283  for (t = 0; t < ntuples; t++) {
284  HeapTuple tuple = tuptable->vals[t];
285  fetch_edge_with_xy(&tuple, &tupdesc, info,
286  &default_id, -1,
287  &(*edges)[total_tuples - ntuples + t],
288  &valid_edges, normal);
289  }
290  SPI_freetuptable(tuptable);
291  } else {
292  moredata = false;
293  }
294  }
295 
296  SPI_cursor_close(SPIportal);
297 
298  if (total_tuples == 0 || valid_edges == 0) {
299  PGR_DBG("No edges found");
300  }
301 
302  (*total_edges) = total_tuples;
303  time_msg("reading edges", start_t, clock());
304 }

References ANY_INTEGER, ANY_NUMERICAL, Column_info_t::colNumber, Column_info_t::eType, fetch_edge_with_xy(), Column_info_t::name, PGR_DBG, pgr_fetch_column_info(), pgr_SPI_cursor_open(), pgr_SPI_prepare(), Column_info_t::strict, time_msg(), and Column_info_t::type.

Referenced by pgr_get_edges_xy(), and pgr_get_edges_xy_reversed().

◆ get_edges_basic()

static void get_edges_basic ( char *  sql,
pgr_basic_edge_t **  edges,
size_t *  totalTuples,
bool  ignore_id 
)
static

Definition at line 596 of file edges_input.c.

600  {
601  clock_t start_t = clock();
602 
603  const int tuple_limit = 1000000;
604 
605  size_t total_tuples;
606  size_t valid_edges;
607 
608  Column_info_t info[5];
609 
610  int i;
611  for (i = 0; i < 5; ++i) {
612  info[i].colNumber = -1;
613  info[i].type = 0;
614  info[i].strict = true;
615  info[i].eType = ANY_INTEGER;
616  }
617  info[0].name = "id";
618  info[1].name = "source";
619  info[2].name = "target";
620  info[3].name = "going";
621  info[4].name = "coming";
622 
623  info[0].strict = !ignore_id;
624  info[4].strict = false;
625 
626  info[3].eType = ANY_NUMERICAL;
627  info[4].eType = ANY_NUMERICAL;
628 
629 
630  void *SPIplan;
631  SPIplan = pgr_SPI_prepare(sql);
632 
633  Portal SPIportal;
634  SPIportal = pgr_SPI_cursor_open(SPIplan);
635 
636 
637  bool moredata = true;
638  (*totalTuples) = total_tuples = valid_edges = 0;
639 
640 
641  int64_t default_id = 0;
642  while (moredata == true) {
643  SPI_cursor_fetch(SPIportal, true, tuple_limit);
644  if (total_tuples == 0)
645  pgr_fetch_column_info(info, 5);
646 
647  size_t ntuples = SPI_processed;
648  total_tuples += ntuples;
649 
650  if (ntuples > 0) {
651  if ((*edges) == NULL)
652  (*edges) = (pgr_basic_edge_t *)palloc0(
653  total_tuples * sizeof(pgr_basic_edge_t));
654  else
655  (*edges) = (pgr_basic_edge_t *)repalloc(
656  (*edges), total_tuples * sizeof(pgr_basic_edge_t));
657 
658  if ((*edges) == NULL) {
659  elog(ERROR, "Out of memory");
660  }
661 
662  size_t t;
663  SPITupleTable *tuptable = SPI_tuptable;
664  TupleDesc tupdesc = SPI_tuptable->tupdesc;
665 
666  for (t = 0; t < ntuples; t++) {
667  HeapTuple tuple = tuptable->vals[t];
668  fetch_basic_edge(&tuple, &tupdesc, info,
669  &default_id,
670  &(*edges)[total_tuples - ntuples + t],
671  &valid_edges);
672  }
673  SPI_freetuptable(tuptable);
674  } else {
675  moredata = false;
676  }
677  }
678 
679  SPI_cursor_close(SPIportal);
680 
681  if (total_tuples == 0 || valid_edges == 0) {
682  PGR_DBG("No edges found");
683  }
684 
685  (*totalTuples) = total_tuples;
686  time_msg("reading edges", start_t, clock());
687 }

References ANY_INTEGER, ANY_NUMERICAL, Column_info_t::colNumber, Column_info_t::eType, fetch_basic_edge(), Column_info_t::name, PGR_DBG, pgr_fetch_column_info(), pgr_SPI_cursor_open(), pgr_SPI_prepare(), Column_info_t::strict, time_msg(), and Column_info_t::type.

Referenced by pgr_get_basic_edges().

◆ get_edges_costFlow()

static void get_edges_costFlow ( char *  sql,
pgr_costFlow_t **  edges,
size_t *  totalTuples,
bool  ignore_id 
)
static

Definition at line 498 of file edges_input.c.

502  {
503  clock_t start_t = clock();
504 
505  const int tuple_limit = 1000000;
506 
507  size_t total_tuples;
508  size_t valid_edges;
509 
510  Column_info_t info[7];
511 
512  int i;
513  for (i = 0; i < 5; ++i) {
514  info[i].colNumber = -1;
515  info[i].type = 0;
516  info[i].strict = true;
517  info[i].eType = ANY_INTEGER;
518  }
519  info[0].name = "id";
520  info[1].name = "source";
521  info[2].name = "target";
522  info[3].name = "capacity";
523  info[4].name = "reverse_capacity";
524  info[5].name = "cost";
525  info[6].name = "reverse_cost";
526 
527  info[0].strict = !ignore_id;
528  info[4].strict = false;
529  info[6].strict = false;
530 
531  info[5].eType = ANY_NUMERICAL;
532  info[6].eType = ANY_NUMERICAL;
533 
534  void *SPIplan;
535  SPIplan = pgr_SPI_prepare(sql);
536 
537  Portal SPIportal;
538  SPIportal = pgr_SPI_cursor_open(SPIplan);
539 
540 
541  bool moredata = true;
542  (*totalTuples) = total_tuples = valid_edges = 0;
543 
544 
545  int64_t default_id = 0;
546  while (moredata == true) {
547  SPI_cursor_fetch(SPIportal, true, tuple_limit);
548  if (total_tuples == 0)
549  pgr_fetch_column_info(info, 7);
550 
551  size_t ntuples = SPI_processed;
552  total_tuples += ntuples;
553 
554  if (ntuples > 0) {
555  if ((*edges) == NULL)
556  (*edges) = (pgr_costFlow_t *)
557  palloc0(total_tuples * sizeof(pgr_costFlow_t));
558  else
559  (*edges) = (pgr_costFlow_t *)
560  repalloc((*edges), total_tuples * sizeof(pgr_costFlow_t));
561 
562  if ((*edges) == NULL) {
563  elog(ERROR, "Out of memory");
564  }
565 
566  size_t t;
567  SPITupleTable *tuptable = SPI_tuptable;
568  TupleDesc tupdesc = SPI_tuptable->tupdesc;
569 
570  for (t = 0; t < ntuples; t++) {
571  HeapTuple tuple = tuptable->vals[t];
572  fetch_costFlow_edge(&tuple, &tupdesc, info,
573  &default_id, -1, 0,
574  &(*edges)[total_tuples - ntuples + t],
575  &valid_edges,
576  true);
577  }
578  SPI_freetuptable(tuptable);
579  } else {
580  moredata = false;
581  }
582  }
583 
584  SPI_cursor_close(SPIportal);
585 
586  if (total_tuples == 0 || valid_edges == 0) {
587  PGR_DBG("No edges found");
588  }
589 
590  (*totalTuples) = total_tuples;
591  time_msg("reading edges", start_t, clock());
592 }

References ANY_INTEGER, ANY_NUMERICAL, Column_info_t::colNumber, Column_info_t::eType, fetch_costFlow_edge(), Column_info_t::name, PGR_DBG, pgr_fetch_column_info(), pgr_SPI_cursor_open(), pgr_SPI_prepare(), Column_info_t::strict, time_msg(), and Column_info_t::type.

Referenced by pgr_get_costFlow_edges().

◆ get_edges_flow()

static void get_edges_flow ( char *  sql,
pgr_edge_t **  edges,
size_t *  totalTuples,
bool  ignore_id 
)
static

Definition at line 406 of file edges_input.c.

410  {
411  clock_t start_t = clock();
412 
413  const int tuple_limit = 1000000;
414 
415  size_t total_tuples;
416  size_t valid_edges;
417 
418  Column_info_t info[5];
419 
420  int i;
421  for (i = 0; i < 5; ++i) {
422  info[i].colNumber = -1;
423  info[i].type = 0;
424  info[i].strict = true;
425  info[i].eType = ANY_INTEGER;
426  }
427  info[0].name = "id";
428  info[1].name = "source";
429  info[2].name = "target";
430  info[3].name = "capacity";
431  info[4].name = "reverse_capacity";
432 
433  info[0].strict = !ignore_id;
434  info[4].strict = false;
435 
436  void *SPIplan;
437  SPIplan = pgr_SPI_prepare(sql);
438 
439  Portal SPIportal;
440  SPIportal = pgr_SPI_cursor_open(SPIplan);
441 
442 
443  bool moredata = true;
444  (*totalTuples) = total_tuples = valid_edges = 0;
445 
446 
447  int64_t default_id = 0;
448  while (moredata == true) {
449  SPI_cursor_fetch(SPIportal, true, tuple_limit);
450  if (total_tuples == 0)
451  pgr_fetch_column_info(info, 5);
452 
453  size_t ntuples = SPI_processed;
454  total_tuples += ntuples;
455 
456  if (ntuples > 0) {
457  if ((*edges) == NULL)
458  (*edges) = (pgr_edge_t *)
459  palloc0(total_tuples * sizeof(pgr_flow_t));
460  else
461  (*edges) = (pgr_edge_t *)
462  repalloc((*edges), total_tuples * sizeof(pgr_flow_t));
463 
464  if ((*edges) == NULL) {
465  elog(ERROR, "Out of memory");
466  }
467 
468  size_t t;
469  SPITupleTable *tuptable = SPI_tuptable;
470  TupleDesc tupdesc = SPI_tuptable->tupdesc;
471 
472  for (t = 0; t < ntuples; t++) {
473  HeapTuple tuple = tuptable->vals[t];
474  fetch_edge(&tuple, &tupdesc, info,
475  &default_id, -1,
476  &(*edges)[total_tuples - ntuples + t],
477  &valid_edges,
478  true);
479  }
480  SPI_freetuptable(tuptable);
481  } else {
482  moredata = false;
483  }
484  }
485 
486  SPI_cursor_close(SPIportal);
487 
488  if (total_tuples == 0 || valid_edges == 0) {
489  PGR_DBG("No edges found");
490  }
491 
492  (*totalTuples) = total_tuples;
493  time_msg("Reading edges", start_t, clock());
494 }

References ANY_INTEGER, Column_info_t::colNumber, Column_info_t::eType, fetch_edge(), Column_info_t::name, PGR_DBG, pgr_fetch_column_info(), pgr_SPI_cursor_open(), pgr_SPI_prepare(), Column_info_t::strict, time_msg(), and Column_info_t::type.

Referenced by pgr_get_flow_edges().

◆ pgr_get_basic_edges()

void pgr_get_basic_edges ( char *  sql,
pgr_basic_edge_t **  edges,
size_t *  total_edges 
)

read basic edges

For queries of the type:

SELECT id, source, target, going, [coming]
FROM edge_table;
Parameters
[in]sql
[out]edges
[out]total_edges

Definition at line 766 of file edges_input.c.

769  {
770  bool ignore_id = false;
771  get_edges_basic(sql, edges, total_edges, ignore_id);
772 }

References get_edges_basic().

Referenced by process().

◆ pgr_get_costFlow_edges()

void pgr_get_costFlow_edges ( char *  sql,
pgr_costFlow_t **  edges,
size_t *  total_edges 
)

read edges for cost flow

Edges:

bigint id, bigint source, bigint target, bigint capacity, bigint reverse_capacity float cost, float reverse_cost

Parameters
[in]sql
[out]edges
[out]total_edges

Definition at line 701 of file edges_input.c.

704  {
705  bool ignore_id = false;
706  get_edges_costFlow(sql, edges, total_edges, ignore_id);
707 }

References get_edges_costFlow().

Referenced by process().

◆ pgr_get_edges()

void pgr_get_edges ( char *  edges_sql,
pgr_edge_t **  edges,
size_t *  total_edges 
)

basic edge_sql

For queries of the type:

SELECT id, source, target, cost, [reverse_cost]
FROM edge_table;
Parameters
[in]edges_sql
[out]edges
[out]total_edges

Definition at line 711 of file edges_input.c.

714  {
715  bool ignore_id = false;
716  bool normal = true;
717  get_edges_5_columns(edges_sql, edges, total_edges, ignore_id, normal);
718 }

References get_edges_5_columns().

Referenced by compute(), compute_trsp(), process(), and process_combinations().

◆ pgr_get_edges_no_id()

void pgr_get_edges_no_id ( char *  edges_sql,
pgr_edge_t **  edges,
size_t *  total_edges 
)

edges_sql without id parameter

SELECT source, target, cost, [reverse_cost]
FROM edge_table;

Currently used in: allpairs

Parameters
[in]edges_sql
[out]edges
[out]total_edges

Definition at line 733 of file edges_input.c.

736  {
737  bool ignore_id = true;
738  bool normal = true;
739  get_edges_5_columns(edges_sql, edges, total_edges, ignore_id, normal);
740 }

References get_edges_5_columns().

Referenced by process().

◆ pgr_get_edges_reversed()

void pgr_get_edges_reversed ( char *  edges_sql,
pgr_edge_t **  edges,
size_t *  total_edges 
)

Definition at line 722 of file edges_input.c.

725  {
726  bool ignore_id = false;
727  bool normal = false;
728  get_edges_5_columns(edges_sql, edges, total_edges, ignore_id, normal);
729 }

References get_edges_5_columns().

Referenced by process().

◆ pgr_get_edges_xy()

void pgr_get_edges_xy ( char *  edges_sql,
Pgr_edge_xy_t **  edges,
size_t *  total_edges 
)

Edges with x, y vertices values.

For queries of the type:

SELECT id, source, target, cost, [reverse_cost], x1, y1, x2, y2
FROM edge_table;
Parameters
[in]edges_sql
[out]edges
[out]total_edges

Definition at line 744 of file edges_input.c.

747  {
748  get_edges_9_columns(edges_sql, edges, total_edges, true);
749 }

References get_edges_9_columns().

Referenced by process().

◆ pgr_get_edges_xy_reversed()

void pgr_get_edges_xy_reversed ( char *  edges_sql,
Pgr_edge_xy_t **  edges,
size_t *  total_edges 
)

for many to 1 on aStar

Used internally

Transforms queries of the type:

SELECT id, source, target, cost, [reverse_cost], x1, y1, x2, y2
FROM edge_table;

to

SELECT id, target, source, cost, [reverse_cost], x1, y1, x2, y2
FROM edge_table;
Parameters
[in]edges_sql
[out]edges
[out]total_edges

Definition at line 757 of file edges_input.c.

760  {
761  get_edges_9_columns(edges_sql, edges, total_edges, false);
762 }

References get_edges_9_columns().

Referenced by process().

◆ pgr_get_flow_edges()

void pgr_get_flow_edges ( char *  sql,
pgr_edge_t **  edges,
size_t *  total_edges 
)

read edges for flow

Edges:

bigint id, bigint source, bigint target, bigint capacity, bigint reverse_capacity

Parameters
[in]sql
[out]edges
[out]total_edges

Definition at line 691 of file edges_input.c.

694  {
695  bool ignore_id = false;
696  get_edges_flow(sql, edges, total_edges, ignore_id);
697 }

References get_edges_flow().

Referenced by process().

Column_info_t::colNumber
int colNumber
Definition: column_info_t.h:51
edge::reverse_cost
float8 reverse_cost
Definition: trsp.h:46
fetch_basic_edge
static void fetch_basic_edge(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[5], int64_t *default_id, pgr_basic_edge_t *edge, size_t *valid_edges)
Definition: edges_input.c:44
edge::cost
float8 cost
Definition: trsp.h:45
edge::target
int64 target
Definition: trsp.h:44
pgr_edge_t
Definition: pgr_edge_t.h:37
Column_info_t::strict
bool strict
Definition: column_info_t.h:53
pgr_SPI_prepare
SPIPlanPtr pgr_SPI_prepare(char *sql)
Definition: postgres_connection.c:94
get_edges_costFlow
static void get_edges_costFlow(char *sql, pgr_costFlow_t **edges, size_t *totalTuples, bool ignore_id)
Definition: edges_input.c:498
pgr_flow_t
Definition: pgr_flow_t.h:37
get_edges_9_columns
static void get_edges_9_columns(char *sql, Pgr_edge_xy_t **edges, size_t *total_edges, bool normal)
Definition: edges_input.c:205
get_edges_5_columns
static void get_edges_5_columns(char *sql, pgr_edge_t **edges, size_t *totalTuples, bool ignore_id, bool normal)
Definition: edges_input.c:310
edge
Definition: trsp.h:41
pgr_SPI_getBigInt
int64_t pgr_SPI_getBigInt(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
Function returns the value of specified column in integer type.
Definition: get_check_data.c:216
pgr_fetch_column_info
void pgr_fetch_column_info(Column_info_t info[], int info_size)
Function tells expected type of each column and then check the correspondence type of each column.
Definition: get_check_data.c:78
fetch_edge_with_xy
static void fetch_edge_with_xy(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[9], int64_t *default_id, float8 default_rcost, Pgr_edge_xy_t *edge, size_t *valid_edges, bool normal)
Definition: edges_input.c:157
Column_info_t::name
char * name
Definition: column_info_t.h:54
pgr_SPI_cursor_open
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
Definition: postgres_connection.c:107
get_edges_basic
static void get_edges_basic(char *sql, pgr_basic_edge_t **edges, size_t *totalTuples, bool ignore_id)
Definition: edges_input.c:596
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
edge::source
int64 source
Definition: trsp.h:43
pgr_basic_edge_t
Definition: pgr_basic_edge_t.h:38
pgr_SPI_getFloat8
double pgr_SPI_getFloat8(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
Function returns the value of specified column in double type.
Definition: get_check_data.c:246
Column_info_t::eType
expectType eType
Definition: column_info_t.h:55
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
ANY_INTEGER
@ ANY_INTEGER
Definition: column_info_t.h:41
pgr_costFlow_t
Definition: pgr_costFlow_t.h:38
edge::id
int64 id
Definition: trsp.h:42
fetch_costFlow_edge
static void fetch_costFlow_edge(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[7], int64_t *default_id, int64_t default_rcapacity, float8 default_rcost, pgr_costFlow_t *edge, size_t *valid_edges, bool normal)
Definition: edges_input.c:113
ANY_NUMERICAL
@ ANY_NUMERICAL
Definition: column_info_t.h:42
column_found
bool column_found(int colNumber)
Function will check whether the colNumber represent any specific column or NULL (SPI_ERROR_NOATTRIBUT...
Definition: get_check_data.c:36
Column_info_t::type
uint64_t type
Definition: column_info_t.h:52
Column_info_t
Definition: column_info_t.h:49
fetch_edge
static void fetch_edge(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[5], int64_t *default_id, float8 default_rcost, pgr_edge_t *edge, size_t *valid_edges, bool normal)
Definition: edges_input.c:70
Pgr_edge_xy_t
Definition: pgr_edge_xy_t.h:38
get_edges_flow
static void get_edges_flow(char *sql, pgr_edge_t **edges, size_t *totalTuples, bool ignore_id)
Definition: edges_input.c:406