From b699cde8adfcb40e743fd98958d514581ad2c169 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Sun, 7 Apr 2024 20:53:08 +0200 Subject: [PATCH] Remove long deprecated add_row() Lua command This also removes the special "area" column type which was only used with the add_row() function. --- src/CMakeLists.txt | 1 - src/flex-lua-table.cpp | 5 +- src/flex-table-column.cpp | 9 - src/flex-table-column.hpp | 5 +- src/flex-write.cpp | 72 -------- src/flex-write.hpp | 5 - src/geom-transform.cpp | 247 -------------------------- src/geom-transform.hpp | 128 ------------- src/output-flex.cpp | 163 +---------------- src/output-flex.hpp | 22 +-- tests/bdd/flex/empty-insert.feature | 29 +++ tests/bdd/flex/script-failure.feature | 25 --- 12 files changed, 37 insertions(+), 674 deletions(-) delete mode 100644 src/geom-transform.cpp delete mode 100644 src/geom-transform.hpp create mode 100644 tests/bdd/flex/empty-insert.feature delete mode 100644 tests/bdd/flex/script-failure.feature diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1fe239e02..f8e2fad8f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -62,7 +62,6 @@ if (WITH_LUA) flex-lua-index.cpp flex-lua-table.cpp flex-write.cpp - geom-transform.cpp lua-setup.cpp lua-utils.cpp output-flex.cpp diff --git a/src/flex-lua-table.cpp b/src/flex-lua-table.cpp index a37d1d84e..98888fdd3 100644 --- a/src/flex-lua-table.cpp +++ b/src/flex-lua-table.cpp @@ -342,12 +342,11 @@ setup_flex_table_columns(lua_State *lua_state, flex_table_t *table, lua_getfield(lua_state, -1, "projection"); if (!lua_isnil(lua_state, -1)) { - if (column.is_geometry_column() || - column.type() == table_column_type::area) { + if (column.is_geometry_column()) { column.set_projection(lua_tostring(lua_state, -1)); } else { throw std::runtime_error{"Projection can only be set on " - "geometry and area columns."}; + "geometry columns."}; } } lua_pop(lua_state, 1); // "projection" diff --git a/src/flex-table-column.cpp b/src/flex-table-column.cpp index c27b74318..fa0e10a07 100644 --- a/src/flex-table-column.cpp +++ b/src/flex-table-column.cpp @@ -51,7 +51,6 @@ static std::array const column_types = { {"multilinestring", table_column_type::multilinestring}, {"multipolygon", table_column_type::multipolygon}, {"geometrycollection", table_column_type::geometrycollection}, - {"area", table_column_type::area}, {"id_type", table_column_type::id_type}, {"id_num", table_column_type::id_num}}}; @@ -62,12 +61,6 @@ static table_column_type get_column_type_from_string(std::string const &type) throw fmt_error("Unknown column type '{}'.", type); } - if (column_type->type == table_column_type::area) { - log_warn("The 'area' column type is deprecated. Please read"); - log_warn("https://osm2pgsql.org/doc/tutorials/" - "switching-from-add-row-to-insert/"); - } - return column_type->type; } @@ -167,8 +160,6 @@ std::string flex_table_column_t::sql_type_name() const return fmt::format("Geometry(MULTIPOLYGON, {})", m_srid); case table_column_type::geometrycollection: return fmt::format("Geometry(GEOMETRYCOLLECTION, {})", m_srid); - case table_column_type::area: - return "real"; case table_column_type::id_type: return "char(1)"; case table_column_type::id_num: diff --git a/src/flex-table-column.hpp b/src/flex-table-column.hpp index c14edc320..4410e03da 100644 --- a/src/flex-table-column.hpp +++ b/src/flex-table-column.hpp @@ -46,8 +46,6 @@ enum class table_column_type : uint8_t multipolygon, geometrycollection, - area, - id_type, id_num }; @@ -158,8 +156,7 @@ class flex_table_column_t table_column_type m_type; /** - * For geometry and area columns only: The projection SRID. Default is - * web mercator. + * For geometry columns only: The projection SRID. Default is web mercator. */ int m_srid = 3857; diff --git a/src/flex-write.cpp b/src/flex-write.cpp index c0090591d..376e75537 100644 --- a/src/flex-write.cpp +++ b/src/flex-write.cpp @@ -257,14 +257,6 @@ void flex_write_column(lua_State *lua_state, flex_table_column_t const &column, std::vector *expire) { - // If there is nothing on the Lua stack, then the Lua function add_row() - // was called without a table parameter. In that case this column will - // be set to NULL. - if (lua_gettop(lua_state) == 0) { - write_null(copy_mgr, column); - return; - } - lua_getfield(lua_state, -1, column.name().c_str()); int const ltype = lua_type(lua_state, -1); @@ -414,9 +406,6 @@ void flex_write_column(lua_State *lua_state, lua_typename(lua_state, ltype)); } } else if (column.is_geometry_column()) { - // If this is a geometry column, the Lua function 'insert()' was - // called, because for 'add_row()' geometry columns are handled - // earlier and 'write_column()' is not called. if (ltype == LUA_TUSERDATA) { auto const *const geom = unpack_geometry(lua_state, -1); if (geom && !geom->is_null()) { @@ -446,12 +435,6 @@ void flex_write_column(lua_State *lua_state, throw fmt_error("Need geometry data for geometry column '{}'.", column.name()); } - } else if (column.type() == table_column_type::area) { - // If this is an area column, the Lua function 'insert()' was - // called, because for 'add_row()' area columns are handled - // earlier and 'write_column()' is not called. - throw std::runtime_error{"Column type 'area' not allowed with " - "'insert()'. Maybe use 'real'?"}; } else { throw fmt_error("Column type {} not implemented.", static_cast(column.type())); @@ -459,58 +442,3 @@ void flex_write_column(lua_State *lua_state, lua_pop(lua_state, 1); } - -void flex_write_row(lua_State *lua_state, table_connection_t *table_connection, - osmium::item_type id_type, osmid_t id, - geom::geometry_t const &geom, int srid, - std::vector *expire) -{ - assert(table_connection); - table_connection->new_line(); - auto *copy_mgr = table_connection->copy_mgr(); - - geom::geometry_t projected_geom; - geom::geometry_t const *output_geom = &geom; - if (srid && geom.srid() != srid) { - projected_geom = geom::transform(geom, get_projection(srid)); - output_geom = &projected_geom; - } - - for (auto const &column : table_connection->table()) { - if (column.create_only()) { - continue; - } - if (column.type() == table_column_type::id_type) { - copy_mgr->add_column(type_to_char(id_type)); - } else if (column.type() == table_column_type::id_num) { - copy_mgr->add_column(id); - } else if (column.is_geometry_column()) { - assert(!geom.is_null()); - auto const type = column.type(); - bool const wrap_multi = - (type == table_column_type::multilinestring || - type == table_column_type::multipolygon); - copy_mgr->add_hex_geom(geom_to_ewkb(*output_geom, wrap_multi)); - } else if (column.type() == table_column_type::area) { - if (geom.is_null()) { - write_null(copy_mgr, column); - } else { - // if srid of the area column is the same as for the geom column - double area = 0; - if (column.srid() == 4326) { - area = geom::area(geom); - } else if (column.srid() == srid) { - area = geom::area(projected_geom); - } else { - auto const &mproj = get_projection(column.srid()); - area = geom::area(geom::transform(geom, mproj)); - } - copy_mgr->add_column(area); - } - } else { - flex_write_column(lua_state, copy_mgr, column, expire); - } - } - - copy_mgr->finish_line(); -} diff --git a/src/flex-write.hpp b/src/flex-write.hpp index fac403925..999923530 100644 --- a/src/flex-write.hpp +++ b/src/flex-write.hpp @@ -36,9 +36,4 @@ void flex_write_column(lua_State *lua_state, flex_table_column_t const &column, std::vector *expire); -void flex_write_row(lua_State *lua_state, table_connection_t *table_connection, - osmium::item_type id_type, osmid_t id, - geom::geometry_t const &geom, int srid, - std::vector *expire); - #endif // OSM2PGSQL_FLEX_WRITE_HPP diff --git a/src/geom-transform.cpp b/src/geom-transform.cpp deleted file mode 100644 index 0ee7ee57d..000000000 --- a/src/geom-transform.cpp +++ /dev/null @@ -1,247 +0,0 @@ -/** - * SPDX-License-Identifier: GPL-2.0-or-later - * - * This file is part of osm2pgsql (https://osm2pgsql.org/). - * - * Copyright (C) 2006-2024 by the osm2pgsql developer community. - * For a full list of authors see the git log. - */ - -#include "geom-from-osm.hpp" -#include "geom-functions.hpp" -#include "geom-transform.hpp" -#include "logging.hpp" -#include "lua-utils.hpp" - -#include - -#include -#include - -bool geom_transform_point_t::is_compatible_with( - table_column_type geom_type) const noexcept -{ - return geom_type == table_column_type::point || - geom_type == table_column_type::geometry; -} - -geom::geometry_t geom_transform_point_t::convert(reprojection const &proj, - osmium::Node const &node) const -{ - return geom::transform(geom::create_point(node), proj); -} - -bool geom_transform_line_t::set_param(char const *name, lua_State *lua_state) -{ - if (std::strcmp(name, "split_at") != 0) { - return false; - } - - if (lua_type(lua_state, -1) != LUA_TNUMBER) { - throw std::runtime_error{ - "The 'split_at' field in a geometry transformation " - "description must be a number."}; - } - m_split_at = lua_tonumber(lua_state, -1); - - return true; -} - -bool geom_transform_line_t::is_compatible_with( - table_column_type geom_type) const noexcept -{ - return geom_type == table_column_type::linestring || - geom_type == table_column_type::multilinestring || - geom_type == table_column_type::geometry; -} - -geom::geometry_t geom_transform_line_t::convert(reprojection const &proj, - osmium::Way const &way) const -{ - auto geom = geom::transform(geom::create_linestring(way), proj); - if (!geom.is_null() && m_split_at > 0.0) { - geom = geom::segmentize(geom, m_split_at); - } - return geom; -} - -geom::geometry_t -geom_transform_line_t::convert(reprojection const &proj, - osmium::Relation const & /*relation*/, - osmium::memory::Buffer const &buffer) const -{ - auto geom = geom::transform( - geom::line_merge(geom::create_multilinestring(buffer)), proj); - if (!geom.is_null() && m_split_at > 0.0) { - geom = geom::segmentize(geom, m_split_at); - } - return geom; -} - -bool geom_transform_area_t::set_param(char const *name, lua_State *lua_state) -{ - if (std::strcmp(name, "multi") == 0) { - throw std::runtime_error{ - "The 'multi' field in the geometry transformation has been" - " removed. See docs on how to use 'split_at' instead."}; - } - - if (std::strcmp(name, "split_at") != 0) { - return false; - } - - char const *const val = lua_tostring(lua_state, -1); - - if (!val) { - throw std::runtime_error{ - "The 'split_at' field in a geometry transformation " - "description must be a string."}; - } - - if (std::strcmp(val, "multi") == 0) { - m_multi = false; - return true; - } - - throw fmt_error("Unknown value for 'split_at' field in a geometry" - " transformation: '{}'", - val); -} - -bool geom_transform_area_t::is_compatible_with( - table_column_type geom_type) const noexcept -{ - return geom_type == table_column_type::polygon || - geom_type == table_column_type::multipolygon || - geom_type == table_column_type::geometry; -} - -geom::geometry_t geom_transform_area_t::convert(reprojection const & /*proj*/, - osmium::Way const &way) const -{ - return geom::create_polygon(way); -} - -geom::geometry_t -geom_transform_area_t::convert(reprojection const & /*proj*/, - osmium::Relation const &relation, - osmium::memory::Buffer const &buffer) const -{ - return geom::create_multipolygon(relation, buffer); -} - -std::unique_ptr create_geom_transform(char const *type) -{ - if (std::strcmp(type, "point") == 0) { - return std::make_unique(); - } - - if (std::strcmp(type, "line") == 0) { - return std::make_unique(); - } - - if (std::strcmp(type, "area") == 0) { - return std::make_unique(); - } - - throw fmt_error("Unknown geometry transformation '{}'.", type); -} - -void init_geom_transform(geom_transform_t *transform, lua_State *lua_state) -{ - static bool show_warning = true; - - assert(transform); - assert(lua_state); - - luaX_for_each(lua_state, [&]() { - char const *const field = lua_tostring(lua_state, -2); - if (field == nullptr) { - throw std::runtime_error{"All fields in geometry transformation " - "description must have string keys."}; - } - - if (std::strcmp(field, "create") != 0) { - if (!transform->set_param(field, lua_state) && show_warning) { - log_warn("Ignoring unknown field '{}' in geometry " - "transformation description.", - field); - show_warning = false; - } - } - }); -} - -std::unique_ptr -get_transform(lua_State *lua_state, flex_table_column_t const &column) -{ - assert(lua_state); - assert(lua_gettop(lua_state) == 1); - - std::unique_ptr transform{}; - - lua_getfield(lua_state, -1, column.name().c_str()); - int const ltype = lua_type(lua_state, -1); - - // Field not set, return null transform - if (ltype == LUA_TNIL) { - lua_pop(lua_state, 1); // geom field - return transform; - } - - // Field set to anything but a Lua table is not allowed - if (ltype != LUA_TTABLE) { - lua_pop(lua_state, 1); // geom field - throw fmt_error("Invalid geometry transformation for column '{}'.", - column.name()); - } - - lua_getfield(lua_state, -1, "create"); - char const *create_type = lua_tostring(lua_state, -1); - if (create_type == nullptr) { - throw fmt_error("Missing geometry transformation for column '{}'.", - column.name()); - } - - transform = create_geom_transform(create_type); - lua_pop(lua_state, 1); // 'create' field - init_geom_transform(transform.get(), lua_state); - if (!transform->is_compatible_with(column.type())) { - throw fmt_error("Geometry transformation is not compatible" - " with column type '{}'.", - column.type_name()); - } - - lua_pop(lua_state, 1); // geom field - - return transform; -} - -geom_transform_t const *get_default_transform(flex_table_column_t const &column, - osmium::item_type object_type) -{ - static geom_transform_point_t const default_transform_node_to_point{}; - static geom_transform_line_t const default_transform_way_to_line{}; - static geom_transform_area_t const default_transform_way_to_area{}; - - switch (object_type) { - case osmium::item_type::node: - if (column.type() == table_column_type::point) { - return &default_transform_node_to_point; - } - break; - case osmium::item_type::way: - if (column.type() == table_column_type::linestring) { - return &default_transform_way_to_line; - } - if (column.type() == table_column_type::polygon) { - return &default_transform_way_to_area; - } - break; - default: - break; - } - - throw fmt_error("Missing geometry transformation for column '{}'.", - column.name()); -} diff --git a/src/geom-transform.hpp b/src/geom-transform.hpp deleted file mode 100644 index 65f48dac5..000000000 --- a/src/geom-transform.hpp +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef OSM2PGSQL_GEOM_TRANSFORM_HPP -#define OSM2PGSQL_GEOM_TRANSFORM_HPP - -/** - * SPDX-License-Identifier: GPL-2.0-or-later - * - * This file is part of osm2pgsql (https://osm2pgsql.org/). - * - * Copyright (C) 2006-2024 by the osm2pgsql developer community. - * For a full list of authors see the git log. - */ - -#include "flex-table-column.hpp" -#include "geom.hpp" -#include "reprojection.hpp" - -#include -#include - -#include - -#include - -/** - * Abstract base class for geometry transformations from nodes, ways, or - * relations to simple feature type geometries. - */ -class geom_transform_t -{ -public: - virtual ~geom_transform_t() = default; - - virtual bool set_param(char const * /*name*/, lua_State * /*lua_state*/) - { - return false; - } - - virtual bool - is_compatible_with(table_column_type geom_type) const noexcept = 0; - - virtual geom::geometry_t convert(reprojection const & /*proj*/, - osmium::Node const & /*node*/) const - { - return {}; - } - - virtual geom::geometry_t convert(reprojection const & /*proj*/, - osmium::Way const & /*way*/) const - { - return {}; - } - - virtual geom::geometry_t - convert(reprojection const & /*proj*/, - osmium::Relation const & /*relation*/, - osmium::memory::Buffer const & /*buffer*/) const - { - return {}; - } - - virtual bool split() const noexcept { return false; } - -}; // class geom_transform_t - -class geom_transform_point_t : public geom_transform_t -{ -public: - bool - is_compatible_with(table_column_type geom_type) const noexcept override; - - geom::geometry_t convert(reprojection const &proj, - osmium::Node const &node) const override; - -}; // class geom_transform_point_t - -class geom_transform_line_t : public geom_transform_t -{ -public: - bool set_param(char const *name, lua_State *lua_state) override; - - bool - is_compatible_with(table_column_type geom_type) const noexcept override; - - geom::geometry_t convert(reprojection const &proj, - osmium::Way const &way) const override; - - geom::geometry_t - convert(reprojection const &proj, osmium::Relation const &relation, - osmium::memory::Buffer const &buffer) const override; - -private: - double m_split_at = 0.0; - -}; // class geom_transform_line_t - -class geom_transform_area_t : public geom_transform_t -{ -public: - bool set_param(char const *name, lua_State *lua_state) override; - - bool - is_compatible_with(table_column_type geom_type) const noexcept override; - - geom::geometry_t convert(reprojection const &proj, - osmium::Way const &way) const override; - - geom::geometry_t - convert(reprojection const &proj, osmium::Relation const &relation, - osmium::memory::Buffer const &buffer) const override; - - bool split() const noexcept override { return !m_multi; } - -private: - bool m_multi = true; - -}; // class geom_transform_area_t - -std::unique_ptr create_geom_transform(char const *type); - -void init_geom_transform(geom_transform_t *transform, lua_State *lua_state); - -std::unique_ptr -get_transform(lua_State *lua_state, flex_table_column_t const &column); - -geom_transform_t const *get_default_transform(flex_table_column_t const &column, - osmium::item_type object_type); - -#endif // OSM2PGSQL_GEOM_TRANSFORM_HPP diff --git a/src/output-flex.cpp b/src/output-flex.cpp index a80fab239..58a579ca1 100644 --- a/src/output-flex.cpp +++ b/src/output-flex.cpp @@ -20,7 +20,6 @@ #include "format.hpp" #include "geom-from-osm.hpp" #include "geom-functions.hpp" -#include "geom-transform.hpp" #include "logging.hpp" #include "lua-init.hpp" #include "lua-setup.hpp" @@ -86,7 +85,6 @@ TRAMPOLINE(app_as_geometrycollection, as_geometrycollection) TRAMPOLINE(table_name, name) TRAMPOLINE(table_schema, schema) TRAMPOLINE(table_cluster, cluster) -TRAMPOLINE(table_add_row, add_row) TRAMPOLINE(table_insert, insert) TRAMPOLINE(table_columns, columns) TRAMPOLINE(table_tostring, __tostring) @@ -583,67 +581,6 @@ bool output_flex_t::relation_cache_t::add_members(middle_query_t const &middle) return true; } -int output_flex_t::table_add_row() -{ - if (m_disable_add_row) { - return 0; - } - - if (m_calling_context != calling_context::process_node && - m_calling_context != calling_context::process_way && - m_calling_context != calling_context::process_relation) { - throw std::runtime_error{ - "The function add_row() can only be called from the " - "process_node/way/relation() functions."}; - } - - // Params are the table object and an optional Lua table with the contents - // for the fields. - auto const num_params = lua_gettop(lua_state()); - if (num_params < 1 || num_params > 2) { - throw std::runtime_error{ - "Need two parameters: The osm2pgsql.Table and the row data."}; - } - - auto &table_connection = m_table_connections.at( - idx_from_param(lua_state(), osm2pgsql_table_name)); - - auto const &table = table_connection.table(); - - // If there is a second parameter, it must be a Lua table. - if (num_params == 2) { - luaL_checktype(lua_state(), 2, LUA_TTABLE); - } - lua_remove(lua_state(), 1); - - if (m_add_row_has_never_been_called) { - m_add_row_has_never_been_called = false; - log_warn("The add_row() function is deprecated. Please read"); - log_warn("https://osm2pgsql.org/doc/tutorials/" - "switching-from-add-row-to-insert/"); - } - - if (m_calling_context == calling_context::process_node) { - if (!table.matches_type(osmium::item_type::node)) { - throw fmt_error("Trying to add node to table '{}'.", table.name()); - } - add_row(&table_connection, *m_context_node); - } else if (m_calling_context == calling_context::process_way) { - if (!table.matches_type(osmium::item_type::way)) { - throw fmt_error("Trying to add way to table '{}'.", table.name()); - } - add_row(&table_connection, m_way_cache.get()); - } else if (m_calling_context == calling_context::process_relation) { - if (!table.matches_type(osmium::item_type::relation)) { - throw fmt_error("Trying to add relation to table '{}'.", - table.name()); - } - add_row(&table_connection, m_relation_cache.get()); - } - - return 0; -} - osmium::OSMObject const & output_flex_t::check_and_get_context_object(flex_table_t const &table) { @@ -671,7 +608,7 @@ output_flex_t::check_and_get_context_object(flex_table_t const &table) int output_flex_t::table_insert() { - if (m_disable_add_row) { + if (m_disable_insert) { return 0; } @@ -783,99 +720,6 @@ int output_flex_t::table_cluster() return 1; } -geom::geometry_t output_flex_t::run_transform(reprojection const &proj, - geom_transform_t const *transform, - osmium::Node const &node) -{ - return transform->convert(proj, node); -} - -geom::geometry_t output_flex_t::run_transform(reprojection const &proj, - geom_transform_t const *transform, - osmium::Way const & /*way*/) -{ - if (m_way_cache.add_nodes(middle()) <= 1U) { - return {}; - } - - return transform->convert(proj, m_way_cache.get()); -} - -geom::geometry_t output_flex_t::run_transform(reprojection const &proj, - geom_transform_t const *transform, - osmium::Relation const &relation) -{ - if (!m_relation_cache.add_members(middle())) { - return {}; - } - - return transform->convert(proj, relation, - m_relation_cache.members_buffer()); -} - -template -void output_flex_t::add_row(table_connection_t *table_connection, - OBJECT const &object) -{ - assert(table_connection); - auto const &table = table_connection->table(); - - if (table.has_multiple_geom_columns()) { - throw fmt_error("Table '{}' has more than one geometry column." - " This is not allowed with 'add_row()'." - " Maybe use 'insert()' instead?", - table.name()); - } - - osmid_t const id = table.map_id(object.type(), object.id()); - - if (!table.has_geom_column()) { - flex_write_row(lua_state(), table_connection, object.type(), id, {}, 0, - &m_expire_tiles); - return; - } - - // From here we are handling the case where the table has a geometry - // column. In this case the second parameter to the Lua function add_row() - // must be present. - if (lua_gettop(lua_state()) == 0) { - throw std::runtime_error{ - "Need two parameters: The osm2pgsql.Table and the row data."}; - } - - auto const &proj = table_connection->proj(); - auto const type = table.geom_column().type(); - - auto const geom_transform = get_transform(lua_state(), table.geom_column()); - assert(lua_gettop(lua_state()) == 1); - - geom_transform_t const *transform = geom_transform.get(); - if (!transform) { - transform = get_default_transform(table.geom_column(), object.type()); - } - - // The geometry returned by run_transform() is in 4326 if it is a - // (multi)polygon. If it is a point or linestring, it is already in the - // target geometry. - auto geom = run_transform(proj, transform, object); - - // We need to split a multi geometry into its parts if the geometry - // column can only take non-multi geometries or if the transform - // explicitly asked us to split, which is the case when an area - // transform explicitly set `split_at = 'multi'`. - bool const split_multi = type == table_column_type::linestring || - type == table_column_type::polygon || - transform->split(); - - auto const geoms = geom::split_multi(std::move(geom), split_multi); - for (auto const &sgeom : geoms) { - table.geom_column().do_expire(sgeom, &m_expire_tiles); - flex_write_row(lua_state(), table_connection, object.type(), id, sgeom, - table.geom_column().srid(), &m_expire_tiles); - table_connection->increment_insert_counter(); - } -} - int output_flex_t::expire_output_tostring() { auto const &expire_output = get_expire_output_from_param(); @@ -1075,9 +919,9 @@ void output_flex_t::pending_relation_stage1c(osmid_t id) return; } - m_disable_add_row = true; + m_disable_insert = true; get_mutex_and_call_lua_function(m_process_relation, m_relation_cache.get()); - m_disable_add_row = false; + m_disable_insert = false; } void output_flex_t::sync() @@ -1387,7 +1231,6 @@ static void init_table_class(lua_State *lua_state) lua_pushvalue(lua_state, -1); lua_setfield(lua_state, -2, "__index"); luaX_add_table_func(lua_state, "__tostring", lua_trampoline_table_tostring); - luaX_add_table_func(lua_state, "add_row", lua_trampoline_table_add_row); luaX_add_table_func(lua_state, "insert", lua_trampoline_table_insert); luaX_add_table_func(lua_state, "name", lua_trampoline_table_name); luaX_add_table_func(lua_state, "schema", lua_trampoline_table_schema); diff --git a/src/output-flex.hpp b/src/output-flex.hpp index d8e07d274..0eca75dbd 100644 --- a/src/output-flex.hpp +++ b/src/output-flex.hpp @@ -163,7 +163,6 @@ class output_flex_t : public output_t int app_mark_way(); int table_tostring(); - int table_add_row(); int table_insert(); int table_name(); int table_schema(); @@ -206,21 +205,6 @@ class output_flex_t : public output_t osmium::OSMObject const & check_and_get_context_object(flex_table_t const &table); - geom::geometry_t run_transform(reprojection const &proj, - geom_transform_t const *transform, - osmium::Node const &node); - - geom::geometry_t run_transform(reprojection const &proj, - geom_transform_t const *transform, - osmium::Way const &way); - - geom::geometry_t run_transform(reprojection const &proj, - geom_transform_t const *transform, - osmium::Relation const &relation); - - template - void add_row(table_connection_t *table_connection, OBJECT const &object); - void delete_from_table(table_connection_t *table_connection, pg_conn_t const &db_connection, osmium::item_type type, osmid_t osm_id); @@ -316,11 +300,9 @@ class output_flex_t : public output_t /** * This is set before calling stage1c process_relation() to disable the - * add_row() command. + * insert() command. */ - bool m_disable_add_row = false; - - bool m_add_row_has_never_been_called = true; + bool m_disable_insert = false; }; #endif // OSM2PGSQL_OUTPUT_FLEX_HPP diff --git a/tests/bdd/flex/empty-insert.feature b/tests/bdd/flex/empty-insert.feature new file mode 100644 index 000000000..7e032c5b4 --- /dev/null +++ b/tests/bdd/flex/empty-insert.feature @@ -0,0 +1,29 @@ +Feature: Tests that empty insert command does something + + Scenario: + Given the OSM data + """ + n1 Tnatural=water x1 y2 + """ + And the lua style + """ + local points = osm2pgsql.define_table{ + name = 'osm2pgsql_test_points', + ids = { type = 'node', id_column = 'node_id' }, + columns = { + { column = 'geom', type = 'point' }, + } + } + + function osm2pgsql.process_node(object) + points:insert() + end + """ + + Then running osm2pgsql flex fails + + And the error output contains + """ + Need two parameters + """ + diff --git a/tests/bdd/flex/script-failure.feature b/tests/bdd/flex/script-failure.feature deleted file mode 100644 index 419b11ebe..000000000 --- a/tests/bdd/flex/script-failure.feature +++ /dev/null @@ -1,25 +0,0 @@ -Feature: Handling of errors in the Lua script - - Background: - Given the input file 'liechtenstein-2013-08-03.osm.pbf' - - Scenario: Missing geom transform in table with geometry should lead to an error - Given the lua style - """ - local test_table = osm2pgsql.define_area_table('osm2pgsql_test_lua', { - { column = 'tags', type = 'hstore' }, - { column = 'geom', type = 'geometry' } - }) - - function osm2pgsql.process_way(object) - test_table:add_row({ - tags = object.tags - }) - end - """ - Then running osm2pgsql flex fails - And the error output contains - """ - Missing geometry transformation for column 'geom' - """ -