From 608faefaf5246efaf5c3897955ad57feadbba178 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 13 Apr 2025 17:59:54 +0200 Subject: [PATCH] always allow table insertion for id-less tables --- src/flex-table.cpp | 5 ++- tests/bdd/flex/table-ids.feature | 57 +++++++++++++++++++++++++++++ tests/bdd/steps/geometry_factory.py | 2 +- 3 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 tests/bdd/flex/table-ids.feature diff --git a/src/flex-table.cpp b/src/flex-table.cpp index e5686ae1b..7d40bb59d 100644 --- a/src/flex-table.cpp +++ b/src/flex-table.cpp @@ -76,8 +76,9 @@ bool flex_table_t::has_id_column() const noexcept bool flex_table_t::matches_type(osmium::item_type type) const noexcept { - // This table takes any type -> okay - if (m_id_type == flex_table_index_type::any_object) { + // This table takes any type or has no ids -> okay + if (m_id_type == flex_table_index_type::any_object || + m_id_type == flex_table_index_type::no_index) { return true; } diff --git a/tests/bdd/flex/table-ids.feature b/tests/bdd/flex/table-ids.feature new file mode 100644 index 000000000..0b9841704 --- /dev/null +++ b/tests/bdd/flex/table-ids.feature @@ -0,0 +1,57 @@ +Feature: Test for correct id column generation + + Background: + Given the 0.1 grid + | 1 | | 2 | + | 3 | | 4 | + + Scenario: Data can be inserted into tables without an iD column + Given the lua style + """ + local simple = osm2pgsql.define_table{ + name = 'simple', + columns = {{ column = 'id', type = 'bigint'}} + } + + function osm2pgsql.process_node(object) + simple:insert{ id = object.id } + end + + function osm2pgsql.process_way(object) + simple:insert{ id = object.id } + end + + function osm2pgsql.process_relation(object) + simple:insert{ id = object.id } + end + """ + And the OSM data + """ + n1 Tp=1 + n2 Tp=2 + w10 Tp=10 Nn1,n2,n4 + r100 Tp=100 Mn1@,n2@ + """ + When running osm2pgsql flex with parameters + | --slim | + Then table simple contains + | id | + | 1 | + | 2 | + | 10 | + | 100 | + Given the OSM data + """ + n1 v2 dD + w11 Tp=11 Nn1,n3 + """ + When running osm2pgsql flex with parameters + | --slim | -a | + Then table simple contains + | id | + | 1 | + | 2 | + | 10 | + | 11 | + | 100 | + diff --git a/tests/bdd/steps/geometry_factory.py b/tests/bdd/steps/geometry_factory.py index 9ba7f9f5f..41e3f18ee 100644 --- a/tests/bdd/steps/geometry_factory.py +++ b/tests/bdd/steps/geometry_factory.py @@ -104,7 +104,7 @@ def complete_node_list(self, nodes): assert ' y' not in line coords = self.grid_node(nid) - assert coords is not None, f"Coordinates missing for node {node}" + assert coords is not None, f"Coordinates missing for node {nid}" nodes[i] = f"{line} x{coords[0]:.{self.grid_precision}f} y{coords[1]:.{self.grid_precision}f}" todos.discard(nid)