Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tags = NULL in middle tables if object doesn't have any tags #2099

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/middle-pgsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ template <typename T>
void pgsql_parse_json_tags(char const *string, osmium::memory::Buffer *buffer,
T *obuilder)
{
if (*string == '\0') { // NULL
return;
}

auto const tags = nlohmann::json::parse(string);
if (!tags.is_object()) {
throw std::runtime_error{"Database format for tags invalid."};
Expand Down Expand Up @@ -439,6 +443,10 @@ template <typename T>
void pgsql_parse_json_members(char const *string,
osmium::memory::Buffer *buffer, T *obuilder)
{
if (*string == '\0') { // NULL
return;
}

osmium::builder::RelationMemberListBuilder builder{*buffer, obuilder};
member_list_json_builder parser{&builder};
nlohmann::json::sax_parse(string, &parser);
Expand Down Expand Up @@ -613,6 +621,10 @@ void middle_pgsql_t::copy_attributes(osmium::OSMObject const &obj)
void middle_pgsql_t::copy_tags(osmium::OSMObject const &obj)
{
if (m_store_options.db_format == 2) {
if (obj.tags().empty()) {
m_db_copy.add_null_column();
return;
}
json_writer_t writer;
tags_to_json(obj.tags(), &writer);
m_db_copy.add_column(writer.json());
Expand Down Expand Up @@ -1464,7 +1476,7 @@ static table_sql sql_for_nodes_format2(middle_pgsql_options const &options)
" lat int4 NOT NULL,"
" lon int4 NOT NULL,"
"{attribute_columns_definition}"
" tags jsonb NOT NULL"
" tags jsonb"
") {data_tablespace}";

sql.prepare_queries = {
Expand Down Expand Up @@ -1530,7 +1542,7 @@ static table_sql sql_for_ways_format2(middle_pgsql_options const &options)
" id int8 PRIMARY KEY {using_tablespace},"
"{attribute_columns_definition}"
" nodes int8[] NOT NULL,"
" tags jsonb NOT NULL"
" tags jsonb"
") {data_tablespace}";

sql.prepare_queries = {"PREPARE get_way(int8) AS"
Expand Down Expand Up @@ -1601,7 +1613,7 @@ static table_sql sql_for_relations_format2()
" id int8 PRIMARY KEY {using_tablespace},"
"{attribute_columns_definition}"
" members jsonb NOT NULL,"
" tags jsonb NOT NULL"
" tags jsonb"
") {data_tablespace}";

sql.prepare_queries = {"PREPARE get_rel(int8) AS"
Expand Down