diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml deleted file mode 100644 index 349e9c00339..00000000000 --- a/.github/workflows/windows.yml +++ /dev/null @@ -1,107 +0,0 @@ -name: Build for Windows - -# This action runs: -# - When this file changes -# - When changes on code (src, include) -# - When changes on data or testing scripts (tools/testers) -# - When the way the build changes (CMakeLists.txt) -# -# Test is done on: -# - the preinstalled postgres version -# - postgis 3 -# -# The boost version tested are when changes that affect pgRouting on -# - boost::graph -# - boost::geometry -# See https://www.boost.org/users/history/ -# Currently -# - boost::geometry has not changed anything we use -# - boost::graph changed on 1.68 and 1.75 requires C++14 -# - 1.56 is the minimum version we ask - -on: - push: - paths: - - '.github/workflows/windows.yml' - - 'src/**' - - 'include/**' - - 'pgtap/**' - - 'tools/testers/**' - - 'CMakeLists.txt' - - branches-ignore: - - 'gh-pages' - - tags: [] - - pull_request: - paths: - - '.github/workflows/windows.yml' - - 'src/**' - - 'include/**' - - 'pgtap/**' - - 'tools/testers/**' - - 'CMakeLists.txt' - - branches-ignore: - - 'gh-pages' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: - contents: read - -env: - postgis_version: 3 - -jobs: - build: - name: windows - runs-on: windows-latest - - strategy: - matrix: - pg_major: [11.13, 12.8, 13.4] - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install boost - uses: MarkusJx/install-boost@v2.4.4 - id: install-boost - with: - # REQUIRED: Specify the required boost version - boost_version: 1.73.0 - - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1.3.1 - - - name: Install PostgreSQL - run: | - curl https://get.enterprisedb.com/postgresql/postgresql-${{ matrix.pg_major }}-1-windows-x64-binaries.zip --output pgsql.zip - Expand-Archive 'pgsql.zip' -Force - $env:path += ";$(Get-Location)\pgsql\pgsql\bin\" - $env:path -split ";" - initdb -D pgsql\data -U postgres - pg_ctl -D pgsql\data start - echo "POSTGRESQL_DIR=$pwd\pgsql\pgsql" >> $env:GITHUB_ENV - - - name: Check Postgres running - run: | - ${{ env.POSTGRESQL_DIR }}\bin\psql -U postgres -d postgres -c "SELECT version()" - - - name: Configure - run: | - mkdir build - cd build - cmake -DPOSTGRESQL_BIN=${{ env.POSTGRESQL_DIR }}\bin -DPOSTGRESQL_INCLUDE_DIR="${{ env.POSTGRESQL_DIR }}\include;${{ env.POSTGRESQL_DIR }}\include\server" -G"Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release -DWITH_DOC=OFF .. - env: - BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }} - - - name: build - run: | - cd build - msbuild PGROUTING.sln /target:Build /property:Configuration=Release diff --git a/include/c_common/README.md b/include/c_common/README.md deleted file mode 100644 index fe22526a1ea..00000000000 --- a/include/c_common/README.md +++ /dev/null @@ -1,19 +0,0 @@ -Purpose of this directory ----------------------------------- - -- Directory having files included exclusively by the `*.c` files - -- forbidden to be used on c++ code - - this prohibition is not enforced but will be in the future - -- Convention: - - files must end with `_input` - -Example ----------------------------------- - -in `foo.c` file -```C - #include "c_common/edges_input.h" - #include "c_common/arrays_input.h" -``` diff --git a/include/c_common/arrays_input.h b/include/c_common/arrays_input.h deleted file mode 100644 index 41e55808b76..00000000000 --- a/include/c_common/arrays_input.h +++ /dev/null @@ -1,47 +0,0 @@ -/*PGR-GNU***************************************************************** -File: arrays_input.h - -Copyright (c) 2023 Celia Virginia Vergara Castillo -Copyright (c) 2015 Celia Virginia Vergara Castillo -mail: vicky at erosion.dev - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_C_COMMON_ARRAYS_INPUT_H_ -#define INCLUDE_C_COMMON_ARRAYS_INPUT_H_ -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -/** @brief Enforces the input array to be @b NOT empty */ -int64_t* pgr_get_bigIntArray(size_t*, ArrayType*, bool); - -#ifdef __cplusplus -} -#endif - -#endif // INCLUDE_C_COMMON_ARRAYS_INPUT_H_ diff --git a/include/c_common/e_report.h b/include/c_common/e_report.h index 77f5f1e9200..96c3111adba 100644 --- a/include/c_common/e_report.h +++ b/include/c_common/e_report.h @@ -116,6 +116,10 @@ pgr_notice2( void pgr_error(char* error_msg); +/* @brief throws postgres error when first string is not null */ +void throw_error(char*, char*); + + /*! @brief error with hint * * ~~~~{.c} diff --git a/include/c_common/get_check_data.h b/include/c_common/get_check_data.h deleted file mode 100644 index 4ac63406a9c..00000000000 --- a/include/c_common/get_check_data.h +++ /dev/null @@ -1,209 +0,0 @@ -/*PGR-GNU***************************************************************** -File: get_check_data.h - -Copyright (c) 2015 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_C_COMMON_GET_CHECK_DATA_H_ -#define INCLUDE_C_COMMON_GET_CHECK_DATA_H_ -#pragma once - -#include "c_common/postgres_connection.h" -typedef struct Column_info_t Column_info_t; - -/*! - * @brief Function will check whether the colNumber represent any specific column or NULL (SPI_ERROR_NOATTRIBUTE). - * - * @param[in] colNumber Column number (count starts at 1). - * - * @return @b TRUE when colNumber exist. - * @b FALSE when colNumber was not found. - * - */ -bool column_found(int colNumber); - -/*! - * @brief Function tells expected type of each column and then check the correspondence type of each column. - * - * @throw ERROR Unknown type of column. - */ -void pgr_fetch_column_info( - Column_info_t info[], - int info_size); - -/*! - * @brief The function check whether column type is ANY-INTEGER or not. - * Where ANY-INTEGER is SQL type: - * SMALLINT, INTEGER, BIGINT - * - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected column type is ANY-INTEGER. - * - */ -void pgr_check_any_integer_type(Column_info_t info); - -/*! - * @brief The function check whether column type is ANY-NUMERICAL. - * Where ANY-NUMERICAL is SQL type: - * SMALLINT, INTEGER, BIGINT, REAL, FLOAT - * - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected column type is ANY-NUMERICAL. - * - */ -void pgr_check_any_numerical_type(Column_info_t info); - -/*! - * @brief The function check whether column type is CHAR or not. - * Where CHAR is SQL type: - * CHARACTER - * - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected column type is CHAR. - * - */ -void pgr_check_char_type(Column_info_t info); - -/*! - * @brief The function check whether column type is TEXT or not. - * Where TEXT is SQL type: - * TEXT - * - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected column type is TEXT. - * - */ -void pgr_check_text_type(Column_info_t info); -void pgr_check_boolean_type(Column_info_t info); - -/*! - * @brief The function check whether column type is ANY-INTEGER-ARRAY or not. - * Where ANY-INTEGER-ARRAY is SQL type: - * SMALLINT[], INTEGER[], BIGINT[] - * - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected ANY-INTEGER-ARRAY. - * - */ - -void pgr_check_any_integerarray_type(Column_info_t info); - -/*! - * @brief Function return the value of specified column in char type. - * - * @param[in] tuple input row to be examined. - * @param[in] tupdesc input row description. - * @param[in] info contain column information. - * @param[in] strict boolean value of strict. - * @param[in] default_value returned when column contain NULL value. - * - * @throw ERROR Unexpected Column type. Expected column type is CHAR. - * @throw ERROR When value of column is NULL. - * - * @return Char type of column value is returned. - * - */ -char pgr_SPI_getChar( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info, - bool strict, - char default_value); - -/*! - * @brief Function returns the values of specified columns in array. - * - * @param[in] tuple input row to be examined. - * @param[in] tupdesc input row description. - * @param[in] info contain column information. - * @param[out] the_size number of element in array. - * - * @throw ERROR No elements found in ARRAY. - * @throw ERROR Unexpected Column type. Expected column type is ANY-INTEGER-ARRAY. - * @throw ERROR NULL value found in Array. - * - * @return Array of columns value is returned. - * - */ - -int64_t* -pgr_SPI_getBigIntArr( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info, - uint64_t *the_size); - -/*! - * @brief Function returns the value of specified column in integer type. - * - * @param[in] tuple input row to be examined. - * @param[in] tupdesc input row description. - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected column type is ANY-INTEGER. - * @throw ERROR When value of column is NULL. - * - * @return Integer type of column value is returned. - * - */ - -int64_t pgr_SPI_getBigInt( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info); - -/*! - * @brief Function returns the value of specified column in double type. - * - * @param[in] tuple input row to be examined. - * @param[in] tupdesc input row description. - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected column type is ANY-NUMERICAL. - * @throw ERROR When value of column is NULL. - * - * @return Double type of column value is returned. - * - */ - -double pgr_SPI_getFloat8( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info); -/*! - * @brief Function returns the string representation of the value of specified column. - * - * @return Pointer of string is returned. - * - */ - -char* pgr_SPI_getText( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info); - - -#endif // INCLUDE_C_COMMON_GET_CHECK_DATA_H_ diff --git a/include/c_common/pgdata_getters.h b/include/c_common/pgdata_getters.h index a7287a3f494..682fab2d784 100644 --- a/include/c_common/pgdata_getters.h +++ b/include/c_common/pgdata_getters.h @@ -3,6 +3,13 @@ File: pgdata_getters.h Copyright (c) 2023 Celia Virginia Vergara Castillo mail: vicky at erosion.dev +Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI +mail: m_attia_sakrcw at yahoo.com, estebanzimanyicw at gmail.com +Copyright (c) 2016 Rohith Reddy +Copyright (c) 2016 Andrea Nardelli +mail: nrd.nardelli at gmail.com +Copyright (c) 2015 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev ------ @@ -26,8 +33,29 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_C_COMMON_PGDATA_GETTERS_H_ #pragma once +#ifdef __cplusplus +extern "C" { +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +#include +#include +#else #include +#include #include +#endif #ifdef __cplusplus using IID_t_rt = struct IID_t_rt; @@ -60,43 +88,54 @@ typedef struct Vehicle_t Vehicle_t; #endif +#ifdef __cplusplus +extern "C" { +#endif + /** @brief Read rows of combinations, called from C file*/ -void pgr_get_combinations(char *, II_t_rt **, size_t *); +void pgr_get_combinations(char *, II_t_rt **, size_t *, char**); /** @brief Read rows of matrix, called from C file*/ -void pgr_get_coordinates(char*, Coordinate_t**, size_t*); +void pgr_get_coordinates(char*, Coordinate_t**, size_t*, char**); /** @brief Read rows of delauny triangles, called from C file*/ -void pgr_get_delauny(char*, Delauny_t**, size_t*); +void pgr_get_delauny(char*, Delauny_t**, size_t*, char**); /** @brief Read edges called from C file*/ -void pgr_get_edges(char*, Edge_t**, size_t*, bool, bool); +void pgr_get_edges(char*, Edge_t**, size_t*, bool, bool, char**); /** @brief Read edges with x, y endpointscalled from C file */ -void pgr_get_edges_xy(char*, Edge_xy_t**, size_t*, bool); +void pgr_get_edges_xy(char*, Edge_xy_t**, size_t*, bool, char**); /** @brief Read edges for flow called from C file */ -void pgr_get_flow_edges(char*, Edge_t**, size_t*); +void pgr_get_flow_edges(char*, Edge_t**, size_t*, char**); /** @brief Read edges for cost called from C fileflow */ -void pgr_get_costFlow_edges(char*, CostFlow_t**, size_t*); +void pgr_get_costFlow_edges(char*, CostFlow_t**, size_t*, char**); /** @brief Read "basic edges" called from C file */ -void pgr_get_basic_edges(char*, Edge_bool_t**, size_t*); +void pgr_get_basic_edges(char*, Edge_bool_t**, size_t*, char**); /** @brief Read rows of matrix, called from C file*/ -void pgr_get_matrixRows(char*, IID_t_rt**, size_t *); +void pgr_get_matrixRows(char*, IID_t_rt**, size_t *, char **); /** @brief Reads the pick-Deliver orders */ -void pgr_get_orders(char *, Orders_t **, size_t *, bool); +void pgr_get_orders(char *, Orders_t **, size_t *, bool, char**); /** @brief Read rows of points, called from C file*/ -void pgr_get_points(char*, Point_on_edge_t**, size_t*); +void pgr_get_points(char*, Point_on_edge_t**, size_t*, char**); /** @brief Read rows of matrix, called from C file*/ -void pgr_get_restrictions(char*, Restriction_t**, size_t*); +void pgr_get_restrictions(char*, Restriction_t**, size_t*, char**); /** @brief Reads the vehicles */ -void pgr_get_vehicles(char*, Vehicle_t**, size_t*, bool); +void pgr_get_vehicles(char*, Vehicle_t**, size_t*, bool, char**); + +/** @brief Enforces the input array to be @b NOT empty */ +int64_t* pgr_get_bigIntArray(size_t*, ArrayType*, bool, char**); + +#ifdef __cplusplus +} +#endif #endif // INCLUDE_C_COMMON_PGDATA_GETTERS_H_ diff --git a/include/c_common/postgres_connection.h b/include/c_common/postgres_connection.h index 2f67cc5415a..c5d09e4775d 100644 --- a/include/c_common/postgres_connection.h +++ b/include/c_common/postgres_connection.h @@ -25,13 +25,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_C_COMMON_POSTGRES_CONNECTION_H_ #pragma once +#ifdef __cplusplus +extern "C" { +#endif #include #include #include -#include // for text_to_cstring +#include #include #include +#include +#include void pgr_send_error(int errcode); @@ -40,4 +45,8 @@ void pgr_SPI_connect(void); SPIPlanPtr pgr_SPI_prepare(char* sql); Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan); +#ifdef __cplusplus +} +#endif + #endif // INCLUDE_C_COMMON_POSTGRES_CONNECTION_H_ diff --git a/include/c_types/column_info_t.h b/include/c_types/info_t.hpp similarity index 75% rename from include/c_types/column_info_t.h rename to include/c_types/info_t.hpp index 120b4438dc9..6cc025519c3 100644 --- a/include/c_types/column_info_t.h +++ b/include/c_types/info_t.hpp @@ -1,8 +1,8 @@ /*PGR-GNU***************************************************************** -File: pgr_types.h +File: info_t.hpp Copyright (c) 2015 Celia Virginia Vergara Castillo -Mail: vicky_vergara@hotmail.com +Mail: vicky at erosion.dev ------ @@ -23,36 +23,32 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_C_TYPES_COLUMN_INFO_T_H_ -#define INCLUDE_C_TYPES_COLUMN_INFO_T_H_ +#ifndef INCLUDE_C_TYPES_INFO_T_HPP_ +#define INCLUDE_C_TYPES_INFO_T_HPP_ #pragma once -/* for int64_t */ -#ifdef __cplusplus -# include -#else -# include -# include -#endif - -// used for getting the data -typedef -enum { +#include +#include + +namespace pgrouting { + +enum expectType { ANY_INTEGER, ANY_NUMERICAL, TEXT, CHAR1, ANY_INTEGER_ARRAY -} expectType; +}; struct Column_info_t { int colNumber; uint64_t type; bool strict; - char *name; + std::string name; expectType eType; }; +} // namespace pgrouting -#endif // INCLUDE_C_TYPES_COLUMN_INFO_T_H_ +#endif // INCLUDE_C_TYPES_INFO_T_HPP_ diff --git a/include/c_types/spanTree_rt.h b/include/c_types/spanTree_rt.h deleted file mode 100644 index 1d31537f7be..00000000000 --- a/include/c_types/spanTree_rt.h +++ /dev/null @@ -1,45 +0,0 @@ -/*PGR-GNU***************************************************************** -File: pgr_randomSpnningTree_t.h - -Copyright (c) 2015 Aditya Pratap Singh -Mail: adityapratap.singh28@gmail.com ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ -/*! @file */ - -#ifndef INCLUDE_C_TYPES_SPANTREE_RT_H_ -#define INCLUDE_C_TYPES_SPANTREE_RT_H_ -#pragma once - - -/* for int64_t */ -#ifdef __cplusplus -# include -#else -# include -#endif - -struct SpanTree_rt { - int seq; - int64_t root_vertex; - int64_t edge; - double cost; - double tree_cost; -}; - -#endif // INCLUDE_C_TYPES_SPANTREE_RT_H_ diff --git a/include/cpp_common/get_check_data.hpp b/include/cpp_common/get_check_data.hpp new file mode 100644 index 00000000000..15f6dfe34f3 --- /dev/null +++ b/include/cpp_common/get_check_data.hpp @@ -0,0 +1,73 @@ +/*PGR-GNU***************************************************************** +File: get_check_data.hpp + +Copyright (c) 2023 Celia Virginia Vergara Castillo +vicky at erosion.dev + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + +#ifndef INCLUDE_C_COMMON_GET_CHECK_DATA_HPP_ +#define INCLUDE_C_COMMON_GET_CHECK_DATA_HPP_ +#pragma once + + +extern "C" { +#include +#include +#include +#include +} + +#include +#include +#include + + + +namespace pgrouting { +using Column_info_t = struct Column_info_t; + +/** @brief Function will check whether the colNumber represent any specific column or NULL (SPI_ERROR_NOATTRIBUTE). */ +bool column_found(int); + +/** @brief Function tells expected type of each column and then check the correspondence type of each column. */ +void fetch_column_info(const TupleDesc&, std::vector&); + +/** @brief Function return the value of specified column in char type. */ +char getChar(const HeapTuple, const TupleDesc&, const Column_info_t&, bool, char); + +/** @brief Enforces the input array to be @b NOT empty */ +int64_t* get_array(ArrayType*, size_t*, bool); + +/** @brief Function returns the values of specified columns in array. */ +int64_t* getBigIntArr(const HeapTuple, const TupleDesc&, const Column_info_t&, uint64_t*); + +/** @brief Function returns the value of specified column in integer type. */ +int64_t getBigInt(const HeapTuple, const TupleDesc&, const Column_info_t&); + +/** @brief Function returns the value of specified column in double type. */ +double getFloat8(const HeapTuple, const TupleDesc&, const Column_info_t&); + +/** @brief Function returns the string representation of the value of specified column. */ +char* getText(const HeapTuple, const TupleDesc&, const Column_info_t&); + +} // namespace pgrouting + + +#endif // INCLUDE_C_COMMON_GET_CHECK_DATA_HPP_ diff --git a/include/cpp_common/get_data.hpp b/include/cpp_common/get_data.hpp new file mode 100644 index 00000000000..d527f4a472d --- /dev/null +++ b/include/cpp_common/get_data.hpp @@ -0,0 +1,103 @@ +/*PGR-GNU***************************************************************** +File: get_data.hpp + +Copyright (c) 2023 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + +#ifndef INCLUDE_CPP_COMMON_GET_DATA_HPP_ +#define INCLUDE_CPP_COMMON_GET_DATA_HPP_ +#pragma once + +#include +#include + +#include "c_common/postgres_connection.h" +#include "c_types/info_t.hpp" +#include "cpp_common/get_check_data.hpp" +#include "cpp_common/pgr_alloc.hpp" + +namespace pgrouting { + +/** @brief Retrives the tuples + * @tparam Data_type Scructure of data + * @tparam Func fetcher function + * @param[in] sql Query to be processed + * @param[out] pgtuples C array of data + * @param[out] total_pgtuples C array size + * @param[in] flag useful flag depending on data + * @param[in] info information about the data + * @param[in] func fetcher function to be used + */ +template +void get_data( + char *sql, + Data_type **pgtuples, + size_t *total_pgtuples, + bool flag, + std::vector info, + Func func) { + const int tuple_limit = 1000000; + + size_t total_tuples; + size_t valid_pgtuples; + + auto SPIplan = pgr_SPI_prepare(sql); + auto SPIportal = pgr_SPI_cursor_open(SPIplan); + + bool moredata = true; + (*total_pgtuples) = total_tuples = valid_pgtuples = 0; + + int64_t default_id = 0; + + while (moredata == true) { + SPI_cursor_fetch(SPIportal, true, tuple_limit); + auto tuptable = SPI_tuptable; + auto tupdesc = SPI_tuptable->tupdesc; + if (total_tuples == 0) fetch_column_info(tupdesc, info); + + size_t ntuples = SPI_processed; + total_tuples += ntuples; + + if (ntuples > 0) { + (*pgtuples) = pgr_alloc(total_tuples, *pgtuples); + if ((*pgtuples) == NULL) { + throw std::string("Out of memory!"); + } + + for (size_t t = 0; t < ntuples; t++) { + func(tuptable->vals[t], tupdesc, info, + &default_id, + &(*pgtuples)[total_tuples - ntuples + t], + &valid_pgtuples, flag); + } + SPI_freetuptable(tuptable); + } else { + moredata = false; + } + } + + SPI_cursor_close(SPIportal); + (*total_pgtuples) = total_tuples; +} + +} // namespace pgrouting + +#endif // INCLUDE_CPP_COMMON_GET_DATA_HPP_ diff --git a/include/cpp_common/pgdata_fetchers.hpp b/include/cpp_common/pgdata_fetchers.hpp new file mode 100644 index 00000000000..41fc461fe65 --- /dev/null +++ b/include/cpp_common/pgdata_fetchers.hpp @@ -0,0 +1,124 @@ +/*PGR-GNU***************************************************************** +File: pgdata_fetchers.hpp + +Copyright (c) 2023 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev +Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI +mail: m_attia_sakrcw at yahoo.com, estebanzimanyicw at gmail.com +Copyright (c) 2016 Rohith Reddy +Copyright (c) 2016 Andrea Nardelli +mail: nrd.nardelli at gmail.com +Copyright (c) 2015 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + +#ifndef INCLUDE_C_COMMON_PGDATA_FETCHERS_HPP_ +#define INCLUDE_C_COMMON_PGDATA_FETCHERS_HPP_ +#pragma once + +/* for HeapTuple, TupleDesc */ +extern "C" { +#include +#include +} + +#include + +using II_t_rt = struct II_t_rt; +using IID_t_rt = struct IID_t_rt; +using Coordinate_t = struct Coordinate_t; +using Delauny_t = struct Delauny_t; +using Edge_bool_t = struct Edge_bool_t; +using Edge_t = struct Edge_t; +using CostFlow_t = struct CostFlow_t; +using Edge_xy_t = struct Edge_xy_t; +using Orders_t = struct Orders_t; +using Restriction_t = struct Restriction_t; +using Point_on_edge_t = struct Point_on_edge_t; +using Vehicle_t = struct Vehicle_t; + +namespace pgrouting { +using Column_info_t = struct Column_info_t; + +void fetch_combination( + const HeapTuple, const TupleDesc &, + const std::vector &, + int64_t*, II_t_rt*, size_t*, bool); + +void fetch_coordinate( + const HeapTuple, const TupleDesc &, + const std::vector &, + int64_t*, Coordinate_t*, size_t*, bool); + +void fetch_delauny( + const HeapTuple, const TupleDesc &, + const std::vector &, + int64_t*, Delauny_t*, size_t*, bool); + +void fetch_basic_edge( + const HeapTuple, const TupleDesc &, + const std::vector &, + int64_t*, Edge_bool_t*, size_t*, bool); + +void fetch_edge( + const HeapTuple, const TupleDesc &, + const std::vector &, + int64_t*, Edge_t*, size_t*, bool); + +void fetch_costFlow_edge( + const HeapTuple, const TupleDesc &, + const std::vector &, + int64_t*, CostFlow_t*, size_t*, bool); + +void fetch_edge_with_xy( + const HeapTuple, const TupleDesc &, + const std::vector &, + int64_t*, Edge_xy_t*, size_t*, bool); + +void pgr_fetch_row( + const HeapTuple, const TupleDesc &, + const std::vector &, + int64_t*, IID_t_rt*, size_t*, bool); + +void fetch_orders( + const HeapTuple, const TupleDesc &, + const std::vector &, + int64_t*, Orders_t*, size_t*, bool); + +void fetch_restriction( + const HeapTuple, const TupleDesc &, + const std::vector &, + int64_t*, Restriction_t*, size_t*, bool); + +void fetch_point( + const HeapTuple, const TupleDesc &, + const std::vector &, + int64_t*, Point_on_edge_t*, size_t*, bool); + +void fetch_vehicle( + const HeapTuple, const TupleDesc &, + const std::vector &, + int64_t*, Vehicle_t*, size_t*, bool); + + + +} // namespace pgrouting + +#endif // INCLUDE_C_COMMON_PGDATA_FETCHERS_HPP_ diff --git a/include/cpp_common/pgr_base_graph.hpp b/include/cpp_common/pgr_base_graph.hpp index 11f968b9a40..7fc312081a7 100644 --- a/include/cpp_common/pgr_base_graph.hpp +++ b/include/cpp_common/pgr_base_graph.hpp @@ -119,7 +119,7 @@ Vector of unique vertices of the graph ~~~~{.c} size_t total_edges; Edge_t *my_edges = NULL; -pgr_get_edges(edges_sql, &my_edges, &total_tuples); +pgr_get_edges(edges_sql, &my_edges, &total_tuples, true, false, &err_msg); std::vector< Basic_Vertex > vertices(pgrouting::extract_vertices(my_edges)); ~~~~ There are several ways to initialize the graph diff --git a/src/allpairs/floydWarshall.c b/src/allpairs/floydWarshall.c index 662df0c5ea3..e55162cc5da 100644 --- a/src/allpairs/floydWarshall.c +++ b/src/allpairs/floydWarshall.c @@ -51,11 +51,15 @@ process( IID_t_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; PGR_DBG("Load data"); Edge_t *edges = NULL; size_t total_tuples = 0; - pgr_get_edges(edges_sql, &edges, &total_tuples, true, true); + pgr_get_edges(edges_sql, &edges, &total_tuples, true, true, &err_msg); + throw_error(err_msg, edges_sql); if (total_tuples == 0) { PGR_DBG("No edges found"); @@ -68,9 +72,6 @@ process( clock_t start_t = clock(); PGR_DBG("Starting processing"); - char *err_msg = NULL; - char *notice_msg = NULL; - char *log_msg = NULL; do_pgr_floydWarshall( edges, total_tuples, diff --git a/src/allpairs/johnson.c b/src/allpairs/johnson.c index aef0b295920..274498271f0 100644 --- a/src/allpairs/johnson.c +++ b/src/allpairs/johnson.c @@ -50,11 +50,15 @@ void process( IID_t_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; PGR_DBG("Load data"); Edge_t *edges = NULL; size_t total_tuples = 0; - pgr_get_edges(edges_sql, &edges, &total_tuples, true, true); + pgr_get_edges(edges_sql, &edges, &total_tuples, true, true, &err_msg); + throw_error(err_msg, edges_sql); if (total_tuples == 0) { PGR_DBG("No edges found"); @@ -66,9 +70,6 @@ void process( PGR_DBG("Total %ld tuples in query:", total_tuples); PGR_DBG("Starting processing"); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; clock_t start_t = clock(); do_pgr_johnson( edges, diff --git a/src/alpha_shape/alphaShape.c b/src/alpha_shape/alphaShape.c index 1f9d6cf6122..adfd674bd6a 100644 --- a/src/alpha_shape/alphaShape.c +++ b/src/alpha_shape/alphaShape.c @@ -46,11 +46,15 @@ static void process( GeomText_t **res, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; Edge_xy_t *edgesArr = NULL; size_t edgesSize = 0; - pgr_get_edges_xy(edges_sql, &edgesArr, &edgesSize, true); + pgr_get_edges_xy(edges_sql, &edgesArr, &edgesSize, true, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("total edges %ld", edgesSize); PGR_DBG("alpha %f", alpha); @@ -71,9 +75,6 @@ static void process( PGR_DBG("Calling alpha-shape driver\n"); - char *err_msg = NULL; - char* log_msg = NULL; - char* notice_msg = NULL; do_alphaShape( edgesArr, edgesSize, diff --git a/src/astar/astar.c b/src/astar/astar.c index 580302e11f5..343d76cb09e 100644 --- a/src/astar/astar.c +++ b/src/astar/astar.c @@ -35,7 +35,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "c_common/check_parameters.h" @@ -85,6 +84,9 @@ process(char* edges_sql, check_parameters(heuristic, factor, epsilon); pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; int64_t* start_vidsArr = NULL; size_t size_start_vidsArr = 0; @@ -99,21 +101,24 @@ process(char* edges_sql, size_t total_combinations = 0; if (normal) { - pgr_get_edges_xy(edges_sql, &edges, &total_edges, true); + pgr_get_edges_xy(edges_sql, &edges, &total_edges, true, &err_msg); + throw_error(err_msg, edges_sql); if (starts && ends) { - start_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_vidsArr, starts, false); - end_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_vidsArr, ends, false); + start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); } } else { - pgr_get_edges_xy(edges_sql, &edges, &total_edges, false); - end_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_vidsArr, starts, false); - start_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_vidsArr, ends, false); + pgr_get_edges_xy(edges_sql, &edges, &total_edges, false, &err_msg); + throw_error(err_msg, edges_sql); + end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } if (total_edges == 0) { @@ -125,9 +130,6 @@ process(char* edges_sql, } PGR_DBG("Starting processing"); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; clock_t start_t = clock(); do_pgr_astarManyToMany( edges, total_edges, diff --git a/src/bdAstar/bdAstar.c b/src/bdAstar/bdAstar.c index c5683c308a6..7303cb25e76 100644 --- a/src/bdAstar/bdAstar.c +++ b/src/bdAstar/bdAstar.c @@ -29,14 +29,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "c_common/check_parameters.h" @@ -65,6 +63,9 @@ process(char* edges_sql, check_parameters(heuristic, factor, epsilon); pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; int64_t* start_vidsArr = NULL; size_t size_start_vidsArr = 0; @@ -76,18 +77,20 @@ process(char* edges_sql, size_t total_combinations = 0; if (starts && ends) { - start_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_vidsArr, starts, false); - end_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_vidsArr, ends, false); + start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); } Edge_xy_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges_xy(edges_sql, &edges, &total_edges, true); + pgr_get_edges_xy(edges_sql, &edges, &total_edges, true, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -99,9 +102,6 @@ process(char* edges_sql, } PGR_DBG("Starting processing"); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; clock_t start_t = clock(); do_pgr_bdAstar( edges, total_edges, diff --git a/src/bdDijkstra/bdDijkstra.c b/src/bdDijkstra/bdDijkstra.c index a671d15f7be..642256ba9a9 100644 --- a/src/bdDijkstra/bdDijkstra.c +++ b/src/bdDijkstra/bdDijkstra.c @@ -30,14 +30,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" + #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/bdDijkstra/bdDijkstra_driver.h" @@ -60,6 +59,9 @@ process( Path_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; int64_t* start_vidsArr = NULL; size_t size_start_vidsArr = 0; @@ -74,15 +76,17 @@ process( size_t total_combinations = 0; if (starts && ends) { - start_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_vidsArr, starts, false); - end_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_vidsArr, ends, false); + start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); } - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -93,9 +97,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_bdDijkstra( edges, total_edges, combinations, total_combinations, diff --git a/src/bellman_ford/bellman_ford.c b/src/bellman_ford/bellman_ford.c index ae55fdcc680..251ec7b4488 100644 --- a/src/bellman_ford/bellman_ford.c +++ b/src/bellman_ford/bellman_ford.c @@ -30,14 +30,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/bellman_ford/bellman_ford_driver.h" @@ -58,6 +56,9 @@ process( Path_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; PGR_DBG("Initializing arrays"); @@ -71,12 +72,13 @@ process( II_t_rt *combinations = NULL; if (starts && ends) { - start_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_vidsArr, starts, false); - end_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_vidsArr, ends, false); + start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); if (total_combinations == 0) { if (combinations) pfree(combinations); @@ -92,7 +94,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -104,9 +107,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_bellman_ford( edges, total_edges, diff --git a/src/bellman_ford/bellman_ford_neg.c b/src/bellman_ford/bellman_ford_neg.c index 10f711cc0fe..e266113013c 100644 --- a/src/bellman_ford/bellman_ford_neg.c +++ b/src/bellman_ford/bellman_ford_neg.c @@ -30,13 +30,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/bellman_ford/bellman_ford_neg_driver.h" // the link to the C++ code of the function @@ -58,6 +56,9 @@ process( Path_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; PGR_DBG("Initializing arrays"); @@ -76,7 +77,8 @@ process( end_vidsArr = (int64_t*) pgr_get_bigIntArray(&size_end_vidsArr, ends, false); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); if (total_combinations == 0) { if (combinations) pfree(combinations); @@ -92,7 +94,8 @@ process( Edge_t *positive_edges = NULL; size_t total_positive_edges = 0; - pgr_get_edges(edges_sql, &positive_edges, &total_positive_edges, true, false); + pgr_get_edges(edges_sql, &positive_edges, &total_positive_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG( "Total positive weighted edges in query: %ld", total_positive_edges); @@ -100,7 +103,8 @@ process( Edge_t *negative_edges = NULL; size_t total_negative_edges = 0; - pgr_get_edges(neg_edges_sql, &negative_edges, &total_negative_edges, true, false); + pgr_get_edges(neg_edges_sql, &negative_edges, &total_negative_edges, true, false, &err_msg); + throw_error(err_msg, neg_edges_sql); PGR_DBG( "Total negative weighted edges in query: %ld", total_negative_edges); @@ -116,9 +120,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_bellman_ford_neg( positive_edges, total_positive_edges, diff --git a/src/bellman_ford/edwardMoore.c b/src/bellman_ford/edwardMoore.c index c3a07924fd1..f44617d4e34 100644 --- a/src/bellman_ford/edwardMoore.c +++ b/src/bellman_ford/edwardMoore.c @@ -30,14 +30,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/bellman_ford/edwardMoore_driver.h" @@ -56,6 +54,9 @@ process( Path_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; PGR_DBG("Initializing arrays"); @@ -69,12 +70,13 @@ process( II_t_rt *combinations = NULL; if (starts && ends) { - start_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_vidsArr, starts, false); - end_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_vidsArr, ends, false); + start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); if (total_combinations == 0) { if (combinations) pfree(combinations); @@ -90,7 +92,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -104,9 +107,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_edwardMoore( edges, total_edges, diff --git a/src/breadthFirstSearch/binaryBreadthFirstSearch.c b/src/breadthFirstSearch/binaryBreadthFirstSearch.c index c904907bf39..a68e703eafe 100644 --- a/src/breadthFirstSearch/binaryBreadthFirstSearch.c +++ b/src/breadthFirstSearch/binaryBreadthFirstSearch.c @@ -30,14 +30,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/breadthFirstSearch/binaryBreadthFirstSearch_driver.h" @@ -56,6 +54,9 @@ process( Path_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; PGR_DBG("Initializing arrays"); @@ -69,12 +70,13 @@ process( II_t_rt *combinations = NULL; if (starts && ends) { - start_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_vidsArr, starts, false); - end_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_vidsArr, ends, false); + start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); if (total_combinations == 0) { if (combinations) pfree(combinations); @@ -90,7 +92,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -104,9 +107,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_binaryBreadthFirstSearch( edges, total_edges, diff --git a/src/breadthFirstSearch/breadthFirstSearch.c b/src/breadthFirstSearch/breadthFirstSearch.c index 83b4749297b..4c6f4c9f133 100644 --- a/src/breadthFirstSearch/breadthFirstSearch.c +++ b/src/breadthFirstSearch/breadthFirstSearch.c @@ -30,13 +30,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "c_types/mst_rt.h" @@ -56,12 +54,15 @@ process( MST_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; PGR_DBG("Initializing arrays"); size_t size_start_vidsArr = 0; - int64_t *start_vidsArr = (int64_t *) - pgr_get_bigIntArray(&size_start_vidsArr, starts, false); + int64_t *start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); PGR_DBG("start_vidsArr size %ld ", size_start_vidsArr); @@ -72,7 +73,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -84,9 +86,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_breadthFirstSearch( edges, total_edges, diff --git a/src/chinese/chinesePostman.c b/src/chinese/chinesePostman.c index 0c17f5f4095..8a75303e2aa 100644 --- a/src/chinese/chinesePostman.c +++ b/src/chinese/chinesePostman.c @@ -54,11 +54,15 @@ process( Path_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); @@ -66,9 +70,6 @@ process( } clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_directedChPP( edges, total_edges, diff --git a/src/circuits/hawickCircuits.c b/src/circuits/hawickCircuits.c index 7d0c5c5cd09..31dd2bb77c8 100644 --- a/src/circuits/hawickCircuits.c +++ b/src/circuits/hawickCircuits.c @@ -63,6 +63,9 @@ process( circuits_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; (*result_tuples) = NULL; (*result_count) = 0; @@ -70,7 +73,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); return; @@ -78,9 +82,6 @@ process( PGR_DBG("Starting timer"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_hawickCircuits( edges, total_edges, diff --git a/src/coloring/bipartite.c b/src/coloring/bipartite.c index 92f613a93fc..4f575e5dfee 100644 --- a/src/coloring/bipartite.c +++ b/src/coloring/bipartite.c @@ -52,10 +52,14 @@ process(char* edges_sql, II_t_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; size_t total_edges = 0; Edge_t* edges = NULL; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); return; @@ -63,9 +67,6 @@ process(char* edges_sql, PGR_DBG("Starting timer"); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_bipartite( edges, total_edges, result_tuples, result_count, diff --git a/src/coloring/edgeColoring.c b/src/coloring/edgeColoring.c index 7a5d27aa23b..618220cf24f 100644 --- a/src/coloring/edgeColoring.c +++ b/src/coloring/edgeColoring.c @@ -67,6 +67,9 @@ process( II_t_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; (*result_tuples) = NULL; (*result_count) = 0; @@ -74,7 +77,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { ereport(WARNING, @@ -87,9 +91,6 @@ process( } clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_edgeColoring( edges, total_edges, diff --git a/src/coloring/sequentialVertexColoring.c b/src/coloring/sequentialVertexColoring.c index aac452ba49d..3d266bfbd52 100644 --- a/src/coloring/sequentialVertexColoring.c +++ b/src/coloring/sequentialVertexColoring.c @@ -33,7 +33,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" @@ -68,6 +67,9 @@ process( II_t_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; (*result_tuples) = NULL; (*result_count) = 0; @@ -75,12 +77,10 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_sequentialVertexColoring( edges, total_edges, diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 1f5386302fd..0d9cce841db 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,23 +1,8 @@ ADD_LIBRARY(common OBJECT postgres_connection.c e_report.c - #restrict_input.c basePath_SSEC.cpp - points_input.c - matrixRows_input.c - get_check_data.c - edges_input.c - combinations_input.c - orders_input.c - orders_input.c - vehicles_input.c - - restrictions_input.c - - coordinates_input.c - delauny_input.c - check_parameters.c time_msg.c diff --git a/src/common/combinations_input.c b/src/common/combinations_input.c deleted file mode 100644 index 7606f6b3e98..00000000000 --- a/src/common/combinations_input.c +++ /dev/null @@ -1,155 +0,0 @@ -/*PGR-GNU***************************************************************** -File: combinations_input.c - -Generated with Template by: -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI -mail: m_attia_sakr@yahoo.com, estebanzimanyi@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - - -#include -#include -#include -#ifdef __cplusplus -# include -#else -# include -#endif - -#include "c_common/pgdata_getters.h" -#include "c_types/column_info_t.h" -#include "c_types/ii_t_rt.h" -#include "c_common/debug_macro.h" -#include "c_common/get_check_data.h" -#include "c_common/time_msg.h" - - -static -void fetch_combination( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[2], - II_t_rt *combination, - size_t *valid_combinations) { - combination->d1.source = pgr_SPI_getBigInt(tuple, tupdesc, info[0]); - combination->d2.target = pgr_SPI_getBigInt(tuple, tupdesc, info[1]); - - *valid_combinations = *valid_combinations + 1; -} - - - -static -void -get_combinations_2_columns( - char *sql, - II_t_rt **combinations, - size_t *totalTuples) { - clock_t start_t = clock(); - - const int tuple_limit = 1000000; - - size_t total_tuples; - size_t valid_combinations; - - Column_info_t info[2]; - - int i; - for (i = 0; i < 2; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - info[0].name = "source"; - info[1].name = "target"; - - void *SPIplan; - SPIplan = pgr_SPI_prepare(sql); - - Portal SPIportal; - SPIportal = pgr_SPI_cursor_open(SPIplan); - - - bool moredata = true; - (*totalTuples) = total_tuples = valid_combinations = 0; - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) - pgr_fetch_column_info(info, 2); - - size_t ntuples = SPI_processed; - total_tuples += ntuples; - - if (ntuples > 0) { - if ((*combinations) == NULL) - (*combinations) = (II_t_rt *) - palloc0(total_tuples * sizeof(II_t_rt)); - else - (*combinations) = (II_t_rt *) - repalloc((*combinations), total_tuples * sizeof(II_t_rt)); - - if ((*combinations) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_combination(&tuple, &tupdesc, info, - &(*combinations)[total_tuples - ntuples + t], - &valid_combinations); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0 || valid_combinations == 0) { - PGR_DBG("No combinations found"); - } - - (*totalTuples) = total_tuples; - PGR_DBG("Reading %ld combinations", total_tuples); - time_msg("reading combinations", start_t, clock()); -} - -/** - * @param [in] combinations_sql - * @param [out] combinations II_t_rt - * @param [out] total_combinations - */ -void -pgr_get_combinations( - char *combinations_sql, - II_t_rt **combinations, - size_t *total_combinations) { - get_combinations_2_columns(combinations_sql, combinations, total_combinations); -} diff --git a/src/common/coordinates_input.c b/src/common/coordinates_input.c deleted file mode 100644 index ceabad22772..00000000000 --- a/src/common/coordinates_input.c +++ /dev/null @@ -1,162 +0,0 @@ -/*PGR-GNU***************************************************************** -File: coordindates_input.c - -Copyright (c) 2015 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/pgdata_getters.h" - -#include "c_types/column_info_t.h" -#include "c_types/coordinate_t.h" -#include "c_common/debug_macro.h" -#include "c_common/get_check_data.h" -#include "c_common/time_msg.h" - -/* - -.. Coordinates SQL definition start - -========= ================= ================================================= -Column Type Description -========= ================= ================================================= -``id`` ``ANY-INTEGER`` Identifier of the starting vertex. -``x`` ``ANY-NUMERICAL`` X value of the coordinate. -``y`` ``ANY-NUMERICAL`` Y value of the coordinate. -========= ================= ================================================= - -.. Coordinates SQL definition end - -*/ - - - - -static -void pgr_fetch_row( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[3], - int64_t *default_id, - Coordinate_t *distance) { - if (column_found(info[0].colNumber)) { - distance->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]); - } else { - distance->id = *default_id; - ++(*default_id); - } - distance->x = pgr_SPI_getFloat8(tuple, tupdesc, info[1]); - distance->y = pgr_SPI_getFloat8(tuple, tupdesc, info[2]); -} - -/*! - * bigint id, - * float x, - * float y, - */ -void pgr_get_coordinates( - char *sql, - Coordinate_t **coordinates, - size_t *total_coordinates) { - clock_t start_t = clock(); - - const int tuple_limit = 1000000; - - size_t total_tuples = 0; - - Column_info_t info[3]; - - int i; - for (i = 0; i < 3; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_NUMERICAL; - } - info[0].name = "id"; - info[1].name = "x"; - info[2].name = "y"; - - info[0].eType = ANY_INTEGER; - info[0].strict = false; - - - void *SPIplan; - SPIplan = pgr_SPI_prepare(sql); - - Portal SPIportal; - SPIportal = pgr_SPI_cursor_open(SPIplan); - - - bool moredata = true; - (*total_coordinates) = total_tuples; - - int64_t default_id = 1; - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) - pgr_fetch_column_info(info, 3); - - size_t ntuples = SPI_processed; - total_tuples += ntuples; - - if (ntuples > 0) { - if ((*coordinates) == NULL) - (*coordinates) = (Coordinate_t *) - palloc0(total_tuples * sizeof(Coordinate_t)); - else - (*coordinates) = (Coordinate_t *) - repalloc((*coordinates), - total_tuples * sizeof(Coordinate_t)); - - if ((*coordinates) == NULL) { - elog(ERROR, "Out of memory"); - } - - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - PGR_DBG("Processing %ld coordinates tupĺes", ntuples); - - size_t t; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - pgr_fetch_row(&tuple, &tupdesc, info, - &default_id, - &(*coordinates)[total_tuples - ntuples + t]); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - - if (total_tuples == 0) { - (*total_coordinates) = 0; - PGR_DBG("NO coordinates"); - return; - } - - (*total_coordinates) = total_tuples; - time_msg(" reading coordinates:", start_t, clock()); -} diff --git a/src/common/delauny_input.c b/src/common/delauny_input.c deleted file mode 100644 index 750db601d53..00000000000 --- a/src/common/delauny_input.c +++ /dev/null @@ -1,137 +0,0 @@ -/*PGR-GNU***************************************************************** -File: delauny_input.c - -Copyright (c) 2018 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/pgdata_getters.h" -#include "c_types/column_info_t.h" -#include "c_types/delauny_t.h" - -#include "c_common/debug_macro.h" -#include "c_common/get_check_data.h" -#include "c_common/time_msg.h" - - - -static -void pgr_fetch_row( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[4], - Delauny_t *delauny) { - delauny->tid = pgr_SPI_getBigInt(tuple, tupdesc, info[0]); - delauny->pid = pgr_SPI_getBigInt(tuple, tupdesc, info[1]); - delauny->x = pgr_SPI_getFloat8(tuple, tupdesc, info[2]); - delauny->y = pgr_SPI_getFloat8(tuple, tupdesc, info[3]); -} - -/*! - * bigint tid, - * bigint pid, - * float x, - * float y, - */ -void pgr_get_delauny( - char *sql, - Delauny_t **delauny, - size_t *total_delauny) { - clock_t start_t = clock(); - - const int tuple_limit = 1000000; - - size_t total_tuples = 0; - - Column_info_t info[4]; - - int i; - for (i = 0; i < 4; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_NUMERICAL; - } - info[0].name = "tid"; - info[1].name = "pid"; - info[2].name = "x"; - info[3].name = "y"; - - info[0].eType = ANY_INTEGER; - info[1].eType = ANY_INTEGER; - - void *SPIplan; - SPIplan = pgr_SPI_prepare(sql); - - Portal SPIportal; - SPIportal = pgr_SPI_cursor_open(SPIplan); - - - bool moredata = true; - (*total_delauny) = total_tuples; - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) - pgr_fetch_column_info(info, 4); - - size_t ntuples = SPI_processed; - total_tuples += ntuples; - - if (ntuples > 0) { - if ((*delauny) == NULL) - (*delauny) = (Delauny_t *) - palloc0(total_tuples * sizeof(Delauny_t)); - else - (*delauny) = (Delauny_t *) - repalloc((*delauny), - total_tuples * sizeof(Delauny_t)); - - if ((*delauny) == NULL) { - elog(ERROR, "Out of memory"); - } - - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - - size_t t; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - pgr_fetch_row(&tuple, &tupdesc, info, - &(*delauny)[total_tuples - ntuples + t]); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - - if (total_tuples == 0) { - (*total_delauny) = 0; - return; - } - - (*total_delauny) = total_tuples; - PGR_DBG("%ld", total_tuples); - time_msg(" calculating Delauny triangles:", start_t, clock()); -} diff --git a/src/common/e_report.c b/src/common/e_report.c index 53728df6aa5..949bdef39f4 100644 --- a/src/common/e_report.c +++ b/src/common/e_report.c @@ -68,6 +68,20 @@ pgr_error(char* err) { } } +/** + * @param[in] err string with an error message + * @param[in] hint string with the hint to be used + * + * Generates an ERROR on postgres when err in not null + */ +void +throw_error(char *err, char *hint) { + if (err) { + ereport(ERROR, (errmsg("%s", err), errhint("%s", hint))); + } +} + + void pgr_error2( char* log, diff --git a/src/common/edges_input.c b/src/common/edges_input.c deleted file mode 100644 index 2ecbdb25096..00000000000 --- a/src/common/edges_input.c +++ /dev/null @@ -1,758 +0,0 @@ -/*PGR-GNU***************************************************************** -File: edges_input.c - -Copyright (c) 2015 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - - -#include -#include -#include -/* for size-t */ -#ifdef __cplusplus -# include -#else -# include -#endif - -#include "c_common/pgdata_getters.h" -#include "c_common/arrays_input.h" -#include "c_types/column_info_t.h" -#include "c_types/edge_bool_t_rt.h" -#include "c_types/costFlow_t.h" -#include "c_types/edge_xy_t.h" -#include "c_types/flow_t.h" -#include "c_types/edge_t.h" - -#include "c_common/debug_macro.h" -#include "c_common/get_check_data.h" -#include "c_common/time_msg.h" - - -/* - * Only for undirected graph, without weights on the costs -*/ -static -void fetch_basic_edge( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[7], - int64_t *default_id, - Edge_bool_t *edge, - size_t *valid_edges) { - if (column_found(info[0].colNumber)) { - edge->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]); - } else { - edge->id = *default_id; - ++(*default_id); - } - bool new_columns = column_found(info[5].colNumber); - - edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[1]); - edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[2]); - - if (new_columns) { - edge->going = pgr_SPI_getFloat8(tuple, tupdesc, info[5]) > 0 - || (column_found(info[6].colNumber) - && pgr_SPI_getFloat8(tuple, tupdesc, info[6]) > 0); - } else { - edge->going = pgr_SPI_getFloat8(tuple, tupdesc, info[3]) > 0 - || (column_found(info[4].colNumber) - && pgr_SPI_getFloat8(tuple, tupdesc, info[4]) > 0); - } - - (*valid_edges)++; -} - -static -void fetch_edge( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[5], - int64_t *default_id, - float8 default_rcost, - Edge_t *edge, - size_t *valid_edges, - bool normal) { - if (column_found(info[0].colNumber)) { - edge->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]); - } else { - edge->id = *default_id; - ++(*default_id); - } - - if (normal) { - edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[1]); - edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[2]); - } else { - edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[1]); - edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[2]); - } - - edge->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[3]); - - if (column_found(info[4].colNumber)) { - edge->reverse_cost = pgr_SPI_getFloat8(tuple, tupdesc, info[4]); - } else { - edge->reverse_cost = default_rcost; - } - - edge->cost = isinf(edge->cost)? - DBL_MAX : edge->cost; - - edge->reverse_cost = isinf(edge->reverse_cost)? - DBL_MAX : edge->reverse_cost; - - *valid_edges = edge->cost < 0? *valid_edges: *valid_edges + 1; - *valid_edges = edge->reverse_cost < 0? *valid_edges: *valid_edges + 1; -} - -static -void fetch_costFlow_edge( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[7], - int64_t *default_id, - int64_t default_rcapacity, - float8 default_rcost, - CostFlow_t *edge, - size_t *valid_edges, - bool normal) { - if (column_found(info[0].colNumber)) { - edge->edge_id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]); - } else { - edge->edge_id = *default_id; - ++(*default_id); - } - - if (normal) { - edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[1]); - edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[2]); - } else { - edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[1]); - edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[2]); - } - - edge->capacity = pgr_SPI_getBigInt(tuple, tupdesc, info[3]); - if (column_found(info[4].colNumber)) { - edge->reverse_capacity = pgr_SPI_getBigInt(tuple, tupdesc, info[4]); - } else { - edge->reverse_capacity = default_rcapacity; - } - - edge->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[5]); - if (column_found(info[6].colNumber)) { - edge->reverse_cost = pgr_SPI_getFloat8(tuple, tupdesc, info[6]); - } else { - edge->reverse_cost = default_rcost; - } - - *valid_edges = edge->capacity < 0? *valid_edges: *valid_edges + 1; - *valid_edges = edge->reverse_capacity < 0? *valid_edges: *valid_edges + 1; -} - -static -void fetch_edge_with_xy( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[9], - int64_t *default_id, - float8 default_rcost, - Edge_xy_t *edge, - size_t *valid_edges, - bool normal) { - if (column_found(info[0].colNumber)) { - edge->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]); - } else { - edge->id = *default_id; - ++(*default_id); - } - - if (normal) { - edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[1]); - edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[2]); - } else { - edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[1]); - edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[2]); - } - edge->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[3]); - - if (column_found(info[4].colNumber)) { - edge->reverse_cost = pgr_SPI_getFloat8(tuple, tupdesc, info[4]); - } else { - edge->reverse_cost = default_rcost; - } - - edge->x1 = pgr_SPI_getFloat8(tuple, tupdesc, info[5]); - edge->y1 = pgr_SPI_getFloat8(tuple, tupdesc, info[6]); - edge->x2 = pgr_SPI_getFloat8(tuple, tupdesc, info[7]); - edge->y2 = pgr_SPI_getFloat8(tuple, tupdesc, info[8]); -#if 0 - PGR_DBG("%ld", edge->id); - PGR_DBG("x1=%f y1=%.15lf", edge->x1, edge->y1); - PGR_DBG("x2=%f y2=%.15lf", edge->x2, edge->y2); -#endif - - - *valid_edges = edge->cost < 0? *valid_edges: *valid_edges + 1; - *valid_edges = edge->reverse_cost < 0? *valid_edges: *valid_edges + 1; -} - -static -void -get_edges_9_columns( - char *sql, - Edge_xy_t **edges, - size_t *total_edges, - bool normal) { - clock_t start_t = clock(); - - const int tuple_limit = 1000000; - - size_t total_tuples; - size_t valid_edges; - - Column_info_t info[9]; - - info[0].name = "id"; - info[1].name = "source"; - info[2].name = "target"; - info[3].name = "cost"; - info[4].name = "reverse_cost"; - info[5].name = "x1"; - info[6].name = "y1"; - info[7].name = "x2"; - info[8].name = "y2"; - - int i; - for (i = 0; i < 3; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - for (i = 3; i < 9; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_NUMERICAL; - } - /* - * reverse_cost is optional - */ - info[4].strict = false; - - - void *SPIplan; - SPIplan = pgr_SPI_prepare(sql); - - Portal SPIportal; - SPIportal = pgr_SPI_cursor_open(SPIplan); - - - bool moredata = true; - (*total_edges) = total_tuples = valid_edges = 0; - - - int64_t default_id = 0; - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) - pgr_fetch_column_info(info, 9); - - size_t ntuples = SPI_processed; - total_tuples += ntuples; - - if (ntuples > 0) { - if ((*edges) == NULL) - (*edges) = (Edge_xy_t *) - palloc0(total_tuples * sizeof(Edge_xy_t)); - else - (*edges) = (Edge_xy_t *) - repalloc((*edges), total_tuples * sizeof(Edge_xy_t)); - - if ((*edges) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_edge_with_xy(&tuple, &tupdesc, info, - &default_id, -1, - &(*edges)[total_tuples - ntuples + t], - &valid_edges, normal); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0 || valid_edges == 0) { - PGR_DBG("No edges found"); - } - - (*total_edges) = total_tuples; - time_msg("reading edges", start_t, clock()); -} - - - -static -void -get_edges_5_columns( - char *sql, - Edge_t **edges, - size_t *totalTuples, - bool ignore_id, - bool normal) { - clock_t start_t = clock(); - - const int tuple_limit = 1000000; - - size_t total_tuples; - size_t valid_edges; - - Column_info_t info[5]; - - int i; - for (i = 0; i < 5; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - info[0].name = "id"; - info[1].name = "source"; - info[2].name = "target"; - info[3].name = "cost"; - info[4].name = "reverse_cost"; - - info[0].strict = !ignore_id; - info[4].strict = false; - - info[3].eType = ANY_NUMERICAL; - info[4].eType = ANY_NUMERICAL; - - - void *SPIplan; - SPIplan = pgr_SPI_prepare(sql); - - Portal SPIportal; - SPIportal = pgr_SPI_cursor_open(SPIplan); - - - bool moredata = true; - (*totalTuples) = total_tuples = valid_edges = 0; - - - int64_t default_id = 0; - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) - pgr_fetch_column_info(info, 5); - - size_t ntuples = SPI_processed; - total_tuples += ntuples; - - if (ntuples > 0) { - if ((*edges) == NULL) - (*edges) = (Edge_t *) - palloc0(total_tuples * sizeof(Edge_t)); - else - (*edges) = (Edge_t *) - repalloc((*edges), total_tuples * sizeof(Edge_t)); - - if ((*edges) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_edge(&tuple, &tupdesc, info, - &default_id, -1, - &(*edges)[total_tuples - ntuples + t], - &valid_edges, - normal); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0 || valid_edges == 0) { - PGR_DBG("No edges found"); - } - - (*totalTuples) = total_tuples; - time_msg("reading edges", start_t, clock()); -} - -static -void -get_edges_flow( - char *sql, - Edge_t **edges, - size_t *totalTuples, - bool ignore_id) { - clock_t start_t = clock(); - - const int tuple_limit = 1000000; - - size_t total_tuples; - size_t valid_edges; - - Column_info_t info[5]; - - int i; - for (i = 0; i < 5; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - info[0].name = "id"; - info[1].name = "source"; - info[2].name = "target"; - info[3].name = "capacity"; - info[4].name = "reverse_capacity"; - - info[0].strict = !ignore_id; - info[4].strict = false; - - void *SPIplan; - SPIplan = pgr_SPI_prepare(sql); - - Portal SPIportal; - SPIportal = pgr_SPI_cursor_open(SPIplan); - - - bool moredata = true; - (*totalTuples) = total_tuples = valid_edges = 0; - - - int64_t default_id = 0; - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) - pgr_fetch_column_info(info, 5); - - size_t ntuples = SPI_processed; - total_tuples += ntuples; - - if (ntuples > 0) { - if ((*edges) == NULL) - (*edges) = (Edge_t *) - palloc0(total_tuples * sizeof(Flow_t)); - else - (*edges) = (Edge_t *) - repalloc((*edges), total_tuples * sizeof(Flow_t)); - - if ((*edges) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_edge(&tuple, &tupdesc, info, - &default_id, -1, - &(*edges)[total_tuples - ntuples + t], - &valid_edges, - true); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0 || valid_edges == 0) { - PGR_DBG("No edges found"); - } - - (*totalTuples) = total_tuples; - time_msg("Reading edges", start_t, clock()); -} - -static -void -get_edges_costFlow( - char *sql, - CostFlow_t **edges, - size_t *totalTuples, - bool ignore_id) { - clock_t start_t = clock(); - - const int tuple_limit = 1000000; - - size_t total_tuples; - size_t valid_edges; - - Column_info_t info[7]; - - int i; - for (i = 0; i < 5; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - info[0].name = "id"; - info[1].name = "source"; - info[2].name = "target"; - info[3].name = "capacity"; - info[4].name = "reverse_capacity"; - info[5].name = "cost"; - info[6].name = "reverse_cost"; - - info[0].strict = !ignore_id; - info[4].strict = false; - info[6].strict = false; - - info[5].eType = ANY_NUMERICAL; - info[6].eType = ANY_NUMERICAL; - - void *SPIplan; - SPIplan = pgr_SPI_prepare(sql); - - Portal SPIportal; - SPIportal = pgr_SPI_cursor_open(SPIplan); - - - bool moredata = true; - (*totalTuples) = total_tuples = valid_edges = 0; - - - int64_t default_id = 0; - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) - pgr_fetch_column_info(info, 7); - - size_t ntuples = SPI_processed; - total_tuples += ntuples; - - if (ntuples > 0) { - if ((*edges) == NULL) - (*edges) = (CostFlow_t *) - palloc0(total_tuples * sizeof(CostFlow_t)); - else - (*edges) = (CostFlow_t *) - repalloc((*edges), total_tuples * sizeof(CostFlow_t)); - - if ((*edges) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_costFlow_edge(&tuple, &tupdesc, info, - &default_id, -1, 0, - &(*edges)[total_tuples - ntuples + t], - &valid_edges, - true); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0 || valid_edges == 0) { - PGR_DBG("No edges found"); - } - - (*totalTuples) = total_tuples; - time_msg("reading edges", start_t, clock()); -} - -static -void -get_edges_basic( - char *sql, - Edge_bool_t **edges, - size_t *totalTuples, - bool ignore_id) { - clock_t start_t = clock(); - - const int tuple_limit = 1000000; - - size_t total_tuples; - size_t valid_edges; - - Column_info_t info[7]; - - int i; - for (i = 0; i < 7; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - info[0].name = "id"; - info[1].name = "source"; - info[2].name = "target"; - info[3].name = "going"; - info[4].name = "coming"; - info[5].name = "cost"; - info[6].name = "reverse_cost"; - - info[0].strict = !ignore_id; - info[3].strict = false; - info[4].strict = false; - info[5].strict = false; - info[6].strict = false; - - info[3].eType = ANY_NUMERICAL; - info[4].eType = ANY_NUMERICAL; - info[5].eType = ANY_NUMERICAL; - info[6].eType = ANY_NUMERICAL; - - - void *SPIplan; - SPIplan = pgr_SPI_prepare(sql); - - Portal SPIportal; - SPIportal = pgr_SPI_cursor_open(SPIplan); - - - bool moredata = true; - (*totalTuples) = total_tuples = valid_edges = 0; - - - int64_t default_id = 0; - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) - pgr_fetch_column_info(info, 7); - - size_t ntuples = SPI_processed; - total_tuples += ntuples; - - if (ntuples > 0) { - if ((*edges) == NULL) - (*edges) = (Edge_bool_t *)palloc0( - total_tuples * sizeof(Edge_bool_t)); - else - (*edges) = (Edge_bool_t *)repalloc( - (*edges), total_tuples * sizeof(Edge_bool_t)); - - if ((*edges) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_basic_edge(&tuple, &tupdesc, info, - &default_id, - &(*edges)[total_tuples - ntuples + t], - &valid_edges); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0 || valid_edges == 0) { - PGR_DBG("No edges found"); - } - - (*totalTuples) = total_tuples; - time_msg("reading edges", start_t, clock()); -} - -/* select id, source, target, capacity, reverse_capacity */ -void -pgr_get_flow_edges( - char *sql, - Edge_t **edges, - size_t *total_edges) { - get_edges_flow(sql, edges, total_edges, true); -} - -/* select id, source, target, capacity, reverse_capacity, cost, reverse_cost */ -void -pgr_get_costFlow_edges( - char *sql, - CostFlow_t **edges, - size_t *total_edges) { - get_edges_costFlow(sql, edges, total_edges, true); -} - -/* select id, source, target, cost, reverse_cost */ -void -pgr_get_edges( - char *edges_sql, - Edge_t **edges, - size_t *total_edges, - bool normal, - bool ignore_id) { - get_edges_5_columns(edges_sql, edges, total_edges, ignore_id, normal); -} - -/* select id, source, target, cost, reverse_cost, x1, y1, x2, y2 */ -void -pgr_get_edges_xy( - char *edges_sql, - Edge_xy_t **edges, - size_t *total_edges, - bool normal) { - get_edges_9_columns(edges_sql, edges, total_edges, normal); -} - -/* used in flow algorithms */ -void -pgr_get_basic_edges( - char *sql, - Edge_bool_t **edges, - size_t *total_edges) { - get_edges_basic(sql, edges, total_edges, true); -} diff --git a/src/common/get_check_data.c b/src/common/get_check_data.c deleted file mode 100644 index 61c70ff330b..00000000000 --- a/src/common/get_check_data.c +++ /dev/null @@ -1,449 +0,0 @@ -/*PGR-GNU***************************************************************** -File: get_check_data.c - -Copyright (c) 2015 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include -#include "c_types/column_info_t.h" -#include "c_common/postgres_connection.h" -#include "c_common/get_check_data.h" -#include "c_common/arrays_input.h" - -#include "catalog/pg_type.h" - -#include "c_common/debug_macro.h" - -/*! - * @brief Function will check whether the colNumber represent any specific column or NULL (SPI_ERROR_NOATTRIBUTE). - * - * @param[in] colNumber Column number (count starts at 1). - * - * @return @b TRUE when colNumber exist. - * @b FALSE when colNumber was not found. - * - */ -bool -column_found(int colNumber) { - /* - * [SPI_ERROR_NOATTRIBUTE](https://doxygen.postgresql.org/spi_8h.html#ac1512d8aaa23c2d57bb0d1eb8f453ee2) - */ - return !(colNumber == SPI_ERROR_NOATTRIBUTE); -} - -/*! - * @brief Function tells expected type of each column and then check the correspondence type of each column. - * - * @param[in] info contain one or more column information. - * - * @throw column not found. - * @throw ERROR Unknown type of column. - * - * - * @return @b TRUE when column exist. - * @b FALSE when column was not found. - * - */ - -static -bool -fetch_column_info( - Column_info_t *info) { -/* TODO(vicky) Remove unused code */ -#if 0 - PGR_DBG("Fetching column info of %s", info->name); -#endif - /* - * [SPI_fnumber](https://www.postgresql.org/docs/8.2/static/spi-spi-fnumber.html) - */ - info->colNumber = SPI_fnumber(SPI_tuptable->tupdesc, info->name); - if (info->strict && !column_found(info->colNumber)) { - elog(ERROR, "Column '%s' not Found", info->name); - } - - if (column_found(info->colNumber)) { - /* - * [SPI_gettypeid](https://www.postgresql.org/docs/9.1/static/spi-spi-gettypeid.html) - */ - (info->type) = SPI_gettypeid(SPI_tuptable->tupdesc, (info->colNumber)); - if (SPI_result == SPI_ERROR_NOATTRIBUTE) { - elog(ERROR, "Type of column '%s' not Found", info->name); - } -/* TODO(vicky) Remove unused code */ -#if 0 - PGR_DBG("Column %s found: %lu", info->name, info->type); -#endif - return true; - } - PGR_DBG("Column %s not found", info->name); - return false; -} - -/*! - * @brief Function tells expected type of each column and then check the correspondence type of each column. - * - * @param[in] info contain one or more column information. - * @param[in] info_size number of columns. - * - * @throw ERROR Unknown type of column. - * - */ - -void pgr_fetch_column_info( - Column_info_t info[], - int info_size) { - int i; - for (i = 0; i < info_size; ++i) { - if (fetch_column_info(&info[i])) { - switch (info[i].eType) { - case ANY_INTEGER: - pgr_check_any_integer_type(info[i]); - break; - case ANY_NUMERICAL: - pgr_check_any_numerical_type(info[i]); - break; - case TEXT: - pgr_check_text_type(info[i]); - break; - case CHAR1: - pgr_check_char_type(info[i]); - break; - case ANY_INTEGER_ARRAY: - pgr_check_any_integerarray_type(info[i]); - break; - default: - elog(ERROR, "Unknown type of column %s", info[i].name); - } - } - } -} - -/* - * [BPCHAROID](https://doxygen.postgresql.org/include_2catalog_2pg__type_8h.html#afa7749dbe36d31874205189d9d6b21d7) - * [INT2ARRAYOID](https://doxygen.postgresql.org/include_2catalog_2pg__type_8h.html#ac265fe7b0bb75fead13b16bf072722e9) - */ - -/*! - * @brief The function check whether column type is CHAR or not. - * Where CHAR is SQL type: - * CHARACTER - * - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected column type is CHAR. - * - */ -void -pgr_check_char_type(Column_info_t info) { - if (!(info.type == BPCHAROID)) { - elog(ERROR, "Unexpected Column '%s' type. Expected CHAR", info.name); - } -} - -/*! - * @brief The function check whether column type is TEXT or not. - * Where TEXT is SQL type: - * TEXT - * - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected column type is TEXT. - * - */ - -void -pgr_check_text_type(Column_info_t info) { - if (!(info.type == TEXTOID)) { - elog(ERROR, "Unexpected Column '%s' type. Expected TEXT", info.name); - } -} - -/*! - * @brief The function check whether column type is ANY-INTEGER or not. - * Where ANY-INTEGER is SQL type: - * SMALLINT, INTEGER, BIGINT - * - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected column type is ANY-INTEGER. - * - */ - -void -pgr_check_any_integer_type(Column_info_t info) { - if (!(info.type == INT2OID - || info.type == INT4OID - || info.type == INT8OID)) { - elog(ERROR, - "Unexpected Column '%s' type. Expected ANY-INTEGER", - info.name); - } -} -/*! - * @brief The function check whether column type is ANY-INTEGER-ARRAY or not. - * Where ANY-INTEGER-ARRAY is SQL type: - * SMALLINT[], INTEGER[], BIGINT[] - * - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected ANY-INTEGER-ARRAY. - * - */ -void -pgr_check_any_integerarray_type(Column_info_t info) { - if (!(info.type == INT2ARRAYOID - || info.type == INT4ARRAYOID - || info.type == 1016)) { - elog(ERROR, - "Unexpected Column '%s' type. Expected ANY-INTEGER-ARRAY", - info.name); - } -} - -/*! - * @brief The function check whether column type is ANY-NUMERICAL. - * Where ANY-NUMERICAL is SQL type: - * SMALLINT, INTEGER, BIGINT, REAL, FLOAT - * - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected column type is ANY-NUMERICAL. - * - */ - -void pgr_check_any_numerical_type(Column_info_t info) { - if (!(info.type == INT2OID - || info.type == INT4OID - || info.type == INT8OID - || info.type == FLOAT4OID - || info.type == FLOAT8OID - || info.type == NUMERICOID)) { - elog(ERROR, - "Unexpected Column '%s' type. Expected ANY-NUMERICAL", - info.name); - } -} - - -/* - * http://doxygen.postgresql.org/include_2catalog_2pg__type_8h.html; - * [SPI_getbinval](https://www.postgresql.org/docs/8.1/static/spi-spi-getbinval.html) - * [Datum](https://doxygen.postgresql.org/datum_8h.html) - * [DatumGetInt16](https://doxygen.postgresql.org/postgres_8h.html#aec991e04209850f29a8a63df0c78ba2d) - */ - -/*! - * @brief Function return the value of specified column in char type. - * - * @param[in] tuple input row to be examined. - * @param[in] tupdesc input row description. - * @param[in] info contain column information. - * @param[in] strict boolean value of strict. - * @param[in] default_value returned when column contain NULL value. - * - * @throw ERROR Unexpected Column type. Expected column type is CHAR. - * @throw ERROR When value of column is NULL. - * - * @return Char type of column value is returned. - * - */ - -char -pgr_SPI_getChar( - HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, - bool strict, char default_value) { - Datum binval; - bool isNull; - char value = default_value; - - binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isNull); - if (!(info.type == BPCHAROID)) { - elog(ERROR, "Unexpected Column type of %s. Expected CHAR", info.name); - } - if (!isNull) { - value = ((char*)binval)[1]; - } else { - if (strict) { - elog(ERROR, "Unexpected Null value in column %s", info.name); - } - value = default_value; - } - return value; -} - -/*! - * @brief Function returns the values of specified columns in array. - * - * @param[in] tuple input row to be examined. - * @param[in] tupdesc input row description. - * @param[in] info contain column information. - * @param[out] the_size number of element in array. - * - * @throw ERROR No elements found in ARRAY. - * @throw ERROR Unexpected Column type. Expected column type is ANY-INTEGER-ARRAY. - * @throw ERROR NULL value found in Array. - * - * @return Array of columns value is returned. - * - */ - -int64_t* -pgr_SPI_getBigIntArr( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info, - uint64_t *the_size) { - bool is_null = false; - - Datum raw_array = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &is_null); - - *the_size = 0; - if (is_null) return (int64_t*)NULL; - /* - * [DatumGetArrayTypeP](https://doxygen.postgresql.org/array_8h.html#aa1b8e77c103863862e06a7b7c07ec532) - * [pgr_get_bigIntArray](http://docs.pgrouting.org/doxy/2.2/arrays__input_8c_source.html) - */ - ArrayType *pg_array = DatumGetArrayTypeP(raw_array); - - return pgr_get_bigIntArray((size_t*)the_size, pg_array, true); -} - -/*! - * @brief Function returns the value of specified column in integer type. - * - * @param[in] tuple input row to be examined. - * @param[in] tupdesc input row description. - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected column type is ANY-INTEGER. - * @throw ERROR When value of column is NULL. - * - * @return Integer type of column value is returned. - * - */ - -int64_t -pgr_SPI_getBigInt(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info) { - Datum binval; - bool isnull; - int64_t value = 0; - binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isnull); - if (isnull) - elog(ERROR, "Unexpected Null value in column %s", info.name); - switch (info.type) { - case INT2OID: - value = (int64_t) DatumGetInt16(binval); - break; - case INT4OID: - value = (int64_t) DatumGetInt32(binval); - break; - case INT8OID: - value = DatumGetInt64(binval); - break; - default: - elog(ERROR, - "Unexpected Column type of %s. Expected ANY-INTEGER", - info.name); - } -/* TODO(vicky) Remove unused code */ -#if 0 - PGR_DBG("Variable: %s Value: %ld", info.name, value); -#endif - return value; -} - -/*! - * @brief Function returns the value of specified column in double type. - * - * @param[in] tuple input row to be examined. - * @param[in] tupdesc input row description. - * @param[in] info contain column information. - * - * @throw ERROR Unexpected Column type. Expected column type is ANY-NUMERICAL. - * @throw ERROR When value of column is NULL. - * - * @return Double type of column value is returned. - * - */ - -double -pgr_SPI_getFloat8(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info) { - Datum binval; - bool isnull = false; - double value = 0.0; - binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isnull); - if (isnull) - elog(ERROR, "Unexpected Null value in column %s", info.name); - - switch (info.type) { - case INT2OID: - value = (double) DatumGetInt16(binval); - break; - case INT4OID: - value = (double) DatumGetInt32(binval); - break; - case INT8OID: - value = (double) DatumGetInt64(binval); - break; - case FLOAT4OID: - value = (double) DatumGetFloat4(binval); - break; - case FLOAT8OID: - value = DatumGetFloat8(binval); - break; - case NUMERICOID: - /* Note: out-of-range values will be clamped to +-HUGE_VAL */ - value = (double) DatumGetFloat8(DirectFunctionCall1(numeric_float8_no_overflow, binval)); - break; - default: - elog(ERROR, - "Unexpected Column type of %s. Expected ANY-NUMERICAL", - info.name); - } -/* TODO(vicky) Remove unused code */ -#if 0 - PGR_DBG("Variable: %s Value: %.20f", info.name, value); -#endif - return value; -} - -/** - * under development - */ -/* - * [DatumGetCString](https://doxygen.postgresql.org/postgres_8h.html#ae401c8476d1a12b420e3061823a206a7) - */ - -/*! - * @brief Function returns the string representation of the value of specified column. - * - * @param[in] tuple input row to be examined. - * @param[in] tupdesc input row description. - * @param[in] info contain column information. - * - * @return Pointer of string is returned. - * - */ - -char* -pgr_SPI_getText(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info) { - return DatumGetCString(SPI_getvalue(*tuple, *tupdesc, info.colNumber)); -} diff --git a/src/common/matrixRows_input.c b/src/common/matrixRows_input.c deleted file mode 100644 index 9f037d97081..00000000000 --- a/src/common/matrixRows_input.c +++ /dev/null @@ -1,155 +0,0 @@ -/*PGR-GNU***************************************************************** -File: matrixRows_input.c - -Copyright (c) 2015 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - - -/* for bool */ -# include -/* for size_t */ -# include - -#include "c_common/pgdata_getters.h" -#include "c_types/column_info_t.h" -#include "c_types/iid_t_rt.h" - -#include "c_common/debug_macro.h" -#include "c_common/get_check_data.h" -#include "c_common/time_msg.h" - -/* - -.. Matrix SQL definition start - -============= ================= ================================================= -Column Type Description -============= ================= ================================================= -``start_vid`` ``ANY-INTEGER`` Identifier of the starting vertex. -``end_vid`` ``ANY-INTEGER`` Identifier of the ending vertex. -``agg_cost`` ``ANY-NUMERICAL`` Cost for going from start_vid to end_vid -============= ================= ================================================= - -.. Matrix SQL definition end - -*/ - - -static -void pgr_fetch_row( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[3], - IID_t_rt *distance) { - distance->from_vid = pgr_SPI_getBigInt(tuple, tupdesc, info[0]); - distance->to_vid = pgr_SPI_getBigInt(tuple, tupdesc, info[1]); - distance->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[2]); -} - -/*! - * bigint start_vid, - * bigint end_vid, - * float agg_cost, - */ -void pgr_get_matrixRows( - char *sql, - IID_t_rt **rows, - size_t *total_rows) { - clock_t start_t = clock(); - - const int tuple_limit = 1000000; - - size_t total_tuples = 0; - - Column_info_t info[3]; - - int i; - for (i = 0; i < 3; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - info[0].name = "start_vid"; - info[1].name = "end_vid"; - info[2].name = "agg_cost"; - - info[2].eType = ANY_NUMERICAL; - - - void *SPIplan; - SPIplan = pgr_SPI_prepare(sql); - - Portal SPIportal; - SPIportal = pgr_SPI_cursor_open(SPIplan); - - - bool moredata = true; - (*total_rows) = total_tuples; - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) - pgr_fetch_column_info(info, 3); - - size_t ntuples = SPI_processed; - total_tuples += ntuples; - - if (ntuples > 0) { - if ((*rows) == NULL) - (*rows) = (IID_t_rt *)palloc0( - total_tuples * sizeof(IID_t_rt)); - else - (*rows) = (IID_t_rt *)repalloc( - (*rows), total_tuples * sizeof(IID_t_rt)); - - if ((*rows) == NULL) { - elog(ERROR, "Out of memory"); - } - - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - PGR_DBG("processing %ld matrix cell tupĺes", ntuples); - - size_t t; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - pgr_fetch_row(&tuple, &tupdesc, info, - &(*rows)[total_tuples - ntuples + t]); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - - if (total_tuples == 0) { - (*total_rows) = 0; - PGR_DBG("NO rows"); - return; - } - - (*total_rows) = total_tuples; - time_msg(" reading matrix cells", start_t, clock()); -} diff --git a/src/common/orders_input.c b/src/common/orders_input.c deleted file mode 100644 index 6bf9f93cf45..00000000000 --- a/src/common/orders_input.c +++ /dev/null @@ -1,221 +0,0 @@ -/*PGR-GNU***************************************************************** -File: pd_orders_input.c - -Copyright (c) 2016 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/pgdata_getters.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 "c_types/pickDeliver/orders_t.h" - -static -void fetch_pd_orders( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[14], - bool matrix_version, - Orders_t *pd_order) { - pd_order->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]); - pd_order->demand = pgr_SPI_getFloat8(tuple, tupdesc, info[1]); - - /* - * the pickups - */ - pd_order->pick_x = matrix_version ? - 0 : pgr_SPI_getFloat8(tuple, tupdesc, info[2]); - pd_order->pick_y = matrix_version ? - 0 : pgr_SPI_getFloat8(tuple, tupdesc, info[3]); - pd_order->pick_open_t = pgr_SPI_getFloat8(tuple, tupdesc, info[4]); - pd_order->pick_close_t = pgr_SPI_getFloat8(tuple, tupdesc, info[5]); - pd_order->pick_service_t = column_found(info[6].colNumber) ? - pgr_SPI_getFloat8(tuple, tupdesc, info[6]) : 0; - - /* - * the deliveries - */ - pd_order->deliver_x = matrix_version ? - 0 : pgr_SPI_getFloat8(tuple, tupdesc, info[7]); - pd_order->deliver_y = matrix_version ? - 0 : pgr_SPI_getFloat8(tuple, tupdesc, info[8]); - pd_order->deliver_open_t = pgr_SPI_getFloat8(tuple, tupdesc, info[9]); - pd_order->deliver_close_t = pgr_SPI_getFloat8(tuple, tupdesc, info[10]); - pd_order->deliver_service_t = column_found(info[11].colNumber) ? - pgr_SPI_getFloat8(tuple, tupdesc, info[11]) : 0; - - pd_order->pick_node_id = matrix_version ? - pgr_SPI_getBigInt(tuple, tupdesc, info[12]) : 0; - pd_order->deliver_node_id = matrix_version ? - pgr_SPI_getBigInt(tuple, tupdesc, info[13]) : 0; -} - - - -static -void -pgr_get_pd_orders_general( - char *pd_orders_sql, - Orders_t **pd_orders, - size_t *total_pd_orders, - bool with_id) { - clock_t start_t = clock(); - - const int tuple_limit = 1000000; - - PGR_DBG("pgr_get_pd_orders_data"); - PGR_DBG("%s", pd_orders_sql); - - Column_info_t info[14]; - - int i; - for (i = 0; i < 14; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_NUMERICAL; - } - - info[0].name = "id"; - info[1].name = "demand"; - info[2].name = "p_x"; - info[3].name = "p_y"; - info[4].name = "p_open"; - info[5].name = "p_close"; - info[6].name = "p_service"; - info[7].name = "d_x"; - info[8].name = "d_y"; - info[9].name = "d_open"; - info[10].name = "d_close"; - info[11].name = "d_service"; - info[12].name = "p_node_id"; - info[13].name = "d_node_id"; - - info[0].eType = ANY_INTEGER; - info[12].eType = ANY_INTEGER; - info[13].eType = ANY_INTEGER; - - /* service is optional*/ - info[6].strict = false; - info[11].strict = false; - /* nodes are going to be ignored*/ - info[12].strict = false; - info[13].strict = false; - - if (with_id) { - /* (x,y) values are ignored*/ - info[2].strict = false; - info[3].strict = false; - info[7].strict = false; - info[8].strict = false; - /* nodes are compulsory*/ - info[12].strict = true; - info[13].strict = true; - } - - - - size_t total_tuples; - - void *SPIplan; - SPIplan = pgr_SPI_prepare(pd_orders_sql); - Portal SPIportal; - SPIportal = pgr_SPI_cursor_open(SPIplan); - - bool moredata = true; - (*total_pd_orders) = total_tuples = 0; - - /* on the first tuple get the column numbers */ - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) { - pgr_fetch_column_info(info, 14); - } - size_t ntuples = SPI_processed; - total_tuples += ntuples; - PGR_DBG("SPI_processed %ld", ntuples); - if (ntuples > 0) { - if ((*pd_orders) == NULL) - (*pd_orders) = (Orders_t *)palloc0( - total_tuples * sizeof(Orders_t)); - else - (*pd_orders) = (Orders_t *)repalloc( - (*pd_orders), - total_tuples * sizeof(Orders_t)); - - if ((*pd_orders) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - PGR_DBG("processing %ld", ntuples); - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_pd_orders(&tuple, &tupdesc, info, with_id, - &(*pd_orders)[total_tuples - ntuples + t]); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0) { - (*total_pd_orders) = 0; - PGR_DBG("NO orders"); - return; - } - - (*total_pd_orders) = total_tuples; - if (with_id) { - PGR_DBG("Finish reading %ld orders for matrix", (*total_pd_orders)); - } else { - PGR_DBG("Finish reading %ld orders for euclidean", (*total_pd_orders)); - } - time_msg("reading edges", start_t, clock()); -} - -void -pgr_get_orders( - char *pd_orders_sql, - Orders_t **pd_orders, - size_t *total_pd_orders, - bool with_id) { - pgr_get_pd_orders_general(pd_orders_sql, pd_orders, total_pd_orders, with_id); -} - -#if 0 -void -pgr_get_pd_orders_with_id( - char *pd_orders_sql, - Orders_t **pd_orders, - size_t *total_pd_orders) { - pgr_get_pd_orders_general(pd_orders_sql, pd_orders, total_pd_orders, true); -} -#endif diff --git a/src/common/points_input.c b/src/common/points_input.c deleted file mode 100644 index 194f760fd30..00000000000 --- a/src/common/points_input.c +++ /dev/null @@ -1,159 +0,0 @@ -/*PGR-GNU***************************************************************** -File: points_input.c - -Copyright (c) 2015 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - - -/* for bool */ -# include -/* for size_t */ -# include - - -#include "c_common/pgdata_getters.h" -#include "c_types/column_info_t.h" -#include "c_types/point_on_edge_t.h" - -#include "c_common/debug_macro.h" -#include "c_common/get_check_data.h" - - - -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) { - if (column_found(info[0].colNumber)) { - point->pid = pgr_SPI_getBigInt(tuple, tupdesc, info[0]); - } else { - point->pid = *default_pid; - ++(*default_pid); - } - - point->edge_id = pgr_SPI_getBigInt(tuple, tupdesc, info[1]); - point->fraction = pgr_SPI_getFloat8(tuple, tupdesc, info[2]); - - if (column_found(info[3].colNumber)) { - point->side = - (char)pgr_SPI_getChar(tuple, tupdesc, info[3], false, default_side); - } else { - point->side = default_side; - } -} - - -// pid, edge_id, fraction, [side] -void -pgr_get_points( - char *points_sql, - Point_on_edge_t **points, - size_t *total_points) { - const int tuple_limit = 1000; - - size_t total_tuples; - Column_info_t info[4]; - - int i; - for (i = 0; i < 4; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - - info[0].name = "pid"; - info[1].name = "edge_id"; - info[2].name = "fraction"; - info[3].name = "side"; - - info[0].strict = false; - info[3].strict = false; - info[2].eType = ANY_NUMERICAL; - info[3].eType = CHAR1; - - - void *SPIplan; - SPIplan = pgr_SPI_prepare(points_sql); - - Portal SPIportal; - SPIportal = pgr_SPI_cursor_open(SPIplan); - - bool moredata = true; - (*total_points) = total_tuples = 0; - - int64_t default_pid = 1; - char default_side = 'b'; - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) { - /* on the first tuple get the column information */ - pgr_fetch_column_info(info, 4); - } - - size_t ntuples = SPI_processed; - total_tuples += ntuples; - - if (ntuples > 0) { - if ((*points) == NULL) - (*points) = (Point_on_edge_t *) - palloc0(total_tuples * sizeof(Point_on_edge_t)); - else - (*points) = (Point_on_edge_t *) - repalloc((*points), total_tuples * sizeof(Point_on_edge_t)); - - if ((*points) == NULL) { - elog(ERROR, "Out of memory"); - } - - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - size_t t; - - PGR_DBG("processing %ld points tuples", ntuples); - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_point(&tuple, &tupdesc, info, - &default_pid, default_side, - &(*points)[total_tuples - ntuples + t]); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - SPI_cursor_close(SPIportal); - - - if (total_tuples == 0) { - (*total_points) = 0; - PGR_DBG("NO points"); - return; - } - - (*total_points) = total_tuples; - PGR_DBG("Finish reading %ld points, %ld", total_tuples, (*total_points)); -} diff --git a/src/common/restrictions_input.c b/src/common/restrictions_input.c deleted file mode 100644 index 3c81bb54bb6..00000000000 --- a/src/common/restrictions_input.c +++ /dev/null @@ -1,146 +0,0 @@ -/*PGR-GNU***************************************************************** -File: restrictions_input.c - -Copyright (c) 2015 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/pgdata_getters.h" -#include "c_types/column_info_t.h" -#include "c_types/restriction_t.h" - -#include "c_common/debug_macro.h" -#include "c_common/time_msg.h" -#include "c_common/get_check_data.h" - - -static -void fetch_restriction( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[2], - Restriction_t *restriction) { - /* - * reading the cost - */ - restriction->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[0]); - - restriction->via = NULL; - restriction->via_size = 0; - - restriction->via = pgr_SPI_getBigIntArr( - tuple, tupdesc, info[1], &restriction->via_size); -} - - -void -pgr_get_restrictions( - char *restrictions_sql, - Restriction_t **restrictions, - size_t *total_restrictions) { - const int tuple_limit = 1000000; - clock_t start_t = clock(); - - PGR_DBG("pgr_get_restrictions"); - PGR_DBG("%s", restrictions_sql); - - Column_info_t info[2]; - - int i; - for (i = 0; i < 2; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - } - - /* restriction id */ - info[0].name = "cost"; - /* array of edges */ - info[1].name = "path"; - - info[0].eType = ANY_NUMERICAL; - info[1].eType = ANY_INTEGER_ARRAY; - - size_t total_tuples; - - void *SPIplan; - SPIplan = pgr_SPI_prepare(restrictions_sql); - Portal SPIportal; - SPIportal = pgr_SPI_cursor_open(SPIplan); - - bool moredata = true; - (*total_restrictions) = total_tuples = 0; - - - /* on the first tuple get the column numbers */ - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) { - pgr_fetch_column_info(info, 2); - } - size_t ntuples = SPI_processed; - total_tuples += ntuples; - PGR_DBG("Restrictions to be processed %ld", ntuples); - PGR_DBG("size of structure %ld", sizeof(Restriction_t)); - if (ntuples > 0) { - if ((*restrictions) == NULL) { - (*restrictions) = (Restriction_t *)palloc( - total_tuples * sizeof(Restriction_t)); - } else { - (*restrictions) = (Restriction_t *)repalloc( - (*restrictions), - total_tuples * sizeof(Restriction_t)); - } - - if ((*restrictions) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - PGR_DBG("processing %ld", ntuples); - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_restriction(&tuple, &tupdesc, info, - &(*restrictions)[total_tuples - ntuples + t]); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0) { - (*total_restrictions) = 0; - PGR_DBG("NO restrictions"); - return; - } - - (*total_restrictions) = total_tuples; - PGR_DBG("Finish reading %ld restrictions, %ld", - total_tuples, - (*total_restrictions)); - clock_t end_t = clock(); - time_msg(" reading Restrictions", start_t, end_t); -} diff --git a/src/common/vehicles_input.c b/src/common/vehicles_input.c deleted file mode 100644 index 96a0a14af6a..00000000000 --- a/src/common/vehicles_input.c +++ /dev/null @@ -1,274 +0,0 @@ -/*PGR-GNU***************************************************************** -File: vehicles_input.c - -Copyright (c) 2016 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include -#include - -#include "c_common/pgdata_getters.h" -#include "c_types/column_info_t.h" -#include "c_types/pickDeliver/vehicle_t.h" -#include "c_common/debug_macro.h" -#include "c_common/get_check_data.h" -#include "c_common/time_msg.h" - - -static -void fetch_vehicles( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[16], - Vehicle_t *vehicle, - bool with_id) { - vehicle->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]); - vehicle->capacity = pgr_SPI_getFloat8(tuple, tupdesc, info[1]); - - vehicle->start_x = with_id ? - 0 : - pgr_SPI_getFloat8(tuple, tupdesc, info[2]); - vehicle->start_y = with_id ? - 0 : - pgr_SPI_getFloat8(tuple, tupdesc, info[3]); - - vehicle->speed = column_found(info[13].colNumber) ? - pgr_SPI_getFloat8(tuple, tupdesc, info[13]) : - 1; - vehicle->cant_v = column_found(info[4].colNumber) ? - pgr_SPI_getBigInt(tuple, tupdesc, info[4]) : - 1; - vehicle->start_open_t = column_found(info[5].colNumber) ? - pgr_SPI_getFloat8(tuple, tupdesc, info[5]) : - 0; - vehicle->start_close_t = column_found(info[6].colNumber) ? - pgr_SPI_getFloat8(tuple, tupdesc, info[6]) : - DBL_MAX; - vehicle->start_service_t = column_found(info[7].colNumber) ? - pgr_SPI_getFloat8(tuple, tupdesc, info[7]) : - 0; - - - if (!(column_found(info[8].colNumber)) - && column_found(info[9].colNumber)) { - ereport(ERROR, - (errmsg("Column \'%s\' not Found", info[8].name), - errhint("%s was found, also column is expected %s ", - info[9].name, info[8].name))); - } - if (column_found(info[8].colNumber) - && !(column_found(info[9].colNumber))) { - ereport(ERROR, - (errmsg("Column \'%s\' not Found", info[9].name), - errhint("%s was found, also column is expected %s ", - info[8].name, info[9].name))); - } - - vehicle->end_x = column_found(info[8].colNumber) ? - pgr_SPI_getFloat8(tuple, tupdesc, info[8]) : - vehicle->start_x; - vehicle->end_y = column_found(info[9].colNumber) ? - pgr_SPI_getFloat8(tuple, tupdesc, info[9]) : - vehicle->start_y; - - if (!(column_found(info[10].colNumber)) - && column_found(info[11].colNumber)) { - ereport(ERROR, - (errmsg("Column \'%s\' not Found", info[10].name), - errhint("%s was found, also column is expected %s ", - info[10].name, info[11].name))); - } - - if (column_found(info[10].colNumber) - && !(column_found(info[11].colNumber))) { - ereport(ERROR, - (errmsg("Column \'%s\' not Found", info[11].name), - errhint("%s was found, also column is expected %s ", - info[11].name, info[10].name))); - } - vehicle->end_open_t = column_found(info[10].colNumber) ? - pgr_SPI_getFloat8(tuple, tupdesc, info[10]) : - vehicle->start_open_t; - vehicle->end_close_t = column_found(info[11].colNumber) ? - pgr_SPI_getFloat8(tuple, tupdesc, info[11]) : - vehicle->start_close_t; - vehicle->end_service_t = column_found(info[12].colNumber) ? - pgr_SPI_getFloat8(tuple, tupdesc, info[12]) : - vehicle->start_service_t; - - vehicle->speed = column_found(info[13].colNumber) ? - pgr_SPI_getFloat8(tuple, tupdesc, info[13]) : - 1; - vehicle->start_node_id = with_id ? - pgr_SPI_getBigInt(tuple, tupdesc, info[14]) : - 0; - vehicle->end_node_id = with_id ? - (column_found(info[12].colNumber) ? - pgr_SPI_getBigInt(tuple, tupdesc, info[15]) : - vehicle->start_node_id) : - 0; -} - - - -static -void pgr_get_vehicles_general( - char *vehicles_sql, - Vehicle_t **vehicles, - size_t *total_vehicles, - bool with_id) { - clock_t start_t = clock(); - - const int tuple_limit = 1000000; - - PGR_DBG("pgr_get_vehicles"); - PGR_DBG("%s", vehicles_sql); - - Column_info_t info[16]; - - int i; - for (i = 0; i < 16; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_NUMERICAL; - } - - info[0].name = "id"; - info[1].name = "capacity"; - info[2].name = "start_x"; - info[3].name = "start_y"; - info[4].name = "number"; - info[5].name = "start_open"; - info[6].name = "start_close"; - info[7].name = "start_service"; - info[8].name = "end_x"; - info[9].name = "end_y"; - info[10].name = "end_open"; - info[11].name = "end_close"; - info[12].name = "end_service"; - info[13].name = "speed"; - info[14].name = "start_node_id"; - info[15].name = "end_node_id"; - - info[0].eType = ANY_INTEGER; - info[4].eType = ANY_INTEGER; - info[14].eType = ANY_INTEGER; - info[15].eType = ANY_INTEGER; - - for (i = 4; i < 16; ++i) { - info[i].strict = false; - } - - if (with_id) { - /* - * with id, then start_x and start_y are optional - * start_node_id is compulsory - */ - info[2].strict = false; - info[3].strict = false; - info[14].strict = true; - } - - size_t total_tuples; - - void *SPIplan; - SPIplan = pgr_SPI_prepare(vehicles_sql); - Portal SPIportal; - SPIportal = pgr_SPI_cursor_open(SPIplan); - - bool moredata = true; - (*total_vehicles) = total_tuples = 0; - - /* on the first tuple get the column numbers */ - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) { - pgr_fetch_column_info(info, 16); - } - size_t ntuples = SPI_processed; - total_tuples += ntuples; - PGR_DBG("SPI_processed %ld", ntuples); - if (ntuples > 0) { - if ((*vehicles) == NULL) - (*vehicles) = (Vehicle_t *)palloc0( - total_tuples * sizeof(Vehicle_t)); - else - (*vehicles) = (Vehicle_t *)repalloc( - (*vehicles), - total_tuples * sizeof(Vehicle_t)); - - if ((*vehicles) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - PGR_DBG("processing %ld", ntuples); - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_vehicles(&tuple, &tupdesc, info, - &(*vehicles)[total_tuples - ntuples + t], with_id); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0) { - (*total_vehicles) = 0; - PGR_DBG("NO orders"); - return; - } - - (*total_vehicles) = total_tuples; - if (with_id) { - PGR_DBG("Finish reading %ld vehicles for matrix", (*total_vehicles)); - } else { - PGR_DBG("Finish reading %ld vehicles for euclidean", (*total_vehicles)); - } - time_msg("reading edges", start_t, clock()); -} - -void -pgr_get_vehicles( - char *vehicles_sql, - Vehicle_t **vehicles, - size_t *total_vehicles, - bool with_id) { - pgr_get_vehicles_general(vehicles_sql, vehicles, total_vehicles, with_id); -} - -#if 0 -void -pgr_get_vehicles_with_id( - char *vehicles_sql, - Vehicle_t **vehicles, - size_t *total_vehicles) { - pgr_get_vehicles_general(vehicles_sql, vehicles, total_vehicles, true); -} -#endif - diff --git a/src/components/articulationPoints.c b/src/components/articulationPoints.c index e74c9c41232..8d563045f11 100644 --- a/src/components/articulationPoints.c +++ b/src/components/articulationPoints.c @@ -52,6 +52,9 @@ process( int64_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; (*result_tuples) = NULL; (*result_count) = 0; @@ -59,7 +62,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); @@ -67,9 +71,6 @@ process( } clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_articulationPoints( edges, total_edges, diff --git a/src/components/biconnectedComponents.c b/src/components/biconnectedComponents.c index 3523240a6b0..5c840e2c910 100644 --- a/src/components/biconnectedComponents.c +++ b/src/components/biconnectedComponents.c @@ -53,6 +53,9 @@ process( II_t_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; (*result_tuples) = NULL; (*result_count) = 0; @@ -60,7 +63,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); @@ -68,9 +72,6 @@ process( } clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_biconnectedComponents( edges, total_edges, diff --git a/src/components/bridges.c b/src/components/bridges.c index 383b4aab106..96a11a344e9 100644 --- a/src/components/bridges.c +++ b/src/components/bridges.c @@ -52,6 +52,9 @@ process( int64_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; (*result_tuples) = NULL; (*result_count) = 0; @@ -59,7 +62,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); @@ -67,9 +71,6 @@ process( } clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_bridges( edges, total_edges, diff --git a/src/components/connectedComponents.c b/src/components/connectedComponents.c index 048e4f58042..9b141615573 100644 --- a/src/components/connectedComponents.c +++ b/src/components/connectedComponents.c @@ -53,6 +53,9 @@ process( II_t_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; (*result_tuples) = NULL; (*result_count) = 0; @@ -60,7 +63,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); @@ -68,9 +72,6 @@ process( } clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_connectedComponents( edges, total_edges, diff --git a/src/components/makeConnected.c b/src/components/makeConnected.c index 95780b3f814..0282f6aca8e 100644 --- a/src/components/makeConnected.c +++ b/src/components/makeConnected.c @@ -30,7 +30,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/ii_t_rt.h" #include "c_common/debug_macro.h" @@ -50,6 +49,9 @@ process( II_t_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; PGR_DBG("Initializing arrays"); @@ -61,7 +63,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -71,9 +74,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_makeConnected( edges, total_edges, diff --git a/src/components/strongComponents.c b/src/components/strongComponents.c index 1c9b8117518..da303132d15 100644 --- a/src/components/strongComponents.c +++ b/src/components/strongComponents.c @@ -53,6 +53,9 @@ process( II_t_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; (*result_tuples) = NULL; (*result_count) = 0; @@ -60,7 +63,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); @@ -68,9 +72,6 @@ process( } clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_strongComponents( edges, total_edges, diff --git a/src/contraction/contractGraph.c b/src/contraction/contractGraph.c index 3021e409ef8..7fb0a45a28d 100644 --- a/src/contraction/contractGraph.c +++ b/src/contraction/contractGraph.c @@ -30,7 +30,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "catalog/pg_type.h" #include "utils/lsyscache.h" @@ -42,7 +41,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" #include "c_types/contracted_rt.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/contraction/contractGraph_driver.h" @@ -66,19 +64,25 @@ process(char* edges_sql, if (num_cycles < 1) return; pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; size_t size_forbidden_vertices = 0; - int64_t* forbidden_vertices = pgr_get_bigIntArray(&size_forbidden_vertices, forbidden, true); + int64_t* forbidden_vertices = pgr_get_bigIntArray(&size_forbidden_vertices, forbidden, true, &err_msg); + throw_error(err_msg, "While getting forbidden_vertices"); PGR_DBG("size_forbidden_vertices %ld", size_forbidden_vertices); size_t size_contraction_order = 0; - int64_t* contraction_order = pgr_get_bigIntArray(&size_contraction_order, order, false); + int64_t* contraction_order = pgr_get_bigIntArray(&size_contraction_order, order, false, &err_msg); + throw_error(err_msg, "While getting contraction order"); PGR_DBG("size_contraction_order %ld ", size_contraction_order); size_t total_edges = 0; Edge_t* edges = NULL; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { if (forbidden_vertices) pfree(forbidden_vertices); if (contraction_order) pfree(contraction_order); @@ -88,9 +92,6 @@ process(char* edges_sql, PGR_DBG("Starting timer"); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_contractGraph( edges, total_edges, forbidden_vertices, size_forbidden_vertices, diff --git a/src/cpp_common/CMakeLists.txt b/src/cpp_common/CMakeLists.txt index 9e99f3bb826..87d81385238 100644 --- a/src/cpp_common/CMakeLists.txt +++ b/src/cpp_common/CMakeLists.txt @@ -5,5 +5,9 @@ ADD_LIBRARY(cpp_common OBJECT bpoint.cpp pgr_messages.cpp combinations.cpp - arrays_input.cpp + + get_check_data.cpp + pgdata_fetchers.cpp + # linked as C, but compiled as C++ + pgdata_getters.cpp ) diff --git a/src/cpp_common/get_check_data.cpp b/src/cpp_common/get_check_data.cpp new file mode 100644 index 00000000000..8a66b0742f6 --- /dev/null +++ b/src/cpp_common/get_check_data.cpp @@ -0,0 +1,458 @@ +/*PGR-GNU***************************************************************** +File: get_check_data.cpp + +Copyright (c) 2023 Celia Virginia Vergara Castillo +vicky at erosion.dev +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + +#include "cpp_common/get_check_data.hpp" + + +extern "C" { +#include +#include +#include +#include +#include +} + +#include + +#include "cpp_common/pgr_alloc.hpp" +#include "c_types/info_t.hpp" + + +namespace { + +/** @brief Function tells expected type of each column and then check the correspondence type of each column. + * + * [SPI_fnumber](https://www.postgresql.org/docs/current/spi-spi-fnumber.html) + * [SPI_gettypeid](https://www.postgresql.org/docs/9.1/static/spi-spi-gettypeid.html) + * @param[in] tupdesc tuple description. + * @param[in] info contain one or more column information. + * @throw column not found. + * @throw ERROR Unknown type of column. + * @return @b TRUE when column exist. + * @b FALSE when column was not found. + */ +bool +get_column_info(const TupleDesc &tupdesc, pgrouting::Column_info_t &info) { + info.colNumber = SPI_fnumber(tupdesc, info.name.c_str()); + if (info.strict && info.colNumber == SPI_ERROR_NOATTRIBUTE) { + throw std::string("Column '") + info.name + "' not Found"; + } + + if (info.colNumber != SPI_ERROR_NOATTRIBUTE) { + info.type = SPI_gettypeid(tupdesc, info.colNumber); + if (info.type == InvalidOid) { + throw std::string("Type of column '") + info.name + "' not Found"; + } + return true; + } + return false; +} + +/** @brief The function check whether column type is ANY-INTEGER or not. + * + * Where ANY-INTEGER is SQL type: SMALLINT, INTEGER, BIGINT + * + * @param[in] info contain column information. + * @throw ERROR Unexpected Column type. Expected column type is ANY-INTEGER. + */ +void +check_any_integer_type(const pgrouting::Column_info_t &info) { + if (!(info.type == INT2OID + || info.type == INT4OID + || info.type == INT8OID)) { + throw std::string("Unexpected Column '") + info.name + "' type. Expected ANY-INTEGER"; + } +} + +/** + * @brief The function check whether column type is ANY-NUMERICAL. + * Where ANY-NUMERICAL is SQL type: + * SMALLINT, INTEGER, BIGINT, REAL, FLOAT + * + * @param[in] info contain column information. + * @throw ERROR Unexpected Column type. Expected column type is ANY-NUMERICAL. + */ +void check_any_numerical_type(const pgrouting::Column_info_t &info) { + if (!(info.type == INT2OID + || info.type == INT4OID + || info.type == INT8OID + || info.type == FLOAT4OID + || info.type == FLOAT8OID + || info.type == NUMERICOID)) { + throw std::string("Unexpected Column '") + info.name + "' type. Expected ANY-NUMERICAL"; + } +} + +/** + * @brief The function check whether column type is TEXT or not. + * Where TEXT is SQL type: + * TEXT + * + * @param[in] info contain column information. + * @throw ERROR Unexpected Column type. Expected column type is TEXT. + */ +void +check_text_type(const pgrouting::Column_info_t &info) { + if (!(info.type == TEXTOID)) { + throw std::string("Unexpected Column '") + info.name + "' type. Expected TEXT"; + } +} + +/** + * @brief The function check whether column type is CHAR or not. + * Where CHAR is SQL type: + * CHARACTER + * + * [BPCHAROID](https://doxygen.postgresql.org/include_2catalog_2pg__type_8h.html#afa7749dbe36d31874205189d9d6b21d7) + * @param[in] info contain column information. + * @throw ERROR Unexpected Column type. Expected column type is CHAR. + */ +void +check_char_type(const pgrouting::Column_info_t &info) { + if (!(info.type == BPCHAROID)) { + throw std::string("Unexpected Column '") + info.name + "' type. Expected TEXT"; + } +} + +/** + * @brief The function check whether column type is ANY-INTEGER-ARRAY or not. + * Where ANY-INTEGER-ARRAY is SQL type: + * SMALLINT[], INTEGER[], BIGINT[] + * + * @param[in] info contain column information. + * @throw ERROR Unexpected Column type. Expected ANY-INTEGER-ARRAY. + */ +void +check_any_integer_array_type(const pgrouting::Column_info_t &info) { + if (!(info.type == INT2ARRAYOID + || info.type == INT4ARRAYOID + || info.type == 1016)) { + throw std::string("Unexpected Column '") + info.name + "' type. Expected ANY-INTEGER-ARRAY"; + } +} + +} // namespace + +namespace pgrouting { + +/** + * @param[in] colNumber Column number (count starts at 1). + * @return @b TRUE when colNumber exist. + * @b FALSE when colNumber was not found. + * + * [SPI_ERROR_NOATTRIBUTE](https://doxygen.postgresql.org/spi_8h.html#ac1512d8aaa23c2d57bb0d1eb8f453ee2) + */ +bool column_found(int colNumber) { + return !(colNumber == SPI_ERROR_NOATTRIBUTE); +} + + +/** + * @param[in] tupdesc tuple descriptor + * @param[in] info contain one or more column information. + * + * @throw ERROR Unknown type of column. + */ +void fetch_column_info( + const TupleDesc &tupdesc, + std::vector &info) { + for (auto &coldata : info) { + if (get_column_info(tupdesc, coldata)) { + switch (coldata.eType) { + case ANY_INTEGER: + check_any_integer_type(coldata); + break; + case ANY_NUMERICAL: + check_any_numerical_type(coldata); + break; + case TEXT: + check_text_type(coldata); + break; + case CHAR1: + check_char_type(coldata); + break; + case ANY_INTEGER_ARRAY: + check_any_integer_array_type(coldata); + break; + default: + throw std::string("Unexpected type of column ") + coldata.name; + } + } + } +} + +/** + * http://doxygen.postgresql.org/include_2catalog_2pg__type_8h.html; + * [SPI_getbinval](https://www.postgresql.org/docs/8.1/static/spi-spi-getbinval.html) + * [Datum](https://doxygen.postgresql.org/datum_8h.html) + * [DatumGetInt16](https://doxygen.postgresql.org/postgres_8h.html#aec991e04209850f29a8a63df0c78ba2d) + * + * @param[in] tuple input row to be examined. + * @param[in] tupdesc tuple descriptor + * @param[in] info contain column information. + * @param[in] strict boolean value of strict. + * @param[in] default_value returned when column contain NULL value. + * @throw ERROR Unexpected Column type. Expected column type is CHAR. + * @throw ERROR When value of column is NULL. + * @return Char type of column value is returned. + */ +char getChar( + const HeapTuple tuple, const TupleDesc &tupdesc, const pgrouting::Column_info_t &info, + bool strict, char default_value) { + Datum binval; + bool isNull; + char value = default_value; + + binval = SPI_getbinval(tuple, tupdesc, info.colNumber, &isNull); + if (!(info.type == BPCHAROID)) { + throw std::string("Unexpected Column type of ") + info.name + ". Expected CHAR"; + } + if (!isNull) { + value = reinterpret_cast(binval)[1]; + } else { + if (strict) { + throw std::string("Unexpected Null value in column ") + info.name; + } + value = default_value; + } + return value; +} + +/** @brief get the array contents from postgres + * + * @details This function generates the array inputs according to their type + * received through @a ArrayType *v parameter and store them in @a c_array. It + * can be empty also if received @a allow_empty true. The cases of failure are:- + * 1. When @a ndim is not equal to one dimension. + * 2. When no element is found i.e. nitems is zero or negative. + * 3. If the element type doesn't lie in switch cases, give the error of expected array of any integer type + * 4. When size of @a c_array is out of range or memory. + * 5. When null value is found in the array. + * + * All these failures are represented as error through @a elog. + * @param[in] v Pointer to the postgres C array + * @param[out] arrlen size of the C array + * @param[in] allow_empty flag to allow empty arrays + * + * @pre the array has to be one dimension + * @pre Must have elements (when allow_empty is false) + * + * @returns The resultant array + */ +int64_t* +get_array(ArrayType *v, size_t *arrlen, bool allow_empty) { + int64_t *c_array = nullptr; + + auto element_type = ARR_ELEMTYPE(v); + auto dim = ARR_DIMS(v); + auto ndim = ARR_NDIM(v); + auto nitems = ArrayGetNItems(ndim, dim); + Datum *elements = nullptr; + bool *nulls = nullptr; + int16 typlen; + bool typbyval; + char typalign; + + + if (allow_empty && (ndim == 0 || nitems <= 0)) { + return nullptr; + } + + if (ndim != 1) { + throw std::string("One dimension expected"); + return nullptr; + } + + if (nitems <= 0) { + throw std::string("No elements found"); + return nullptr; + } + + get_typlenbyvalalign(element_type, &typlen, &typbyval, &typalign); + + /* validate input data type */ + switch (element_type) { + case INT2OID: + case INT4OID: + case INT8OID: + break; + default: + throw std::string("Expected array of ANY-INTEGER"); + return nullptr; + } + + deconstruct_array(v, element_type, typlen, typbyval, + typalign, &elements, &nulls, + &nitems); + + c_array = pgr_alloc(static_cast(nitems), (c_array)); + if (!c_array) { + throw std::string("Out of memory!"); + } + + + for (int i = 0; i < nitems; i++) { + if (nulls[i]) { + pfree(c_array); + throw std::string("NULL value found in Array!"); + return nullptr; + } else { + switch (element_type) { + case INT2OID: + c_array[i] = static_cast(DatumGetInt16(elements[i])); + break; + case INT4OID: + c_array[i] = static_cast(DatumGetInt32(elements[i])); + break; + case INT8OID: + c_array[i] = DatumGetInt64(elements[i]); + break; + } + } + } + (*arrlen) = static_cast(nitems); + + pfree(elements); + pfree(nulls); + return c_array; +} + +/** + * [DatumGetArrayTypeP](https://doxygen.postgresql.org/array_8h.html#aa1b8e77c103863862e06a7b7c07ec532) + * [pgrouting::get_bigIntArray](http://docs.pgrouting.org/doxy/2.2/arrays__input_8c_source.html) + * @param[in] tuple input row to be examined. + * @param[in] tupdesc input row description. + * @param[in] info contain column information. + * @param[out] the_size number of element in array. + * + * @throw ERROR No elements found in ARRAY. + * @throw ERROR Unexpected Column type. Expected column type is ANY-INTEGER-ARRAY. + * @throw ERROR NULL value found in Array. + * @return Array of columns value is returned. + */ +int64_t* getBigIntArr( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const Column_info_t &info, + uint64_t *the_size) { + bool is_null = false; + + Datum raw_array = SPI_getbinval(tuple, tupdesc, info.colNumber, &is_null); + + *the_size = 0; + if (is_null) return nullptr; + ArrayType *pg_array = DatumGetArrayTypeP(raw_array); + return get_array(pg_array, the_size, true); +} + +/** + * @param[in] tuple input row to be examined. + * @param[in] tupdesc tuple descriptor + * @param[in] info contain column information. + * @throw ERROR Unexpected Column type. Expected column type is ANY-INTEGER. + * @throw ERROR When value of column is NULL. + * + * @return Integer type of column value is returned. + */ +int64_t getBigInt( + const HeapTuple tuple, const TupleDesc &tupdesc, const pgrouting::Column_info_t &info) { + Datum binval; + bool isnull; + int64_t value = 0; + binval = SPI_getbinval(tuple, tupdesc, info.colNumber, &isnull); + if (isnull) + throw std::string("Unexpected Null value in column ") + info.name; + switch (info.type) { + case INT2OID: + value = (int64_t) DatumGetInt16(binval); + break; + case INT4OID: + value = (int64_t) DatumGetInt32(binval); + break; + case INT8OID: + value = DatumGetInt64(binval); + break; + default: + throw std::string("Unexpected Column type of ") + info.name + ". Expected ANY-INTEGER"; + } + return value; +} + +/** + * @param[in] tuple input row to be examined. + * @param[in] tupdesc tuple descriptor + * @param[in] info contain column information. + * @throw ERROR Unexpected Column type. Expected column type is ANY-NUMERICAL. + * @throw ERROR When value of column is NULL. + * @return Double type of column value is returned. + */ +double getFloat8( + const HeapTuple tuple, const TupleDesc &tupdesc, const pgrouting::Column_info_t &info) { + Datum binval; + bool isnull = false; + binval = SPI_getbinval(tuple, tupdesc, info.colNumber, &isnull); + if (isnull) + throw std::string("Unexpected Null value in column ") + info.name; + + switch (info.type) { + case INT2OID: + return static_cast(DatumGetInt16(binval)); + break; + case INT4OID: + return static_cast(DatumGetInt32(binval)); + break; + case INT8OID: + return static_cast(DatumGetInt64(binval)); + break; + case FLOAT4OID: + return static_cast(DatumGetFloat4(binval)); + break; + case FLOAT8OID: + return static_cast(DatumGetFloat8(binval)); + break; + case NUMERICOID: + /* Note: out-of-range values will be clamped to +-HUGE_VAL */ + return static_cast(DatumGetFloat8(DirectFunctionCall1(numeric_float8_no_overflow, binval))); + break; + default: + throw std::string("Unexpected Column type of ") + info.name + ". Expected ANY-NUMERICAL"; + } + return 0.0; +} + +/*! + * [DatumGetCString](https://doxygen.postgresql.org/postgres_8h.html#ae401c8476d1a12b420e3061823a206a7) + * @note under development Not used, not tested + * @param[in] tuple input row to be examined. + * @param[in] tupdesc tuple descriptor + * @param[in] info contain column information. + * @return Pointer of string is returned. + */ + +char* getText(const HeapTuple tuple, const TupleDesc &tupdesc, const pgrouting::Column_info_t &info) { + return DatumGetCString(SPI_getvalue(tuple, tupdesc, info.colNumber)); +} + +} // namespace pgrouting diff --git a/src/cpp_common/pgdata_fetchers.cpp b/src/cpp_common/pgdata_fetchers.cpp new file mode 100644 index 00000000000..991d698c70a --- /dev/null +++ b/src/cpp_common/pgdata_fetchers.cpp @@ -0,0 +1,451 @@ +/*PGR-GNU***************************************************************** +File: pgdata_fetchers.cpp + +Copyright (c) 2023 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev +Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI +mail: m_attia_sakrcw at yahoo.com, estebanzimanyicw at gmail.com +Copyright (c) 2016 Rohith Reddy +Copyright (c) 2016 Andrea Nardelli +mail: nrd.nardelli at gmail.com +Copyright (c) 2015 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev + + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + +#include "cpp_common/pgdata_fetchers.hpp" + +#include +#include +#include + +#include "cpp_common/get_check_data.hpp" + +#include "c_types/info_t.hpp" +#include "c_types/ii_t_rt.h" +#include "c_types/coordinate_t.h" +#include "c_types/delauny_t.h" +#include "c_types/edge_bool_t_rt.h" +#include "c_types/costFlow_t.h" +#include "c_types/edge_xy_t.h" +#include "c_types/edge_t.h" +#include "c_types/iid_t_rt.h" +#include "c_types/pickDeliver/orders_t.h" +#include "c_types/restriction_t.h" +#include "c_types/point_on_edge_t.h" +#include "c_types/pickDeliver/vehicle_t.h" + + +namespace pgrouting { + +void fetch_combination( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const std::vector &info, + int64_t*, + II_t_rt *combination, + size_t* valid_combinations, + bool) { + combination->d1.source = pgrouting::getBigInt(tuple, tupdesc, info[0]); + combination->d2.target = pgrouting::getBigInt(tuple, tupdesc, info[1]); + + *valid_combinations = *valid_combinations + 1; +} + +void fetch_coordinate( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const std::vector &info, + int64_t *default_id, + Coordinate_t* coordinate, + size_t*, + bool) { + if (pgrouting::column_found(info[0].colNumber)) { + coordinate->id = pgrouting::getBigInt(tuple, tupdesc, info[0]); + } else { + coordinate->id = *default_id; + ++(*default_id); + } + coordinate->x = pgrouting::getFloat8(tuple, tupdesc, info[1]); + coordinate->y = pgrouting::getFloat8(tuple, tupdesc, info[2]); +} + +void fetch_delauny( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const std::vector &info, + int64_t*, + Delauny_t* delauny, + size_t*, + bool) { + delauny->tid = pgrouting::getBigInt(tuple, tupdesc, info[0]); + delauny->pid = pgrouting::getBigInt(tuple, tupdesc, info[1]); + delauny->x = pgrouting::getFloat8(tuple, tupdesc, info[2]); + delauny->y = pgrouting::getFloat8(tuple, tupdesc, info[3]); +} + +/* edges have many fetchers */ + +void fetch_basic_edge( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const std::vector &info, + int64_t *default_id, + Edge_bool_t *edge, + size_t *valid_edges, + bool) { + if (pgrouting::column_found(info[0].colNumber)) { + edge->id = pgrouting::getBigInt(tuple, tupdesc, info[0]); + } else { + edge->id = *default_id; + ++(*default_id); + } + bool new_columns = pgrouting::column_found(info[5].colNumber); + + edge->source = pgrouting::getBigInt(tuple, tupdesc, info[1]); + edge->target = pgrouting::getBigInt(tuple, tupdesc, info[2]); + + if (new_columns) { + edge->going = pgrouting::getFloat8(tuple, tupdesc, info[5]) > 0 + || (pgrouting::column_found(info[6].colNumber) + && pgrouting::getFloat8(tuple, tupdesc, info[6]) > 0); + } else { + edge->going = pgrouting::getFloat8(tuple, tupdesc, info[3]) > 0 + || (pgrouting::column_found(info[4].colNumber) + && pgrouting::getFloat8(tuple, tupdesc, info[4]) > 0); + } + + (*valid_edges)++; +} + +void fetch_edge( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const std::vector &info, + int64_t *default_id, + Edge_t *edge, + size_t *valid_edges, + bool normal) { + if (pgrouting::column_found(info[0].colNumber)) { + edge->id = pgrouting::getBigInt(tuple, tupdesc, info[0]); + } else { + edge->id = *default_id; + ++(*default_id); + } + + if (normal) { + edge->source = pgrouting::getBigInt(tuple, tupdesc, info[1]); + edge->target = pgrouting::getBigInt(tuple, tupdesc, info[2]); + } else { + edge->target = pgrouting::getBigInt(tuple, tupdesc, info[1]); + edge->source = pgrouting::getBigInt(tuple, tupdesc, info[2]); + } + + edge->cost = pgrouting::getFloat8(tuple, tupdesc, info[3]); + + if (pgrouting::column_found(info[4].colNumber)) { + edge->reverse_cost = pgrouting::getFloat8(tuple, tupdesc, info[4]); + } else { + edge->reverse_cost = -1; + } + + edge->cost = std::isinf(edge->cost)? + DBL_MAX : edge->cost; + + edge->reverse_cost = std::isinf(edge->reverse_cost)? + DBL_MAX : edge->reverse_cost; + + *valid_edges = edge->cost < 0? *valid_edges: *valid_edges + 1; + *valid_edges = edge->reverse_cost < 0? *valid_edges: *valid_edges + 1; +} + +void fetch_costFlow_edge( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const std::vector &info, + int64_t *default_id, + CostFlow_t *edge, + size_t *valid_edges, + bool normal) { + if (pgrouting::column_found(info[0].colNumber)) { + edge->edge_id = pgrouting::getBigInt(tuple, tupdesc, info[0]); + } else { + edge->edge_id = *default_id; + ++(*default_id); + } + + if (normal) { + edge->source = pgrouting::getBigInt(tuple, tupdesc, info[1]); + edge->target = pgrouting::getBigInt(tuple, tupdesc, info[2]); + } else { + edge->target = pgrouting::getBigInt(tuple, tupdesc, info[1]); + edge->source = pgrouting::getBigInt(tuple, tupdesc, info[2]); + } + + edge->capacity = pgrouting::getBigInt(tuple, tupdesc, info[3]); + if (pgrouting::column_found(info[4].colNumber)) { + edge->reverse_capacity = pgrouting::getBigInt(tuple, tupdesc, info[4]); + } else { + edge->reverse_capacity = -1; + } + + edge->cost = pgrouting::getFloat8(tuple, tupdesc, info[5]); + if (pgrouting::column_found(info[6].colNumber)) { + edge->reverse_cost = pgrouting::getFloat8(tuple, tupdesc, info[6]); + } else { + edge->reverse_cost = 0; + } + + *valid_edges = edge->capacity < 0? *valid_edges: *valid_edges + 1; + *valid_edges = edge->reverse_capacity < 0? *valid_edges: *valid_edges + 1; +} + +void fetch_edge_with_xy( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const std::vector &info, + int64_t *default_id, + Edge_xy_t *edge, + size_t *valid_edges, + bool normal) { + if (pgrouting::column_found(info[0].colNumber)) { + edge->id = pgrouting::getBigInt(tuple, tupdesc, info[0]); + } else { + edge->id = *default_id; + ++(*default_id); + } + + if (normal) { + edge->source = pgrouting::getBigInt(tuple, tupdesc, info[1]); + edge->target = pgrouting::getBigInt(tuple, tupdesc, info[2]); + } else { + edge->target = pgrouting::getBigInt(tuple, tupdesc, info[1]); + edge->source = pgrouting::getBigInt(tuple, tupdesc, info[2]); + } + edge->cost = pgrouting::getFloat8(tuple, tupdesc, info[3]); + + if (pgrouting::column_found(info[4].colNumber)) { + edge->reverse_cost = pgrouting::getFloat8(tuple, tupdesc, info[4]); + } else { + edge->reverse_cost = -1; + } + + edge->x1 = pgrouting::getFloat8(tuple, tupdesc, info[5]); + edge->y1 = pgrouting::getFloat8(tuple, tupdesc, info[6]); + edge->x2 = pgrouting::getFloat8(tuple, tupdesc, info[7]); + edge->y2 = pgrouting::getFloat8(tuple, tupdesc, info[8]); + + *valid_edges = edge->cost < 0? *valid_edges: *valid_edges + 1; + *valid_edges = edge->reverse_cost < 0? *valid_edges: *valid_edges + 1; +} + +void pgr_fetch_row( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const std::vector &info, + int64_t*, + IID_t_rt *distance, + size_t*, + bool) { + distance->from_vid = pgrouting::getBigInt(tuple, tupdesc, info[0]); + distance->to_vid = pgrouting::getBigInt(tuple, tupdesc, info[1]); + distance->cost = pgrouting::getFloat8(tuple, tupdesc, info[2]); +} + + +void fetch_orders( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const std::vector &info, + int64_t*, + Orders_t* pd_order, + size_t*, + bool with_id) { + pd_order->id = pgrouting::getBigInt(tuple, tupdesc, info[0]); + pd_order->demand = pgrouting::getFloat8(tuple, tupdesc, info[1]); + + /* + * the pickups + */ + pd_order->pick_x = with_id ? + 0 : pgrouting::getFloat8(tuple, tupdesc, info[2]); + pd_order->pick_y = with_id ? + 0 : pgrouting::getFloat8(tuple, tupdesc, info[3]); + pd_order->pick_open_t = pgrouting::getFloat8(tuple, tupdesc, info[4]); + pd_order->pick_close_t = pgrouting::getFloat8(tuple, tupdesc, info[5]); + pd_order->pick_service_t = pgrouting::column_found(info[6].colNumber) ? + pgrouting::getFloat8(tuple, tupdesc, info[6]) : 0; + + /* + * the deliveries + */ + pd_order->deliver_x = with_id ? + 0 : pgrouting::getFloat8(tuple, tupdesc, info[7]); + pd_order->deliver_y = with_id ? + 0 : pgrouting::getFloat8(tuple, tupdesc, info[8]); + pd_order->deliver_open_t = pgrouting::getFloat8(tuple, tupdesc, info[9]); + pd_order->deliver_close_t = pgrouting::getFloat8(tuple, tupdesc, info[10]); + pd_order->deliver_service_t = pgrouting::column_found(info[11].colNumber) ? + pgrouting::getFloat8(tuple, tupdesc, info[11]) : 0; + + pd_order->pick_node_id = with_id ? + pgrouting::getBigInt(tuple, tupdesc, info[12]) : 0; + pd_order->deliver_node_id = with_id ? + pgrouting::getBigInt(tuple, tupdesc, info[13]) : 0; +} + + +void fetch_restriction( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const std::vector &info, + int64_t*, + Restriction_t *restriction, + size_t*, + bool) { + restriction->cost = pgrouting::getFloat8(tuple, tupdesc, info[0]); + + restriction->via = NULL; + restriction->via_size = 0; + restriction->via = pgrouting::getBigIntArr(tuple, tupdesc, info[1], &restriction->via_size); +} + + +void fetch_point( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const std::vector &info, + int64_t *default_pid, + Point_on_edge_t* point, + size_t*, + bool) { + if (pgrouting::column_found(info[0].colNumber)) { + point->pid = pgrouting::getBigInt(tuple, tupdesc, info[0]); + } else { + ++(*default_pid); + point->pid = *default_pid; + } + + point->edge_id = pgrouting::getBigInt(tuple, tupdesc, info[1]); + point->fraction = pgrouting::getFloat8(tuple, tupdesc, info[2]); + + if (pgrouting::column_found(info[3].colNumber)) { + point->side = pgrouting::getChar(tuple, tupdesc, info[3], false, 'b'); + } else { + point->side = 'b'; + } +} + +void fetch_vehicle( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const std::vector &info, + int64_t*, + Vehicle_t *vehicle, + size_t*, + bool with_id) { + vehicle->id = pgrouting::getBigInt(tuple, tupdesc, info[0]); + vehicle->capacity = pgrouting::getFloat8(tuple, tupdesc, info[1]); + + vehicle->start_x = with_id ? + 0 : + pgrouting::getFloat8(tuple, tupdesc, info[2]); + vehicle->start_y = with_id ? + 0 : + pgrouting::getFloat8(tuple, tupdesc, info[3]); + + vehicle->speed = pgrouting::column_found(info[13].colNumber) ? + pgrouting::getFloat8(tuple, tupdesc, info[13]) : + 1; + vehicle->cant_v = pgrouting::column_found(info[4].colNumber) ? + pgrouting::getBigInt(tuple, tupdesc, info[4]) : + 1; + vehicle->start_open_t = pgrouting::column_found(info[5].colNumber) ? + pgrouting::getFloat8(tuple, tupdesc, info[5]) : + 0; + vehicle->start_close_t = pgrouting::column_found(info[6].colNumber) ? + pgrouting::getFloat8(tuple, tupdesc, info[6]) : + DBL_MAX; + vehicle->start_service_t = pgrouting::column_found(info[7].colNumber) ? + pgrouting::getFloat8(tuple, tupdesc, info[7]) : + 0; + + + if (!(pgrouting::column_found(info[8].colNumber)) + && pgrouting::column_found(info[9].colNumber)) { + ereport(ERROR, + (errmsg("Column \'%s\' not Found", info[8].name.c_str()), + errhint("%s was found, also column is expected %s ", + info[9].name.c_str(), info[8].name.c_str()))); + } + if (pgrouting::column_found(info[8].colNumber) + && !(pgrouting::column_found(info[9].colNumber))) { + ereport(ERROR, + (errmsg("Column \'%s\' not Found", info[9].name.c_str()), + errhint("%s was found, also column is expected %s ", + info[8].name.c_str(), info[9].name.c_str()))); + } + + vehicle->end_x = pgrouting::column_found(info[8].colNumber) ? + pgrouting::getFloat8(tuple, tupdesc, info[8]) : + vehicle->start_x; + vehicle->end_y = pgrouting::column_found(info[9].colNumber) ? + pgrouting::getFloat8(tuple, tupdesc, info[9]) : + vehicle->start_y; + + if (!(pgrouting::column_found(info[10].colNumber)) + && pgrouting::column_found(info[11].colNumber)) { + ereport(ERROR, + (errmsg("Column \'%s\' not Found", info[10].name.c_str()), + errhint("%s was found, also column is expected %s ", + info[10].name.c_str(), info[11].name.c_str()))); + } + + if (pgrouting::column_found(info[10].colNumber) + && !(pgrouting::column_found(info[11].colNumber))) { + ereport(ERROR, + (errmsg("Column \'%s\' not Found", info[11].name.c_str()), + errhint("%s was found, also column is expected %s ", + info[11].name.c_str(), info[10].name.c_str()))); + } + vehicle->end_open_t = pgrouting::column_found(info[10].colNumber) ? + pgrouting::getFloat8(tuple, tupdesc, info[10]) : + vehicle->start_open_t; + vehicle->end_close_t = pgrouting::column_found(info[11].colNumber) ? + pgrouting::getFloat8(tuple, tupdesc, info[11]) : + vehicle->start_close_t; + vehicle->end_service_t = pgrouting::column_found(info[12].colNumber) ? + pgrouting::getFloat8(tuple, tupdesc, info[12]) : + vehicle->start_service_t; + + vehicle->speed = pgrouting::column_found(info[13].colNumber) ? + pgrouting::getFloat8(tuple, tupdesc, info[13]) : + 1; + vehicle->start_node_id = with_id ? + pgrouting::getBigInt(tuple, tupdesc, info[14]) : + 0; + vehicle->end_node_id = with_id ? + (pgrouting::column_found(info[12].colNumber) ? + pgrouting::getBigInt(tuple, tupdesc, info[15]) : + vehicle->start_node_id) : + 0; +} + +} // namespace pgrouting diff --git a/src/cpp_common/pgdata_getters.cpp b/src/cpp_common/pgdata_getters.cpp new file mode 100644 index 00000000000..8b448e54a76 --- /dev/null +++ b/src/cpp_common/pgdata_getters.cpp @@ -0,0 +1,670 @@ +/*PGR-GNU***************************************************************** +File: pgdata_getters.cpp + +Copyright (c) 2023 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev +Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI +mail: m_attia_sakrcw at yahoo.com, estebanzimanyicw at gmail.com +Copyright (c) 2016 Rohith Reddy +Copyright (c) 2016 Andrea Nardelli +mail: nrd.nardelli at gmail.com +Copyright (c) 2015 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev + + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + +#include "c_common/pgdata_getters.h" +#include +#include +#include +#include + +#include "cpp_common/get_data.hpp" +#include "cpp_common/get_check_data.hpp" +#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/pgdata_fetchers.hpp" + +#include "c_types/info_t.hpp" +#include "c_types/coordinate_t.h" +#include "c_types/costFlow_t.h" +#include "c_types/ii_t_rt.h" +#include "c_types/iid_t_rt.h" +#include "c_types/delauny_t.h" +#include "c_types/edge_t.h" +#include "c_types/edge_bool_t_rt.h" +#include "c_types/edge_xy_t.h" +#include "c_types/flow_t.h" +#include "c_types/pickDeliver/orders_t.h" +#include "c_types/pickDeliver/vehicle_t.h" +#include "c_types/point_on_edge_t.h" +#include "c_types/restriction_t.h" + + +/** + * @param[out] arrlen Length of the array + * @param[in] input the postgres array + * @param[in] allow_empty when true, empty arrays are accepted. + * @param[out] err_msg when not null, there was an error and contains the message + * @returns Returns a C array of integers + */ +int64_t* pgr_get_bigIntArray(size_t *arrlen, ArrayType *input, bool allow_empty, char** err_msg) { + using pgrouting::pgr_msg; + try { + return pgrouting::get_array(input, arrlen, allow_empty); + } catch (const std::string &ex) { + (*arrlen) = 0; + *err_msg = pgr_msg(ex.c_str()); + return nullptr; + } catch(...) { + (*arrlen) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + return nullptr; + } +} + + +/** + For queries of the type: + ~~~~{.c} + SELECT source, target FROM combinations; + ~~~~ + + @param[in] sql The query + @param [out] rows array of combinations + @param [out] total_rows size of combinations + @param[out] err_msg when not null, there was an error and contains the message + */ +void pgr_get_combinations( + char *sql, + II_t_rt **rows, + size_t *total_rows, + char **err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + using pgrouting::Column_info_t; + try { + std::vector info{2}; + + info[0] = {-1, 0, true, "source", pgrouting::ANY_INTEGER}; + info[1] = {-1, 0, true, "target", pgrouting::ANY_INTEGER}; + pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_combination); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} + + +/** + For queries of the type: + ~~~~{.c} + SELECT id, x, y FROM coordinates; + ~~~~ + + @param[in] sql The query + @param[out] rows the matrix coordinates + @param[out] total_rows size of coordinates + @param[out] err_msg when not null, there was an error and contains the message + */ +void pgr_get_coordinates( + char *sql, + Coordinate_t **rows, + size_t *total_rows, + char **err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + using pgrouting::Column_info_t; + try { + std::vector info{3}; + + info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; + info[1] = {-1, 0, true, "x", pgrouting::ANY_NUMERICAL}; + info[2] = {-1, 0, true, "y", pgrouting::ANY_NUMERICAL}; + pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_coordinate); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} + + +/** + For queries of the type: + ~~~~{.c} + SELECT tid, pid, x, y FROM delauny; + SELECT pid, pid, x, y FROM delauny; + ~~~~ + + @param[in] sql The query + @param[out] rows the delauny array + @param[out] total_rows size of delauny + @param[out] err_msg when not null, there was an error and contains the message + */ +void pgr_get_delauny( + char *sql, + Delauny_t **rows, + size_t *total_rows, + char **err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + using pgrouting::Column_info_t; + try { + std::vector info{4}; + + info[0] = {-1, 0, true, "tid", pgrouting::ANY_INTEGER}; + info[1] = {-1, 0, true, "pid", pgrouting::ANY_INTEGER}; + info[2] = {-1, 0, true, "x", pgrouting::ANY_NUMERICAL}; + info[3] = {-1, 0, true, "y", pgrouting::ANY_NUMERICAL}; + pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_delauny); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} + + +/** + For queries of the type: + ~~~~{.c} + SELECT id, source, target, capacity, [reverse_capacity] FROM edge_table; + ~~~~ + + @param[in] sql The query + @param[out] rows the edges array + @param[out] total_rows size of edges + @param[out] err_msg when not null, there was an error and contains the message + */ +void +pgr_get_flow_edges( + char *sql, + Edge_t **rows, + size_t *total_rows, + char **err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + using pgrouting::Column_info_t; + try { + std::vector info{5}; + + info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; + info[1] = {-1, 0, true, "source", pgrouting::ANY_INTEGER}; + info[2] = {-1, 0, true, "target", pgrouting::ANY_INTEGER}; + info[3] = {-1, 0, true, "capacity", pgrouting::ANY_INTEGER}; + info[4] = {-1, 0, false, "reverse_capacity", pgrouting::ANY_INTEGER}; + + pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_edge); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} + +/** + For queries of the type: + ~~~~{.c} + SELECT id, source, target, capacity, [reverse_capacity], cost, [reverse_cost] + FROM edge_table; + ~~~~ + + @param[in] sql The query + @param[out] rows the edges array + @param[out] total_rows size of edges + @param[out] err_msg when not null, there was an error and contains the message + */ +void +pgr_get_costFlow_edges( + char *sql, + CostFlow_t **rows, + size_t *total_rows, + char **err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + using pgrouting::Column_info_t; + try { + std::vector info{7}; + + info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; + info[1] = {-1, 0, true, "source", pgrouting::ANY_INTEGER}; + info[2] = {-1, 0, true, "target", pgrouting::ANY_INTEGER}; + info[3] = {-1, 0, true, "capacity", pgrouting::ANY_INTEGER}; + info[4] = {-1, 0, false, "reverse_capacity", pgrouting::ANY_INTEGER}; + info[5] = {-1, 0, true, "cost", pgrouting::ANY_NUMERICAL}; + info[6] = {-1, 0, false, "reverse_cost", pgrouting::ANY_NUMERICAL}; + + pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_costFlow_edge); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} + + +/** + For queries of the type: + ~~~~{.c} + SELECT id, source, target, cost, [reverse_cost] FROM edge_table; + ~~~~ + + For backward compatability it also accepts: + ~~~~{.c} + SELECT id, source, target, going, [coming] FROM edge_table; + ~~~~ + @todo This option will be removed on V4 + + @param[in] sql The query + @param[out] rows the edges array + @param[out] total_rows size of edges + @param[out] err_msg when not null, there was an error and contains the message + */ +void +pgr_get_basic_edges( + char *sql, + Edge_bool_t **rows, + size_t *total_rows, + char **err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + using pgrouting::Column_info_t; + try { + std::vector info{7}; + + info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; + info[1] = {-1, 0, true, "source", pgrouting::ANY_INTEGER}; + info[2] = {-1, 0, true, "target", pgrouting::ANY_INTEGER}; + info[3] = {-1, 0, false, "going", pgrouting::ANY_NUMERICAL}; + info[4] = {-1, 0, false, "coming", pgrouting::ANY_NUMERICAL}; + info[5] = {-1, 0, false, "cost", pgrouting::ANY_NUMERICAL}; + info[6] = {-1, 0, false, "reverse_cost", pgrouting::ANY_NUMERICAL}; + + pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_basic_edge); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} + +/** + For queries of the type: + ~~~~{.c} + SELECT id, source, target, cost, [reverse_cost], x1, y1, x2, y2 FROM edge_table; + ~~~~ + + @param[in] sql The query + @param[out] rows the edges array + @param[out] total_rows size of edges + @param[in] normal when false then the graph is reversed + @param[out] err_msg when not null, there was an error and contains the message + */ +void +pgr_get_edges_xy( + char *sql, + Edge_xy_t **rows, + size_t *total_rows, + bool normal, + char **err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + using pgrouting::Column_info_t; + try { + std::vector info{9}; + + info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; + info[1] = {-1, 0, true, "source", pgrouting::ANY_INTEGER}; + info[2] = {-1, 0, true, "target", pgrouting::ANY_INTEGER}; + info[3] = {-1, 0, true, "cost", pgrouting::ANY_NUMERICAL}; + info[4] = {-1, 0, false, "reverse_cost", pgrouting::ANY_NUMERICAL}; + info[5] = {-1, 0, true, "x1", pgrouting::ANY_NUMERICAL}; + info[6] = {-1, 0, true, "y1", pgrouting::ANY_NUMERICAL}; + info[7] = {-1, 0, true, "x2", pgrouting::ANY_NUMERICAL}; + info[8] = {-1, 0, true, "y2", pgrouting::ANY_NUMERICAL}; + + pgrouting::get_data(sql, rows, total_rows, normal, info, &pgrouting::fetch_edge_with_xy); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} + +/** + For queries of the type: + ~~~~{.c} + SELECT id, source, target, cost, [reverse_cost] FROM edge_table; + ~~~~ + + @param[in] sql The query + @param[out] rows the edges array + @param[out] total_rows size of edges + @param[in] normal when false then the graph is reversed + @param[in] ignore_id when true id value of edge is ignored + @param[out] err_msg when not null, there was an error and contains the message + */ +void +pgr_get_edges( + char *sql, + Edge_t **rows, + size_t *total_rows, + bool normal, + bool ignore_id, + char **err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + using pgrouting::Column_info_t; + try { + std::vector info{5}; + + info[0] = {-1, 0, !ignore_id, "id", pgrouting::ANY_INTEGER}; + info[1] = {-1, 0, true, "source", pgrouting::ANY_INTEGER}; + info[2] = {-1, 0, true, "target", pgrouting::ANY_INTEGER}; + info[3] = {-1, 0, true, "cost", pgrouting::ANY_NUMERICAL}; + info[4] = {-1, 0, false, "reverse_cost", pgrouting::ANY_NUMERICAL}; + + pgrouting::get_data(sql, rows, total_rows, normal, info, &pgrouting::fetch_edge); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} + + +/** + For queries of the type: + ~~~~{.c} + SELECT start_vid, end_vid, agg_cost FROM matrix_data; + ~~~~ + + @param[in] sql The query + @param[out] rows of the matrix array + @param[out] total_rows size of matrix rows + @param[out] err_msg when not null, there was an error and contains the message + */ +void pgr_get_matrixRows( + char *sql, + IID_t_rt **rows, + size_t *total_rows, + char **err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + using pgrouting::Column_info_t; + try { + std::vector info{3}; + + info[0] = {-1, 0, true, "start_vid", pgrouting::ANY_INTEGER}; + info[1] = {-1, 0, true, "end_vid", pgrouting::ANY_INTEGER}; + info[2] = {-1, 0, true, "agg_cost", pgrouting::ANY_NUMERICAL}; + pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::pgr_fetch_row); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} + + +/** + For queries of the type: + ~~~~{.c} + SELECT id, demand + [p_node_id | p_x, p_y], p_open, p_close, p_service, + [d_node_id | d_x, d_y], d_open, d_close, d_service, + FROM orders; + ~~~~ + + @param[in] sql The query + @param[out] rows of the orders + @param[out] total_rows size of orders rows + @param[out] with_id flag to choose if its euclidean or matrix + @param[out] err_msg when not null, there was an error and contains the message + */ +void pgr_get_orders( + char *sql, + Orders_t **rows, + size_t *total_rows, + bool with_id, + char **err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + using pgrouting::Column_info_t; + try { + std::vector info{14}; + + info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; + info[1] = {-1, 0, true, "demand", pgrouting::ANY_NUMERICAL}; + info[2] = {-1, 0, true, "p_x", pgrouting::ANY_NUMERICAL}; + info[3] = {-1, 0, true, "p_y", pgrouting::ANY_NUMERICAL}; + info[4] = {-1, 0, true, "p_open", pgrouting::ANY_NUMERICAL}; + info[5] = {-1, 0, true, "p_close", pgrouting::ANY_NUMERICAL}; + info[6] = {-1, 0, false, "p_service", pgrouting::ANY_NUMERICAL}; + info[7] = {-1, 0, true, "d_x", pgrouting::ANY_NUMERICAL}; + info[8] = {-1, 0, true, "d_y", pgrouting::ANY_NUMERICAL}; + info[9] = {-1, 0, true, "d_open", pgrouting::ANY_NUMERICAL}; + info[10] = {-1, 0, true, "d_close", pgrouting::ANY_NUMERICAL}; + info[11] = {-1, 0, false, "d_service", pgrouting::ANY_NUMERICAL}; + /* nodes are going to be ignored*/ + info[12] = {-1, 0, false, "p_node_id", pgrouting::ANY_INTEGER}; + info[13] = {-1, 0, false, "d_node_id", pgrouting::ANY_INTEGER}; + + if (with_id) { + /* (x,y) values are ignored*/ + info[2].strict = false; + info[3].strict = false; + info[7].strict = false; + info[8].strict = false; + /* nodes are compulsory*/ + info[12].strict = true; + info[13].strict = true; + } + + pgrouting::get_data(sql, rows, total_rows, with_id, info, &pgrouting::fetch_orders); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} + + +/** + For queries of the type: + ~~~~{.c} + SELECT pid, edge_id, fraction side FROM points; + ~~~~ + + @param[in] sql The query + @param[out] rows the points array + @param[out] total_rows size of points + @param[out] err_msg when not null, there was an error and contains the message + */ +void pgr_get_points( + char *sql, + Point_on_edge_t **rows, + size_t *total_rows, + char **err_msg) { + using pgrouting::pgr_free; + using pgrouting::pgr_msg; + using pgrouting::Column_info_t; + try { + std::vector info{4}; + + info[0] = {-1, 0, false, "pid", pgrouting::ANY_INTEGER}; + info[1] = {-1, 0, true, "edge_id", pgrouting::ANY_INTEGER}; + info[2] = {-1, 0, true, "fraction", pgrouting::ANY_NUMERICAL}; + info[3] = {-1, 0, false, "side", pgrouting::CHAR1}; + pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_point); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} + + +/** + For queries of the type: + ~~~~{.c} + SELECT cost, path FROM restrictions; + ~~~~ + + @param[in] sql The query + @param[out] rows the restrictions array + @param[out] total_rows size of restrictions + @param[out] err_msg when not null, there was an error and contains the message + */ +void pgr_get_restrictions( + char *sql, + Restriction_t **rows, + size_t *total_rows, + char **err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + using pgrouting::Column_info_t; + try { + std::vector info{2}; + + info[0] = {-1, 0, true, "cost", pgrouting::ANY_NUMERICAL}; + info[1] = {-1, 0, true, "path", pgrouting::ANY_INTEGER_ARRAY}; + pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_restriction); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} + + +/** + For queries of the type: + ~~~~{.c} + SELECT id, capacity, speed, number + [start_node_id | start_x, start_y], start_open, start_close, start_service, + [end_node_id | end_x, end_y], end_open, end_close, end_service, + FROM orders; + ~~~~ + + @param[in] sql The query + @param[out] rows of vehicles + @param[out] total_rows size of vehicles rows + @param[out] with_id flag to choose if its euclidean or matrix + @param[out] err_msg when not null, there was an error and contains the message + */ +void pgr_get_vehicles( + char *sql, + Vehicle_t **rows, + size_t *total_rows, + bool with_id, + char **err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + using pgrouting::Column_info_t; + try { + std::vector info{16}; + + info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; + info[1] = {-1, 0, true, "capacity", pgrouting::ANY_NUMERICAL}; + info[2] = {-1, 0, true, "start_x", pgrouting::ANY_NUMERICAL}; + info[3] = {-1, 0, true, "start_y", pgrouting::ANY_NUMERICAL}; + info[4] = {-1, 0, false, "number", pgrouting::ANY_INTEGER}; + info[5] = {-1, 0, false, "start_open", pgrouting::ANY_NUMERICAL}; + info[6] = {-1, 0, false, "start_close", pgrouting::ANY_NUMERICAL}; + info[7] = {-1, 0, false, "start_service", pgrouting::ANY_NUMERICAL}; + info[8] = {-1, 0, false, "end_x", pgrouting::ANY_NUMERICAL}; + info[9] = {-1, 0, false, "end_y", pgrouting::ANY_NUMERICAL}; + info[10] = {-1, 0, false, "end_open", pgrouting::ANY_NUMERICAL}; + info[11] = {-1, 0, false, "end_close", pgrouting::ANY_NUMERICAL}; + info[12] = {-1, 0, false, "end_service", pgrouting::ANY_NUMERICAL}; + info[13] = {-1, 0, false, "speed", pgrouting::ANY_NUMERICAL}; + /* nodes are going to be ignored*/ + info[14] = {-1, 0, false, "start_node_id", pgrouting::ANY_INTEGER}; + info[15] = {-1, 0, false, "end_node_id", pgrouting::ANY_INTEGER}; + + if (with_id) { + /* (x,y) values are ignored*/ + info[2].strict = false; + info[3].strict = false; + /* start nodes are compulsory*/ + info[14].strict = false; + } + + pgrouting::get_data(sql, rows, total_rows, with_id, info, &pgrouting::fetch_vehicle); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} diff --git a/src/dagShortestPath/dagShortestPath.c b/src/dagShortestPath/dagShortestPath.c index 3edcf77fe89..7cf59e43d26 100644 --- a/src/dagShortestPath/dagShortestPath.c +++ b/src/dagShortestPath/dagShortestPath.c @@ -30,13 +30,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/dagShortestPath/dagShortestPath_driver.h" // the link to the C++ code of the function @@ -59,6 +57,9 @@ process( * https://www.postgresql.org/docs/current/static/spi-spi-connect.html */ pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; @@ -74,12 +75,13 @@ process( II_t_rt *combinations = NULL; if (starts && ends) { - start_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_vidsArr, starts, false); - end_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_vidsArr, ends, false); + start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); if (total_combinations == 0) { if (combinations) pfree(combinations); @@ -95,7 +97,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -106,9 +109,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_dagShortestPath( edges, total_edges, diff --git a/src/dijkstra/dijkstra.c b/src/dijkstra/dijkstra.c index 6eca72f265a..787be235080 100644 --- a/src/dijkstra/dijkstra.c +++ b/src/dijkstra/dijkstra.c @@ -35,14 +35,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" - #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/dijkstra/dijkstra_driver.h" @@ -65,6 +62,9 @@ process( Path_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; int64_t* start_vidsArr = NULL; size_t size_start_vidsArr = 0; @@ -75,17 +75,20 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; if (normal) { - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); - start_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_vidsArr, starts, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); + start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); end_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_vidsArr, ends, false); + pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } else { - pgr_get_edges(edges_sql, &edges, &total_edges, false, false); - end_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_vidsArr, starts, false); - start_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_vidsArr, ends, false); + pgr_get_edges(edges_sql, &edges, &total_edges, false, false, &err_msg); + throw_error(err_msg, edges_sql); + end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } if (total_edges == 0) { @@ -96,9 +99,6 @@ process( } clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_many_to_many_dijkstra( edges, total_edges, start_vidsArr, size_start_vidsArr, @@ -163,6 +163,9 @@ process_combinations( Path_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; Edge_t *edges = NULL; size_t total_edges = 0; @@ -170,13 +173,15 @@ process_combinations( II_t_rt *combinations = NULL; size_t total_combinations = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); return; } - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); if (total_combinations == 0) { if (edges) pfree(edges); pgr_SPI_finish(); @@ -184,9 +189,6 @@ process_combinations( } clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_combinations_dijkstra( edges, total_edges, combinations, total_combinations, diff --git a/src/dijkstra/dijkstraVia.c b/src/dijkstra/dijkstraVia.c index b7d7946d3aa..241ae34cd9a 100644 --- a/src/dijkstra/dijkstraVia.c +++ b/src/dijkstra/dijkstraVia.c @@ -32,7 +32,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/dijkstra/dijkstraVia_driver.h" @@ -49,13 +48,18 @@ process(char* edges_sql, Routes_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; size_t size_via_vidsArr = 0; - int64_t* via_vidsArr = (int64_t*) pgr_get_bigIntArray(&size_via_vidsArr, vias, false); + int64_t* via_vidsArr = pgr_get_bigIntArray(&size_via_vidsArr, vias, false, &err_msg); + throw_error(err_msg, "While getting via vertices"); Edge_t* edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { if (via_vidsArr) pfree(via_vidsArr); @@ -65,9 +69,6 @@ process(char* edges_sql, PGR_DBG("Starting timer"); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_dijkstraVia( edges, total_edges, via_vidsArr, size_via_vidsArr, diff --git a/src/dominator/lengauerTarjanDominatorTree.c b/src/dominator/lengauerTarjanDominatorTree.c index b76a3483710..43d48986df3 100644 --- a/src/dominator/lengauerTarjanDominatorTree.c +++ b/src/dominator/lengauerTarjanDominatorTree.c @@ -51,11 +51,15 @@ process(char* edges_sql, II_t_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; size_t total_edges = 0; Edge_t* edges = NULL; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); return; @@ -63,9 +67,6 @@ process(char* edges_sql, PGR_DBG("Starting timer"); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_LTDTree( edges, total_edges, root_vertex, diff --git a/src/driving_distance/many_to_dist_driving_distance.c b/src/driving_distance/many_to_dist_driving_distance.c index 00fd226d4df..d8289e1a273 100644 --- a/src/driving_distance/many_to_dist_driving_distance.c +++ b/src/driving_distance/many_to_dist_driving_distance.c @@ -24,14 +24,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/driving_distance/drivedist_driver.h" @@ -42,7 +40,7 @@ PG_FUNCTION_INFO_V1(_pgr_drivingdistance); static void process( - char* sql, + char* edges_sql, ArrayType *starts, float8 distance, bool directed, @@ -50,13 +48,18 @@ void process( Path_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; size_t size_start_vidsArr = 0; - int64_t* start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false); + int64_t* start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); Edge_t *edges = NULL; size_t total_tuples = 0; - pgr_get_edges(sql, &edges, &total_tuples, true, false); + pgr_get_edges(edges_sql, &edges, &total_tuples, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_tuples == 0) { return; @@ -64,9 +67,6 @@ void process( PGR_DBG("Starting timer"); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_driving_many_to_dist( edges, total_tuples, start_vidsArr, size_start_vidsArr, diff --git a/src/driving_distance/many_to_dist_withPointsDD.c b/src/driving_distance/many_to_dist_withPointsDD.c index c6e2fdc7539..844934f6175 100644 --- a/src/driving_distance/many_to_dist_withPointsDD.c +++ b/src/driving_distance/many_to_dist_withPointsDD.c @@ -24,14 +24,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/withPoints/get_new_queries.h" @@ -59,14 +57,19 @@ void process( PGR_DBG("estimated driving side:%c", driving_side[0]); pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; size_t total_starts = 0; - int64_t* start_pidsArr = pgr_get_bigIntArray(&total_starts, starts, false); + int64_t* start_pidsArr = pgr_get_bigIntArray(&total_starts, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); PGR_DBG("sourcesArr size %ld ", total_starts); Point_on_edge_t *points = NULL; size_t total_points = 0; - pgr_get_points(points_sql, &points, &total_points); + pgr_get_points(points_sql, &points, &total_points, &err_msg); + throw_error(err_msg, points_sql); char *edges_of_points_query = NULL; char *edges_no_points_query = NULL; @@ -78,11 +81,13 @@ void process( Edge_t *edges_of_points = NULL; size_t total_edges_of_points = 0; - pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false); + pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false, &err_msg); + throw_error(err_msg, edges_of_points_query); Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false); + pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_no_points_query); PGR_DBG("freeing allocated memory not used anymore"); pfree(edges_of_points_query); @@ -98,9 +103,6 @@ void process( PGR_DBG("Starting timer"); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_many_withPointsDD( edges, total_edges, points, total_points, diff --git a/src/ksp/ksp.c b/src/ksp/ksp.c index b950aecd2f2..84ed209c831 100644 --- a/src/ksp/ksp.c +++ b/src/ksp/ksp.c @@ -48,6 +48,9 @@ void compute( bool heap_paths, Path_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; if (p_k < 0) { return; } @@ -64,7 +67,8 @@ void compute( return; } - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -78,9 +82,6 @@ void compute( PGR_DBG("heap_paths = %i\n", heap_paths); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_ksp( edges, diff --git a/src/ksp/turnRestrictedPath.c b/src/ksp/turnRestrictedPath.c index d5eebca5daa..38ac24e2319 100644 --- a/src/ksp/turnRestrictedPath.c +++ b/src/ksp/turnRestrictedPath.c @@ -77,19 +77,23 @@ process( } pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); Restriction_t *restrictions = NULL; size_t total_restrictions = 0; - pgr_get_restrictions(restrictions_sql, &restrictions, - &total_restrictions); + pgr_get_restrictions(restrictions_sql, &restrictions, &total_restrictions, &err_msg); + throw_error(err_msg, restrictions_sql); if (total_edges == 0) { PGR_DBG("No edges found"); @@ -98,9 +102,6 @@ process( } clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_turnRestrictedPath( edges, total_edges, diff --git a/src/ksp/withPoints_ksp.c b/src/ksp/withPoints_ksp.c index a957baf8ae2..ac775c4500b 100644 --- a/src/ksp/withPoints_ksp.c +++ b/src/ksp/withPoints_ksp.c @@ -74,10 +74,14 @@ process( } pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; Point_on_edge_t *points = NULL; size_t total_points = 0; - pgr_get_points(points_sql, &points, &total_points); + pgr_get_points(points_sql, &points, &total_points, &err_msg); + throw_error(err_msg, points_sql); char *edges_of_points_query = NULL; char *edges_no_points_query = NULL; @@ -89,11 +93,13 @@ process( Edge_t *edges_of_points = NULL; size_t total_edges_of_points = 0; - pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false); + pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false, &err_msg); + throw_error(err_msg, edges_of_points_query); Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false); + pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_no_points_query); PGR_DBG("freeing allocated memory not used anymore"); pfree(edges_of_points_query); @@ -110,9 +116,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_withPointsKsp( edges, total_edges, diff --git a/src/lineGraph/lineGraph.c b/src/lineGraph/lineGraph.c index 58b82e49c85..cdc5c72b38e 100644 --- a/src/lineGraph/lineGraph.c +++ b/src/lineGraph/lineGraph.c @@ -77,6 +77,9 @@ process( PGR_DBG("\nUndirectedGraph\n"); } pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; (*result_tuples) = NULL; (*result_count) = 0; @@ -85,7 +88,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -96,9 +100,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_lineGraph( edges, total_edges, diff --git a/src/lineGraph/lineGraphFull.c b/src/lineGraph/lineGraphFull.c index f0526d56769..6647483b6a4 100644 --- a/src/lineGraph/lineGraphFull.c +++ b/src/lineGraph/lineGraphFull.c @@ -49,6 +49,9 @@ process( PGR_DBG("\nSQL QUERY: %s\n", edges_sql); PGR_DBG("\nDirectedGraph\n"); pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; (*result_tuples) = NULL; (*result_count) = 0; @@ -57,7 +60,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -68,9 +72,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_lineGraphFull( edges, total_edges, diff --git a/src/max_flow/edge_disjoint_paths.c b/src/max_flow/edge_disjoint_paths.c index c6082b8472e..05b014cfac0 100644 --- a/src/max_flow/edge_disjoint_paths.c +++ b/src/max_flow/edge_disjoint_paths.c @@ -30,13 +30,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/max_flow/edge_disjoint_paths_driver.h" @@ -55,6 +53,9 @@ process( Path_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; int64_t *source_vertices = NULL; size_t size_source_verticesArr = 0; @@ -70,12 +71,13 @@ process( size_t total_combinations = 0; if (starts && ends) { - source_vertices = (int64_t*) - pgr_get_bigIntArray(&size_source_verticesArr, starts, false); - sink_vertices = (int64_t*) - pgr_get_bigIntArray(&size_sink_verticesArr, ends, false); + source_vertices = pgr_get_bigIntArray(&size_source_verticesArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + sink_vertices = pgr_get_bigIntArray(&size_sink_verticesArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end_vids"); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); if (total_combinations == 0) { if (combinations) pfree(combinations); @@ -84,7 +86,8 @@ process( } } - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { if (source_vertices) pfree(source_vertices); @@ -96,9 +99,6 @@ process( PGR_DBG("Starting timer"); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_edge_disjoint_paths( edges, total_edges, diff --git a/src/max_flow/max_flow.c b/src/max_flow/max_flow.c index 9d5c9a3f92b..6ccb7ad394c 100644 --- a/src/max_flow/max_flow.c +++ b/src/max_flow/max_flow.c @@ -30,13 +30,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" - #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/max_flow/max_flow_driver.h" @@ -61,6 +58,9 @@ process( } pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; int64_t *source_vertices = NULL; size_t size_source_verticesArr = 0; @@ -75,12 +75,13 @@ process( size_t total_combinations = 0; if (starts && ends) { - source_vertices = (int64_t*) - pgr_get_bigIntArray(&size_source_verticesArr, starts, false); - sink_vertices = (int64_t*) - pgr_get_bigIntArray(&size_sink_verticesArr, ends, false); + source_vertices = pgr_get_bigIntArray(&size_source_verticesArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + sink_vertices = pgr_get_bigIntArray(&size_sink_verticesArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); if (total_combinations == 0) { if (combinations) pfree(combinations); @@ -92,7 +93,8 @@ process( /* NOTE: * For flow, cost and reverse_cost are really capacity and reverse_capacity */ - pgr_get_flow_edges(edges_sql, &edges, &total_edges); + pgr_get_flow_edges(edges_sql, &edges, &total_edges, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { if (source_vertices) pfree(source_vertices); @@ -104,9 +106,6 @@ process( PGR_DBG("Starting timer"); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char *err_msg = NULL; do_pgr_max_flow( edges, total_edges, diff --git a/src/max_flow/maximum_cardinality_matching.c b/src/max_flow/maximum_cardinality_matching.c index 5e2afdda12d..4152214a305 100644 --- a/src/max_flow/maximum_cardinality_matching.c +++ b/src/max_flow/maximum_cardinality_matching.c @@ -54,10 +54,14 @@ process( Only_int_rt** result_tuples, size_t* result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; Edge_bool_t* edges = NULL; size_t total_edges = 0; - pgr_get_basic_edges(edges_sql, &edges, &total_edges); + pgr_get_basic_edges(edges_sql, &edges, &total_edges, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); @@ -66,9 +70,6 @@ process( PGR_DBG("Starting timer"); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char *err_msg = NULL; do_pgr_maximum_cardinality_matching( edges, total_edges, diff --git a/src/max_flow/minCostMaxFlow.c b/src/max_flow/minCostMaxFlow.c index 9e999886eaa..d3f29692d7d 100644 --- a/src/max_flow/minCostMaxFlow.c +++ b/src/max_flow/minCostMaxFlow.c @@ -45,13 +45,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include "c_common/postgres_connection.h" -#include "utils/array.h" - #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/max_flow/minCostMaxFlow_driver.h" @@ -78,6 +75,9 @@ process( * https://www.postgresql.org/docs/current/static/spi-spi-connect.html */ pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; int64_t *sourceVertices = NULL; size_t sizeSourceVerticesArr = 0; @@ -93,12 +93,13 @@ process( size_t total_combinations = 0; if (starts && ends) { - sourceVertices = (int64_t*) - pgr_get_bigIntArray(&sizeSourceVerticesArr, starts, false); - sinkVertices = (int64_t*) - pgr_get_bigIntArray(&sizeSinkVerticesArr, ends, false); + sourceVertices = pgr_get_bigIntArray(&sizeSourceVerticesArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + sinkVertices = pgr_get_bigIntArray(&sizeSinkVerticesArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); if (total_combinations == 0) { if (combinations) pfree(combinations); @@ -107,7 +108,8 @@ process( } } - pgr_get_costFlow_edges(edges_sql, &edges, &total_edges); + pgr_get_costFlow_edges(edges_sql, &edges, &total_edges, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -122,9 +124,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_minCostMaxFlow( edges, total_edges, diff --git a/src/mincut/stoerWagner.c b/src/mincut/stoerWagner.c index 77234279bc9..ee53807cc52 100644 --- a/src/mincut/stoerWagner.c +++ b/src/mincut/stoerWagner.c @@ -54,6 +54,9 @@ process( * https://www.postgresql.org/docs/current/static/spi-spi-connect.html */ pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; (*result_tuples) = NULL; (*result_count) = 0; @@ -62,7 +65,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -73,9 +77,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_stoerWagner( edges, total_edges, diff --git a/src/ordering/cuthillMckeeOrdering.c b/src/ordering/cuthillMckeeOrdering.c index b0f58808f58..9b0bafc3f51 100644 --- a/src/ordering/cuthillMckeeOrdering.c +++ b/src/ordering/cuthillMckeeOrdering.c @@ -67,6 +67,9 @@ process( II_t_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; (*result_tuples) = NULL; (*result_count) = 0; @@ -74,7 +77,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { ereport(WARNING, (errmsg("Insufficient data edges SQL."), @@ -87,9 +91,6 @@ process( PGR_DBG("Starting timer"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_cuthillMckeeOrdering( edges, total_edges, diff --git a/src/pickDeliver/pickDeliver.c b/src/pickDeliver/pickDeliver.c index e81dc3a2625..a0785e8fc7d 100644 --- a/src/pickDeliver/pickDeliver.c +++ b/src/pickDeliver/pickDeliver.c @@ -80,16 +80,21 @@ process( } pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; PGR_DBG("Load orders"); Orders_t *pd_orders_arr = NULL; size_t total_pd_orders = 0; - pgr_get_orders(pd_orders_sql, &pd_orders_arr, &total_pd_orders, true); + pgr_get_orders(pd_orders_sql, &pd_orders_arr, &total_pd_orders, true, &err_msg); + throw_error(err_msg, pd_orders_sql); PGR_DBG("Load vehicles"); Vehicle_t *vehicles_arr = NULL; size_t total_vehicles = 0; - pgr_get_vehicles(vehicles_sql, &vehicles_arr, &total_vehicles, true); + pgr_get_vehicles(vehicles_sql, &vehicles_arr, &total_vehicles, true, &err_msg); + throw_error(err_msg, vehicles_sql); PGR_DBG("total vehicles %ld", total_vehicles); @@ -143,7 +148,8 @@ process( PGR_DBG("load matrix"); IID_t_rt *matrix_cells_arr = NULL; size_t total_cells = 0; - pgr_get_matrixRows(matrix_sql, &matrix_cells_arr, &total_cells); + pgr_get_matrixRows(matrix_sql, &matrix_cells_arr, &total_cells, &err_msg); + throw_error(err_msg, matrix_sql); if (total_pd_orders == 0 || total_vehicles == 0 || total_cells == 0) { @@ -159,9 +165,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_pickDeliver( pd_orders_arr, total_pd_orders, diff --git a/src/pickDeliver/pickDeliverEuclidean.c b/src/pickDeliver/pickDeliverEuclidean.c index b294324d54b..7ecb7c07635 100644 --- a/src/pickDeliver/pickDeliverEuclidean.c +++ b/src/pickDeliver/pickDeliverEuclidean.c @@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ #include "c_common/postgres_connection.h" -#include "utils/array.h" + #include "c_common/debug_macro.h" #include "c_common/e_report.h" @@ -84,16 +84,21 @@ process( } pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; PGR_DBG("Load orders"); Orders_t *pd_orders_arr = NULL; size_t total_pd_orders = 0; - pgr_get_orders(pd_orders_sql, &pd_orders_arr, &total_pd_orders, false); + pgr_get_orders(pd_orders_sql, &pd_orders_arr, &total_pd_orders, false, &err_msg); + throw_error(err_msg, pd_orders_sql); PGR_DBG("Load vehicles"); Vehicle_t *vehicles_arr = NULL; size_t total_vehicles = 0; - pgr_get_vehicles(vehicles_sql, &vehicles_arr, &total_vehicles, false); + pgr_get_vehicles(vehicles_sql, &vehicles_arr, &total_vehicles, false, &err_msg); + throw_error(err_msg, vehicles_sql); PGR_DBG("total vehicles %ld", total_vehicles); size_t i; @@ -154,9 +159,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_pickDeliverEuclidean( pd_orders_arr, total_pd_orders, vehicles_arr, total_vehicles, diff --git a/src/planar/boyerMyrvold.c b/src/planar/boyerMyrvold.c index e8ccd70ee72..456079c00ff 100644 --- a/src/planar/boyerMyrvold.c +++ b/src/planar/boyerMyrvold.c @@ -30,7 +30,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" @@ -49,6 +48,9 @@ process( IID_t_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; PGR_DBG("Initializing arrays"); @@ -60,7 +62,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -70,9 +73,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_boyerMyrvold( edges, total_edges, diff --git a/src/planar/isPlanar.c b/src/planar/isPlanar.c index cf98f55a824..14586abf547 100644 --- a/src/planar/isPlanar.c +++ b/src/planar/isPlanar.c @@ -30,7 +30,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" @@ -48,11 +47,15 @@ process( ) { bool planarity = false; pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); @@ -60,10 +63,6 @@ process( } clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; - planarity = do_pgr_isPlanar( edges, diff --git a/src/spanningTree/kruskal.c b/src/spanningTree/kruskal.c index 906ac064cc9..4a42b256e31 100644 --- a/src/spanningTree/kruskal.c +++ b/src/spanningTree/kruskal.c @@ -34,7 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "c_types/mst_rt.h" @@ -57,10 +56,10 @@ process( MST_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; char * fn_name = get_name(0, fn_suffix, &err_msg); if (err_msg) { @@ -69,7 +68,8 @@ process( } size_t size_rootsArr = 0; - int64_t* rootsArr = (int64_t*) pgr_get_bigIntArray(&size_rootsArr, roots, false); + int64_t* rootsArr = pgr_get_bigIntArray(&size_rootsArr, roots, false, &err_msg); + throw_error(err_msg, "While getting start vids"); (*result_tuples) = NULL; (*result_count) = 0; @@ -77,7 +77,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); clock_t start_t = clock(); do_pgr_kruskal( diff --git a/src/spanningTree/prim.c b/src/spanningTree/prim.c index fb5da78ef69..7383107e672 100644 --- a/src/spanningTree/prim.c +++ b/src/spanningTree/prim.c @@ -28,12 +28,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "c_types/mst_rt.h" @@ -56,10 +54,10 @@ process( MST_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; char * fn_name = get_name(1, fn_suffix, &err_msg); if (err_msg) { @@ -68,7 +66,8 @@ process( } size_t size_rootsArr = 0; - int64_t* rootsArr = (int64_t*) pgr_get_bigIntArray(&size_rootsArr, roots, false); + int64_t* rootsArr = pgr_get_bigIntArray(&size_rootsArr, roots, false, &err_msg); + throw_error(err_msg, "While getting start vids"); (*result_tuples) = NULL; (*result_count) = 0; @@ -76,7 +75,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); clock_t start_t = clock(); diff --git a/src/spanningTree/randomSpanningTree.c b/src/spanningTree/randomSpanningTree.c index 7fce9fd9eff..6547d99d00e 100644 --- a/src/spanningTree/randomSpanningTree.c +++ b/src/spanningTree/randomSpanningTree.c @@ -52,6 +52,9 @@ process( * https://www.postgresql.org/docs/current/static/spi-spi-connect.html */ pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; (*result_tuples) = NULL; (*result_count) = 0; @@ -60,7 +63,8 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { @@ -71,9 +75,6 @@ process( PGR_DBG("Starting processing"); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_randomSpanningTree( edges, total_edges, diff --git a/src/topologicalSort/topologicalSort.c b/src/topologicalSort/topologicalSort.c index da5de03af63..7580a769626 100644 --- a/src/topologicalSort/topologicalSort.c +++ b/src/topologicalSort/topologicalSort.c @@ -32,7 +32,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/postgres_connection.h" #include "c_types/i_rt.h" -#include "utils/array.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" @@ -52,16 +51,17 @@ process( I_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); PGR_DBG("Starting timer"); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_topologicalSort( edges, total_edges, result_tuples, diff --git a/src/transitiveClosure/transitiveClosure.c b/src/transitiveClosure/transitiveClosure.c index 5086f2cf0b1..67969ce308e 100644 --- a/src/transitiveClosure/transitiveClosure.c +++ b/src/transitiveClosure/transitiveClosure.c @@ -30,7 +30,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "catalog/pg_type.h" #include "utils/lsyscache.h" @@ -56,10 +55,14 @@ process(char* edges_sql, TransitiveClosure_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; size_t total_edges = 0; Edge_t* edges = NULL; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); return; @@ -67,9 +70,6 @@ process(char* edges_sql, PGR_DBG("Starting timer"); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_transitiveClosure( edges, total_edges, diff --git a/src/traversal/depthFirstSearch.c b/src/traversal/depthFirstSearch.c index 41c9e1f7bba..99d0fbe850e 100644 --- a/src/traversal/depthFirstSearch.c +++ b/src/traversal/depthFirstSearch.c @@ -33,13 +33,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "c_types/mst_rt.h" @@ -75,10 +73,14 @@ process( MST_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; size_t size_rootsArr = 0; - int64_t* rootsArr = (int64_t*) pgr_get_bigIntArray(&size_rootsArr, roots, false); + int64_t* rootsArr = pgr_get_bigIntArray(&size_rootsArr, roots, false, &err_msg); + throw_error(err_msg, "While getting start vids"); (*result_tuples) = NULL; (*result_count) = 0; @@ -86,12 +88,10 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); clock_t start_t = clock(); - char *log_msg = NULL; - char *notice_msg = NULL; - char *err_msg = NULL; do_pgr_depthFirstSearch( edges, total_edges, rootsArr, size_rootsArr, diff --git a/src/trsp/new_trsp.c b/src/trsp/new_trsp.c index 0bff301c7fa..5cc8fcc4e33 100644 --- a/src/trsp/new_trsp.c +++ b/src/trsp/new_trsp.c @@ -28,8 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" - #include "drivers/trsp/trsp_driver.h" @@ -41,7 +39,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_types/restriction_t.h" #include "c_types/path_rt.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" PGDLLEXPORT Datum _trsp(PG_FUNCTION_ARGS); @@ -65,6 +62,9 @@ void process( Path_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; size_t size_start_vidsArr = 0; int64_t* start_vidsArr = NULL; @@ -80,28 +80,27 @@ void process( Restriction_t * restrictions = NULL; size_t total_restrictions = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false); + pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (total_edges == 0) { pgr_SPI_finish(); return; } - pgr_get_restrictions(restrictions_sql, &restrictions, &total_restrictions); + pgr_get_restrictions(restrictions_sql, &restrictions, &total_restrictions, &err_msg); + throw_error(err_msg, restrictions_sql); if (starts && ends) { - start_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_vidsArr, starts, false); - end_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_vidsArr, ends, false); + start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); } clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_trsp( edges, total_edges, diff --git a/src/trsp/trsp.c b/src/trsp/trsp.c index 820472b3f44..d57f2544be8 100644 --- a/src/trsp/trsp.c +++ b/src/trsp/trsp.c @@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/postgres_connection.h" #include "catalog/pg_type.h" #include "c_common/debug_macro.h" +#include "c_common/e_report.h" #include "c_types/trsp/trsp.h" @@ -135,7 +136,7 @@ fetch_restrict(HeapTuple *tuple, TupleDesc *tupdesc, static int compute_trsp( - char* sql, + char* edges_sql, int dovertex, int64_t start_id, double start_pos, @@ -147,13 +148,15 @@ static int compute_trsp( path_element_tt **path, size_t *path_count) { pgr_SPI_connect(); + char* err_msg = NULL; SPIPlanPtr SPIplan; Portal SPIportal; Edge_t *edges = NULL; size_t total_tuples = 0; - pgr_get_edges(sql, &edges, &total_tuples, true, false); + pgr_get_edges(edges_sql, &edges, &total_tuples, true, false, &err_msg); + throw_error(err_msg, edges_sql); // defining min and max vertex id int64_t v_max_id = 0; @@ -224,13 +227,12 @@ static int compute_trsp( restrict_columns_t restrict_columns = {.target_id = -1, .via_path = -1, .to_cost = -1}; - char *err_msg; int ret = -1; if (restrict_sql == NULL) { PGR_DBG("Sql for restrictions is null."); } else { - uint32_t TUPLIMIT = 1000; + int64 TUPLIMIT = 1000; SPIplan = SPI_prepare(restrict_sql, 0, NULL); if (SPIplan == NULL) { diff --git a/src/trsp/trspVia.c b/src/trsp/trspVia.c index d1d92a88a53..1b72ff2e6ca 100644 --- a/src/trsp/trspVia.c +++ b/src/trsp/trspVia.c @@ -24,12 +24,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/routes_t.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/trsp/trspVia_driver.h" @@ -48,13 +46,18 @@ process( Routes_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; size_t size_via = 0; - int64_t* via = (int64_t*) pgr_get_bigIntArray(&size_via, via_arr, false); + int64_t* via = pgr_get_bigIntArray(&size_via, via_arr, false, &err_msg); + throw_error(err_msg, "While getting via vertices"); Edge_t* edges = NULL; size_t size_edges = 0; - pgr_get_edges(edges_sql, &edges, &size_edges, true, false); + pgr_get_edges(edges_sql, &edges, &size_edges, true, false, &err_msg); + throw_error(err_msg, edges_sql); if (size_edges == 0) { if (via) pfree(via); @@ -65,12 +68,10 @@ process( Restriction_t * restrictions = NULL; size_t size_restrictions = 0; - pgr_get_restrictions(restrictions_sql, &restrictions, &size_restrictions); + pgr_get_restrictions(restrictions_sql, &restrictions, &size_restrictions, &err_msg); + throw_error(err_msg, restrictions_sql); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_trspVia( edges, size_edges, restrictions, size_restrictions, diff --git a/src/trsp/trspVia_withPoints.c b/src/trsp/trspVia_withPoints.c index 71a97188709..8ab3b82cbd2 100644 --- a/src/trsp/trspVia_withPoints.c +++ b/src/trsp/trspVia_withPoints.c @@ -24,12 +24,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/routes_t.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/withPoints/get_new_queries.h" #include "drivers/trsp/trspVia_withPoints_driver.h" @@ -55,12 +53,16 @@ process( Routes_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; /* * Processing Via */ size_t size_via = 0; - int64_t* via = (int64_t*) pgr_get_bigIntArray(&size_via, viasArr, false); + int64_t* via = pgr_get_bigIntArray(&size_via, viasArr, false, &err_msg); + throw_error(err_msg, "While getting via vertices"); // TODO(vicky) figure out what happens when one point or 0 points are given @@ -74,7 +76,8 @@ process( Point_on_edge_t *points = NULL; size_t total_points = 0; - pgr_get_points(points_sql, &points, &total_points); + pgr_get_points(points_sql, &points, &total_points, &err_msg); + throw_error(err_msg, points_sql); char *edges_of_points_query = NULL; char *edges_no_points_query = NULL; @@ -89,8 +92,10 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false); - pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false); + pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_no_points_query); + pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false, &err_msg); + throw_error(err_msg, edges_of_points_query); {pfree(edges_of_points_query); edges_of_points_query = NULL;} {pfree(edges_no_points_query); edges_no_points_query = NULL;} @@ -109,12 +114,10 @@ process( Restriction_t * restrictions = NULL; size_t size_restrictions = 0; - pgr_get_restrictions(restrictions_sql, &restrictions, &size_restrictions); + pgr_get_restrictions(restrictions_sql, &restrictions, &size_restrictions, &err_msg); + throw_error(err_msg, restrictions_sql); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_trspVia_withPoints( edges, total_edges, restrictions, size_restrictions, diff --git a/src/trsp/trsp_withPoints.c b/src/trsp/trsp_withPoints.c index fb4fe1c08d2..9055b9ceca4 100644 --- a/src/trsp/trsp_withPoints.c +++ b/src/trsp/trsp_withPoints.c @@ -39,7 +39,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/withPoints/get_new_queries.h" @@ -72,6 +71,9 @@ process( } pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; size_t size_start_pidsArr = 0; int64_t* start_pidsArr = NULL; @@ -96,8 +98,10 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false); - pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false); + pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false, &err_msg); + throw_error(err_msg, edges_of_points_query); + pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_no_points_query); pfree(edges_of_points_query); pfree(edges_no_points_query); @@ -111,27 +115,29 @@ process( /* Managing departure & destination */ if (starts && ends) { - start_pidsArr = (int64_t*) pgr_get_bigIntArray(&size_start_pidsArr, starts, false); - end_pidsArr = (int64_t*) pgr_get_bigIntArray(&size_end_pidsArr, ends, false); + start_pidsArr = (int64_t*) pgr_get_bigIntArray(&size_start_pidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + end_pidsArr = (int64_t*) pgr_get_bigIntArray(&size_end_pidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); } /* Managing Points */ Point_on_edge_t *points = NULL; size_t total_points = 0; - pgr_get_points(points_sql, &points, &total_points); + pgr_get_points(points_sql, &points, &total_points, &err_msg); + throw_error(err_msg, points_sql); /* Managing restrictions */ Restriction_t *restrictions = NULL; size_t restrictions_size = 0; - pgr_get_restrictions(restrictions_sql, &restrictions, &restrictions_size); + pgr_get_restrictions(restrictions_sql, &restrictions, &restrictions_size, &err_msg); + throw_error(err_msg, restrictions_sql); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_trsp_withPoints( edges, total_edges, diff --git a/src/tsp/TSP.c b/src/tsp/TSP.c index 8e0ccf2e8d3..a1ecf2f4e1b 100644 --- a/src/tsp/TSP.c +++ b/src/tsp/TSP.c @@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ #include "c_common/postgres_connection.h" -#include "utils/array.h" + #include "c_types/path_rt.h" #include "c_common/debug_macro.h" @@ -46,7 +46,7 @@ PGDLLEXPORT Datum _pgr_tsp(PG_FUNCTION_ARGS); static void process( - char* distances_sql, + char* matrix_sql, int64_t start_vid, int64_t end_vid, int max_cycles, @@ -54,15 +54,18 @@ process( TSP_tour_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; IID_t_rt *distances = NULL; size_t total_distances = 0; - pgr_get_matrixRows(distances_sql, &distances, &total_distances); - + pgr_get_matrixRows(matrix_sql, &distances, &total_distances, &err_msg); + throw_error(err_msg, matrix_sql); if (total_distances == 0) { ereport(WARNING, (errmsg("Insufficient data found on inner query."), - errhint("%s", distances_sql))); + errhint("%s", matrix_sql))); (*result_count) = 0; (*result_tuples) = NULL; pgr_SPI_finish(); @@ -72,9 +75,6 @@ process( PGR_DBG("Starting timer"); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_tsp( distances, total_distances, diff --git a/src/tsp/euclideanTSP.c b/src/tsp/euclideanTSP.c index aad00a37e2c..b2d1b2650a8 100644 --- a/src/tsp/euclideanTSP.c +++ b/src/tsp/euclideanTSP.c @@ -55,10 +55,14 @@ process( TSP_tour_rt **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; Coordinate_t *coordinates = NULL; size_t total_coordinates = 0; - pgr_get_coordinates(coordinates_sql, &coordinates, &total_coordinates); + pgr_get_coordinates(coordinates_sql, &coordinates, &total_coordinates, &err_msg); + throw_error(err_msg, coordinates_sql); if (total_coordinates == 0) { ereport(WARNING, @@ -72,9 +76,6 @@ process( PGR_DBG("Starting timer"); clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_euclideanTSP( coordinates, total_coordinates, diff --git a/src/withPoints/withPoints.c b/src/withPoints/withPoints.c index b01e4b1554c..0a65ea0c614 100644 --- a/src/withPoints/withPoints.c +++ b/src/withPoints/withPoints.c @@ -29,7 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/path_rt.h" #include "c_types/point_on_edge_t.h" @@ -37,7 +36,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/withPoints/get_new_queries.h" #include "drivers/withPoints/withPoints_driver.h" @@ -67,6 +65,9 @@ process( driving_side[0] = estimate_drivingSide(driving_side[0]); pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; size_t size_start_pidsArr = 0; int64_t* start_pidsArr = NULL; @@ -79,7 +80,8 @@ process( Point_on_edge_t *points = NULL; size_t total_points = 0; - pgr_get_points(points_sql, &points, &total_points); + pgr_get_points(points_sql, &points, &total_points, &err_msg); + throw_error(err_msg, points_sql); #ifndef NDEBUG size_t i; @@ -102,25 +104,30 @@ process( size_t total_edges = 0; if (normal) { - pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false); - pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false); + pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false, &err_msg); + throw_error(err_msg, edges_of_points_query); + pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_no_points_query); if (starts && ends) { - start_pidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_pidsArr, starts, false); - end_pidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_pidsArr, ends, false); + start_pidsArr = pgr_get_bigIntArray(&size_start_pidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + end_pidsArr = pgr_get_bigIntArray(&size_end_pidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations); + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); } } else { - pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, false, false); - pgr_get_edges(edges_no_points_query, &edges, &total_edges, false, false); - - end_pidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_pidsArr, starts, false); - start_pidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_pidsArr, ends, false); + pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, false, false, &err_msg); + throw_error(err_msg, edges_of_points_query); + pgr_get_edges(edges_no_points_query, &edges, &total_edges, false, false, &err_msg); + throw_error(err_msg, edges_no_points_query); + + end_pidsArr = pgr_get_bigIntArray(&size_end_pidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + start_pidsArr = pgr_get_bigIntArray(&size_start_pidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); } @@ -135,9 +142,6 @@ process( } clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_pgr_withPoints( edges, total_edges, diff --git a/src/withPoints/withPointsVia.c b/src/withPoints/withPointsVia.c index 98e070f5db4..92cb5cafbe7 100644 --- a/src/withPoints/withPointsVia.c +++ b/src/withPoints/withPointsVia.c @@ -24,12 +24,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" + #include "c_types/routes_t.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/arrays_input.h" #include "c_common/pgdata_getters.h" #include "drivers/withPoints/get_new_queries.h" #include "drivers/withPoints/withPointsVia_driver.h" @@ -51,6 +50,9 @@ process( Routes_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; driving_side[0] = estimate_drivingSide(driving_side[0]); @@ -58,7 +60,8 @@ process( * Processing Via */ size_t size_vias = 0; - int64_t* vias = (int64_t*) pgr_get_bigIntArray(&size_vias, viasArr, false); + int64_t* vias = pgr_get_bigIntArray(&size_vias, viasArr, false, &err_msg); + throw_error(err_msg, "While getting via vertices"); // TODO(vicky) figure out what happens when one point or 0 points are given @@ -67,7 +70,8 @@ process( */ Point_on_edge_t *points = NULL; size_t total_points = 0; - pgr_get_points(points_sql, &points, &total_points); + pgr_get_points(points_sql, &points, &total_points, &err_msg); + throw_error(err_msg, points_sql); char *edges_of_points_query = NULL; char *edges_no_points_query = NULL; @@ -79,8 +83,10 @@ process( Edge_t *edges = NULL; size_t total_edges = 0; - pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false); - pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false); + pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false, &err_msg); + throw_error(err_msg, edges_no_points_query); + pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false, &err_msg); + throw_error(err_msg, edges_of_points_query); {pfree(edges_of_points_query); edges_of_points_query = NULL;} {pfree(edges_no_points_query); edges_no_points_query = NULL;} @@ -94,9 +100,6 @@ process( } clock_t start_t = clock(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; do_withPointsVia( edges, total_edges, points, total_points,