PGROUTING  3.2
points_input.c File Reference
#include "c_common/points_input.h"
#include <stdbool.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 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

◆ fetch_point()

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 41 of file points_input.c.

47  {
48  if (column_found(info[0].colNumber)) {
49  point->pid = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
50  } else {
51  point->pid = *default_pid;
52  ++(*default_pid);
53  }
54 
55  point->edge_id = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
56  point->fraction = pgr_SPI_getFloat8(tuple, tupdesc, info[2]);
57 
58  if (column_found(info[3].colNumber)) {
59  point->side =
60  (char)pgr_SPI_getChar(tuple, tupdesc, info[3], false, default_side);
61  } else {
62  point->side = default_side;
63  }
64 }

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

◆ pgr_get_points()

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 69 of file points_input.c.

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

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

Column_info_t::colNumber
int colNumber
Definition: column_info_t.h:51
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
Point_on_edge_t::edge_id
int64_t edge_id
Definition: point_on_edge_t.h:39
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
pgr_SPI_getChar
char pgr_SPI_getChar(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, bool strict, char default_value)
Function return the value of specified column in char type.
Definition: get_check_data.c:170
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
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
fetch_point
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:41
Point_on_edge_t::pid
int64_t pid
Definition: point_on_edge_t.h:38
Point_on_edge_t
Definition: point_on_edge_t.h:37
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
Point_on_edge_t::side
char side
Definition: point_on_edge_t.h:40
Point_on_edge_t::fraction
double fraction
Definition: point_on_edge_t.h:41
ANY_INTEGER
@ ANY_INTEGER
Definition: column_info_t.h:41
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
CHAR1
@ CHAR1
Definition: column_info_t.h:44
Column_info_t
Definition: column_info_t.h:49