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

Go to the source code of this file.

Functions

static void pgr_fetch_row (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[3], Matrix_cell_t *distance)
 
void pgr_get_matrixRows (char *sql, Matrix_cell_t **rows, size_t *total_rows)
 bigint start_vid, bigint end_vid, float agg_cost, More...
 

Function Documentation

static void pgr_fetch_row ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info[3],
Matrix_cell_t distance 
)
static

Definition at line 36 of file matrixRows_input.c.

References matrix_cell::cost, matrix_cell::from_vid, pgr_SPI_getBigInt(), pgr_SPI_getFloat8(), and matrix_cell::to_vid.

Referenced by pgr_get_matrixRows().

40  {
41  distance->from_vid = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
42  distance->to_vid = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
43  distance->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[2]);
44 }
int64_t pgr_SPI_getBigInt(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
int64_t from_vid
Definition: matrix_cell_t.h:59
int64_t to_vid
Definition: matrix_cell_t.h:60
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_matrixRows ( char *  sql,
Matrix_cell_t **  rows,
size_t *  total_rows 
)

bigint start_vid, bigint end_vid, float agg_cost,

Definition at line 51 of file matrixRows_input.c.

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

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

Here is the call graph for this function:

Here is the caller graph for this function: