Skip to content

Commit b4e3849

Browse files
author
Hannah Bast
committed
Fetch only non-point WKT geometries
So far, the initial cache-warming query fetched *all* `geo:asWKT` geometries from the SPARQL endpoint. However, `POINT` geometries do not need to be cached since (for QLever) the coordinates are folded into the ID. In particular, this makes a huge difference for OSM Planet, where the vast majority of geometries are `POINT` geometries (at the time of this writing, over 20 billion out of 22 billion).
1 parent 9beca55 commit b4e3849

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/qlever-petrimaps/GeomCache.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,31 @@ const static std::string INDEX_HASH_PREFIX = "_1_";
3434
//
3535
// NOTE: It is important that the order of the geometries is deterministic.
3636
// We use `INTERNAL SORT BY` instead of `ORDER BY` because the former is
37-
// more efficient (and the actual order does not matter).
37+
// more efficient (and the actual order does not matter). We don't need the
38+
// POINT geometries because we can reconstruct them from the QLever ID.
3839
const static std::string QUERY_ASWKT =
3940
"PREFIX geo: <http://www.opengis.net/ont/geosparql#> "
4041
"SELECT ?geometry WHERE {"
4142
" ?subject geo:asWKT ?geometry "
43+
" FILTER (!ql:isGeoPoint(?geometry)) "
4244
"} INTERNAL SORT BY ?geometry";
4345

4446
const static std::string QUERY_WDTP625 =
4547
"PREFIX wdt: <http://www.wikidata.org/prop/direct/> "
4648
"SELECT ?geometry WHERE {"
47-
" ?subject wdt:P625 ?geometry"
49+
" ?subject wdt:P625 ?geometry"
50+
" FILTER (!ql:isGeoPoint(?geometry)) "
4851
"} INTERNAL SORT BY ?geometry";
4952

5053
const static std::string QUERY_WDTP625_SERVICE =
5154
"PREFIX wdt: <http://www.wikidata.org/prop/direct/> "
5255
"SELECT ?geometry WHERE {"
53-
" SERVICE <https://qlever.cs.uni-freiburg.de/api/wikidata> {"
54-
" SELECT ?geometry WHERE {"
55-
" ?subject wdt:P625 ?geometry"
56-
" } INTERNAL SORT BY ?geometry"
57-
" }"
56+
" SERVICE <https://qlever.cs.uni-freiburg.de/api/wikidata> {"
57+
" SELECT ?geometry WHERE {"
58+
" ?subject wdt:P625 ?geometry"
59+
" FILTER (!ql:isGeoPoint(?geometry)) "
60+
" } INTERNAL SORT BY ?geometry"
61+
" }"
5862
"}";
5963

6064
// _____________________________________________________________________________
@@ -87,6 +91,7 @@ std::string GeomCache::getCountQuery(const std::string &backendUrl) const {
8791
LOG(ERROR) << "Could not find SELECT in query: " << query;
8892
return "SELECT ?count WHERE { VALUES ?count { 0 } }";
8993
}
94+
util::replaceAll(query, "INTERNAL SORT BY ?geometry", "");
9095
query.insert(pos, "SELECT (COUNT(?geometry) AS ?count) WHERE { ");
9196
query.append(" }");
9297
return query;

0 commit comments

Comments
 (0)