Allow multiple tile features to have the same join key

This commit is contained in:
Erica Fischer
2025-01-08 08:41:08 -08:00
parent cfd877267e
commit d17a911db5
+18 -16
View File
@@ -92,7 +92,7 @@ std::vector<std::vector<std::map<std::string, mvt_value>>> get_joined_rows(sqlit
std::string query = s; std::string query = s;
sqlite3_free((void *) s); sqlite3_free((void *) s);
std::map<std::string, size_t> key_to_row; std::multimap<std::string, size_t> key_to_row;
for (size_t i = 0; i < join_keys.size(); i++) { for (size_t i = 0; i < join_keys.size(); i++) {
const mvt_value &v = join_keys[i]; const mvt_value &v = join_keys[i];
@@ -129,29 +129,31 @@ std::vector<std::vector<std::map<std::string, mvt_value>>> get_joined_rows(sqlit
if (count > 0) { if (count > 0) {
// join key is 0th column of query // join key is 0th column of query
std::string key = (const char *) sqlite3_column_text(stmt, 0); std::string key = (const char *) sqlite3_column_text(stmt, 0);
auto f = key_to_row.find(key); auto f = key_to_row.equal_range(key);
if (f == key_to_row.end()) { if (f.first == f.second) {
fprintf(stderr, "Unexpected join key: %s\n", key.c_str()); fprintf(stderr, "Unexpected join key: %s\n", key.c_str());
continue; continue;
} }
if (ret[f->second].size() < join_count_limit) { for (auto ff = f.first; ff != f.second; ++ff) {
for (int i = 1; i < count; i++) { if (ret[ff->second].size() < join_count_limit) {
int type = sqlite3_column_type(stmt, i); for (int i = 1; i < count; i++) {
mvt_value v; int type = sqlite3_column_type(stmt, i);
v.type = mvt_null; mvt_value v;
v.type = mvt_null;
if (type == SQLITE_INTEGER || type == SQLITE_FLOAT) { if (type == SQLITE_INTEGER || type == SQLITE_FLOAT) {
v = mvt_value(sqlite3_column_double(stmt, i)); v = mvt_value(sqlite3_column_double(stmt, i));
} else if (type == SQLITE_TEXT || type == SQLITE_BLOB) { } else if (type == SQLITE_TEXT || type == SQLITE_BLOB) {
v.set_string_value((const char *) sqlite3_column_text(stmt, i)); v.set_string_value((const char *) sqlite3_column_text(stmt, i));
}
const char *name = sqlite3_column_name(stmt, i);
row.emplace(name, v);
} }
const char *name = sqlite3_column_name(stmt, i); ret[ff->second].push_back(row);
row.emplace(name, v);
} }
ret[f->second].push_back(std::move(row));
} }
} }
} }