PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
restrict_input.c File Reference
Include dependency graph for restrict_input.c:

Go to the source code of this file.

Functions

static void fetch_restriction (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[4], Restrict_t *restriction)
 
void pgr_get_restriction_data (char *restrictions_sql, Restrict_t **restrictions, size_t *total_restrictions)
 

Function Documentation

static void fetch_restriction ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info[4],
Restrict_t restriction 
)
static

Definition at line 36 of file restrict_input.c.

References Restrict_t::cost, Restrict_t::id, MAX_RULE_LENGTH, pgr_SPI_getBigInt(), pgr_SPI_getFloat8(), and Restrict_t::restricted_edges.

Referenced by pgr_get_restriction_data().

40  {
41  restriction->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
42  restriction->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[1]);
43  char *str = DatumGetCString(
44  SPI_getvalue(*tuple, *tupdesc, info[2].colNumber));
45 
46 // TODO(someone) because its text, no guarantee the text read is correct
47 // move this code to c++ to tokenize the integers.
48  int i = 0;
49  for (i = 0; i < MAX_RULE_LENGTH; ++i) restriction->restricted_edges[i] = -1;
50  str[0] = ',';
51  if (str != NULL) {
52  char *token = NULL;
53  int i = 0;
54 
55  token = (char *)strtok(str, " ,");
56 
57  while (token != NULL && i < MAX_RULE_LENGTH) {
58  restriction->restricted_edges[i] = atoi(token);
59  i++;
60  token = (char *)strtok(NULL, " ,");
61  }
62  }
63 }
int64_t pgr_SPI_getBigInt(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
int64_t id
Definition: restrict_t.h:61
#define MAX_RULE_LENGTH
Definition: trsp.h:25
int64_t restricted_edges[5]
Definition: restrict_t.h:63
double cost
Definition: restrict_t.h:62
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_restriction_data ( char *  restrictions_sql,
Restrict_t **  restrictions,
size_t *  total_restrictions 
)

Definition at line 69 of file restrict_input.c.

Referenced by process().

72  {
73  const int tuple_limit = 1000000;
74  clock_t start_t = clock();
75 
76  PGR_DBG("pgr_get_restriction_data");
77  PGR_DBG("%s", restrictions_sql);
78  Column_info_t info[3];
79 
80  int i;
81  for (i = 0; i < 3; ++i) {
82  info[i].colNumber = -1;
83  info[i].type = 0;
84  info[i].strict = true;
85  info[i].eType = ANY_INTEGER;
86  }
87  info[0].name = strdup("id");
88  info[1].name = strdup("cost");
89  info[2].name = strdup("restricted_edges");
90 
91  info[1].eType = ANY_NUMERICAL;
92  info[2].eType = ANY_INTEGER_ARRAY;
93 
94 #if 0
95  // experiment starts
96 
97  size_t total_tuples = (*total_restrictions) ;
98 
99  (*restrictions) = (Restrict_t *)palloc0(sizeof(Restrict_t));
100 
101  (*restrictions)[0].id = 1;
102  (*restrictions)[0].cost = -1;
103  (*restrictions)[0].restricted_edges[0] = 4;
104  (*restrictions)[0].restricted_edges[1] = 7;
105 
106  // experiment ends
107 #endif
108 
109 #if 1
110  size_t ntuples;
111  size_t total_tuples;
112 
113  void *SPIplan;
114  SPIplan = pgr_SPI_prepare(restrictions_sql);
115  Portal SPIportal;
116  SPIportal = pgr_SPI_cursor_open(SPIplan);
117 
118  bool moredata = TRUE;
119  (*total_restrictions) = total_tuples = 0;
120 
121 
122  while (moredata == TRUE) {
123  SPI_cursor_fetch(SPIportal, TRUE, tuple_limit);
124  if (total_tuples == 0) {
125  pgr_fetch_column_info(info, 3);
126  }
127  ntuples = SPI_processed;
128  total_tuples += ntuples;
129  PGR_DBG("SPI_processed %ld", ntuples);
130  if (ntuples > 0) {
131  if ((*restrictions) == NULL)
132  (*restrictions) = (Restrict_t *)palloc0(
133  total_tuples * sizeof(Restrict_t));
134  else
135  (*restrictions) = (Restrict_t *)repalloc(
136  (*restrictions),
137  total_tuples * sizeof(Restrict_t));
138 
139  if ((*restrictions) == NULL) {
140  elog(ERROR, "Out of memory");
141  }
142 
143  size_t t;
144  SPITupleTable *tuptable = SPI_tuptable;
145  TupleDesc tupdesc = SPI_tuptable->tupdesc;
146  PGR_DBG("processing %ld", ntuples);
147  for (t = 0; t < ntuples; t++) {
148  HeapTuple tuple = tuptable->vals[t];
149  fetch_restriction(&tuple, &tupdesc, info,
150  &(*restrictions)[total_tuples - ntuples + t]);
151  }
152  SPI_freetuptable(tuptable);
153  } else {
154  moredata = FALSE;
155  }
156  }
157 
158  SPI_cursor_close(SPIportal);
159 
160  if (total_tuples == 0) {
161  (*total_restrictions) = 0;
162  PGR_DBG("NO restrictions");
163  return;
164  }
165 
166  (*total_restrictions) = total_tuples;
167 #endif
168  PGR_DBG("Finish reading %ld data, %ld",
169  total_tuples,
170  (*total_restrictions));
171  clock_t end_t = clock();
172  time_msg(" reading Restrictions", start_t, end_t);
173 }
#define PGR_DBG(...)
Definition: debug_macro.h:34
uint64_t type
Definition: column_info_t.h:73
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
void pgr_fetch_column_info(Column_info_t info[], int info_size)
static void fetch_restriction(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[4], Restrict_t *restriction)
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
SPIPlanPtr pgr_SPI_prepare(char *sql)
expectType eType
Definition: column_info_t.h:76

Here is the caller graph for this function: