PGROUTING  3.2
matrixRows_input.h File Reference
#include <stddef.h>
#include "c_types/matrix_cell_t.h"
Include dependency graph for matrixRows_input.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void pgr_get_matrixRows (char *sql, Matrix_cell_t **distaces, size_t *total_distances)
 bigint start_vid, bigint end_vid, float agg_cost, More...
 

Function Documentation

◆ pgr_get_matrixRows()

void pgr_get_matrixRows ( char *  sql,
Matrix_cell_t **  distaces,
size_t *  total_distances 
)

bigint start_vid, bigint end_vid, float agg_cost,

Definition at line 56 of file matrixRows_input.c.

59  {
60  clock_t start_t = clock();
61 
62  const int tuple_limit = 1000000;
63 
64  size_t total_tuples = 0;
65 
66  Column_info_t info[3];
67 
68  int i;
69  for (i = 0; i < 3; ++i) {
70  info[i].colNumber = -1;
71  info[i].type = 0;
72  info[i].strict = true;
73  info[i].eType = ANY_INTEGER;
74  }
75  info[0].name = "start_vid";
76  info[1].name = "end_vid";
77  info[2].name = "agg_cost";
78 
79  info[2].eType = ANY_NUMERICAL;
80 
81 
82  void *SPIplan;
83  SPIplan = pgr_SPI_prepare(sql);
84 
85  Portal SPIportal;
86  SPIportal = pgr_SPI_cursor_open(SPIplan);
87 
88 
89  bool moredata = true;
90  (*total_rows) = total_tuples;
91 
92  while (moredata == true) {
93  SPI_cursor_fetch(SPIportal, true, tuple_limit);
94  if (total_tuples == 0)
95  pgr_fetch_column_info(info, 3);
96 
97  size_t ntuples = SPI_processed;
98  total_tuples += ntuples;
99 
100  if (ntuples > 0) {
101  if ((*rows) == NULL)
102  (*rows) = (Matrix_cell_t *)palloc0(
103  total_tuples * sizeof(Matrix_cell_t));
104  else
105  (*rows) = (Matrix_cell_t *)repalloc(
106  (*rows), total_tuples * sizeof(Matrix_cell_t));
107 
108  if ((*rows) == NULL) {
109  elog(ERROR, "Out of memory");
110  }
111 
112  SPITupleTable *tuptable = SPI_tuptable;
113  TupleDesc tupdesc = SPI_tuptable->tupdesc;
114  PGR_DBG("processing %ld matrix cell tupĺes", ntuples);
115 
116  size_t t;
117  for (t = 0; t < ntuples; t++) {
118  HeapTuple tuple = tuptable->vals[t];
119  pgr_fetch_row(&tuple, &tupdesc, info,
120  &(*rows)[total_tuples - ntuples + t]);
121  }
122  SPI_freetuptable(tuptable);
123  } else {
124  moredata = false;
125  }
126  }
127 
128  SPI_cursor_close(SPIportal);
129 
130 
131  if (total_tuples == 0) {
132  (*total_rows) = 0;
133  PGR_DBG("NO rows");
134  return;
135  }
136 
137  (*total_rows) = total_tuples;
138  time_msg(" reading matrix cells", start_t, clock());
139 }

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

Referenced by process().

Column_info_t::colNumber
int colNumber
Definition: column_info_t.h:51
pgr_fetch_row
static void pgr_fetch_row(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[3], Matrix_cell_t *distance)
Definition: matrixRows_input.c:41
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
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
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
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
Matrix_cell_t
struct matrix_cell Matrix_cell_t
ANY_NUMERICAL
@ ANY_NUMERICAL
Definition: column_info_t.h:42
matrix_cell
Definition: matrix_cell_t.h:37
Column_info_t::type
uint64_t type
Definition: column_info_t.h:52
Column_info_t
Definition: column_info_t.h:49