PGROUTING  2.5
points_input.c File Reference
Include dependency graph for points_input.c:

Go to the source code of this file.

Functions

static void fetch_point (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[4], int64_t *default_pid, char default_side, Point_on_edge_t *point)
 
void pgr_get_points (char *points_sql, Point_on_edge_t **points, size_t *total_points)
 pgr_get_points More...
 

Function Documentation

static void fetch_point ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info[4],
int64_t *  default_pid,
char  default_side,
Point_on_edge_t point 
)
static

Definition at line 35 of file points_input.c.

References column_found(), Point_on_edge_t::edge_id, Point_on_edge_t::fraction, pgr_SPI_getBigInt(), pgr_SPI_getChar(), pgr_SPI_getFloat8(), Point_on_edge_t::pid, and Point_on_edge_t::side.

Referenced by pgr_get_points().

41  {
42  if (column_found(info[0].colNumber)) {
43  point->pid = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
44  } else {
45  point->pid = *default_pid;
46  ++(*default_pid);
47  }
48 
49  point->edge_id = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
50  point->fraction = pgr_SPI_getFloat8(tuple, tupdesc, info[2]);
51 
52  if (column_found(info[3].colNumber)) {
53  point->side =
54  (char)pgr_SPI_getChar(tuple, tupdesc, info[3], false, default_side);
55  } else {
56  point->side = default_side;
57  }
58 }
int64_t pgr_SPI_getBigInt(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
char pgr_SPI_getChar(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, bool strict, char default_value)
bool column_found(int colNumber)
double pgr_SPI_getFloat8(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)

Here is the call graph for this function:

Here is the caller graph for this function:

void pgr_get_points ( char *  points_sql,
Point_on_edge_t **  points,
size_t *  total_points 
)

pgr_get_points

For queries of the type:

SELECT pid, edge_id, fraction, [side]
FROM edge_table;
Parameters
[in]points_sql
[out]points
[out]total_points

Definition at line 63 of file points_input.c.

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

Referenced by process().

66  {
67  const int tuple_limit = 1000;
68 
69  size_t ntuples;
70  size_t total_tuples;
71  Column_info_t info[4];
72 
73  int i;
74  for (i = 0; i < 4; ++i) {
75  info[i].colNumber = -1;
76  info[i].type = 0;
77  info[i].strict = true;
78  info[i].eType = ANY_INTEGER;
79  }
80 
81  info[0].name = strdup("pid");
82  info[1].name = strdup("edge_id");
83  info[2].name = strdup("fraction");
84  info[3].name = strdup("side");
85 
86  info[0].strict = false;
87  info[3].strict = false;
88  info[2].eType = ANY_NUMERICAL;
89  info[3].eType = CHAR1;
90 
91 
92  void *SPIplan;
93  SPIplan = pgr_SPI_prepare(points_sql);
94 
95  Portal SPIportal;
96  SPIportal = pgr_SPI_cursor_open(SPIplan);
97 
98  bool moredata = true;
99  (*total_points) = total_tuples = 0;
100 
101  int64_t default_pid = 0;
102  char default_side = 'b';
103 
104  while (moredata == true) {
105  SPI_cursor_fetch(SPIportal, true, tuple_limit);
106  if (total_tuples == 0) {
107  /* on the first tuple get the column information */
108  pgr_fetch_column_info(info, 4);
109  }
110 
111  ntuples = SPI_processed;
112  total_tuples += ntuples;
113 
114  if (ntuples > 0) {
115  if ((*points) == NULL)
116  (*points) = (Point_on_edge_t *)
117  palloc0(total_tuples * sizeof(Point_on_edge_t));
118  else
119  (*points) = (Point_on_edge_t *)
120  repalloc((*points), total_tuples * sizeof(Point_on_edge_t));
121 
122  if ((*points) == NULL) {
123  elog(ERROR, "Out of memory");
124  }
125 
126  SPITupleTable *tuptable = SPI_tuptable;
127  TupleDesc tupdesc = SPI_tuptable->tupdesc;
128  size_t t;
129 
130  PGR_DBG("processing %ld points tuples", ntuples);
131  for (t = 0; t < ntuples; t++) {
132  HeapTuple tuple = tuptable->vals[t];
133  fetch_point(&tuple, &tupdesc, info,
134  &default_pid, default_side,
135  &(*points)[total_tuples - ntuples + t]);
136  }
137  SPI_freetuptable(tuptable);
138  } else {
139  moredata = false;
140  }
141  }
142  SPI_cursor_close(SPIportal);
143 
144 
145  if (total_tuples == 0) {
146  (*total_points) = 0;
147  PGR_DBG("NO points");
148  return;
149  }
150 
151  (*total_points) = total_tuples;
152  PGR_DBG("Finish reading %ld points, %ld", total_tuples, (*total_points));
153 }
#define PGR_DBG(...)
Definition: debug_macro.h:34
uint64_t type
Definition: column_info_t.h:77
void pgr_fetch_column_info(Column_info_t info[], int info_size)
static void fetch_point(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[4], int64_t *default_pid, char default_side, Point_on_edge_t *point)
Definition: points_input.c:35
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
SPIPlanPtr pgr_SPI_prepare(char *sql)
expectType eType
Definition: column_info_t.h:80

Here is the call graph for this function:

Here is the caller graph for this function: