Skip to content

Commit

Permalink
Implement comparison of two geo points (#1801)
Browse files Browse the repository at this point in the history
This was not implemented so far and crashed the server when two geo points were compared.
Also add `static_assert`s that will make such crashes less likely when datatypes are added in the future. Fixes #1791
  • Loading branch information
hannahbast authored Feb 19, 2025
1 parent 1213437 commit 4fa1fea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/global/ValueIdComparators.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,17 +505,23 @@ ComparisonResult compareIdsImpl(ValueId a, ValueId b, auto comparator) {
return fromBool(std::invoke(comparator, a, b));
}

auto visitor = [comparator]<typename A, typename B>(
// If both are geo points, compare the raw IDs.
if (a.getDatatype() == Datatype::GeoPoint &&
b.getDatatype() == Datatype::GeoPoint) {
return fromBool(std::invoke(comparator, a.getBits(), b.getBits()));
}

auto visitor = [comparator, &a, &b]<typename A, typename B>(
const A& aValue, const B& bValue) -> ComparisonResult {
if constexpr (std::is_same_v<A, LocalVocabIndex> &&
std::is_same_v<B, LocalVocabIndex>) {
// We have handled this case outside the visitor.
AD_FAIL();
} else if constexpr (requires() {
std::invoke(comparator, aValue, bValue);
}) {
if constexpr (requires() { std::invoke(comparator, aValue, bValue); }) {
return fromBool(std::invoke(comparator, aValue, bValue));
} else {
static_assert((!std::is_same_v<A, B>) ||
ad_utility::SameAsAny<A, LocalVocabIndex, GeoPoint,
Id::UndefinedType>);
AD_LOG_ERROR << "Comparison not implemented for types "
<< toString(a.getDatatype()) << " and "
<< toString(b.getDatatype()) << std::endl;
AD_FAIL();
}
};
Expand Down
2 changes: 2 additions & 0 deletions src/index/IndexImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ IndexBuilderDataAsStxxlVector IndexImpl::passFileForVocabulary(
AD_LOG_INFO << "Number of triples created (including QLever-internal ones): "
<< (*idTriples.wlock())->size() << " [may contain duplicates]"
<< std::endl;
AD_LOG_INFO << "Number of partial vocabularies created: " << numFiles
<< std::endl;

size_t sizeInternalVocabulary = 0;
std::vector<std::string> prefixes;
Expand Down

0 comments on commit 4fa1fea

Please sign in to comment.