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

◆ pgr_fetch_row()

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

Definition at line 41 of file matrixRows_input.c.

45  {
46  distance->from_vid = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
47  distance->to_vid = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
48  distance->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[2]);
49 }

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

Referenced by pgr_get_matrixRows().

◆ pgr_get_matrixRows()

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 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
matrix_cell::to_vid
int64_t to_vid
Definition: matrix_cell_t.h:39
matrix_cell::cost
double cost
Definition: matrix_cell_t.h:40
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
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
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
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
matrix_cell::from_vid
int64_t from_vid
Definition: matrix_cell_t.h:38
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