Skip to content

Commit

Permalink
PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan24680 committed Feb 10, 2025
1 parent 47ba454 commit 61c6b98
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/engine/SpatialJoinAlgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <s2/util/units/length-units.h>

#include <cmath>
#include <set>

#include "engine/ExportQueryExecutionTrees.h"
#include "engine/SpatialJoin.h"
Expand Down Expand Up @@ -608,6 +609,16 @@ std::vector<Box> SpatialJoinAlgorithms::getQueryBox(

// ____________________________________________________________________________
Result SpatialJoinAlgorithms::BoundingBoxAlgorithm() {
// helper struct to avoid duplicate entries for areas
struct AddedPair {
size_t rowLeft;
size_t rowRight;

bool operator<(const AddedPair& other) const {
return (rowLeft < other.rowLeft) || (rowLeft == other.rowLeft && rowRight < other.rowRight);
}
};

const auto [idTableLeft, resultLeft, idTableRight, resultRight, leftJoinCol,
rightJoinCol, rightSelectedCols, numColumns, maxDist,
maxResults] = params_;
Expand Down Expand Up @@ -664,6 +675,7 @@ Result SpatialJoinAlgorithms::BoundingBoxAlgorithm() {
rtree.query(bgi::intersects(bbox), std::back_inserter(results));
});

std::set<AddedPair> pairs;
ql::ranges::for_each(results, [&](Value& res) {
size_t rowLeft = res.second.row_;
size_t rowRight = i;
Expand All @@ -673,8 +685,16 @@ Result SpatialJoinAlgorithms::BoundingBoxAlgorithm() {
auto distance = computeDist(res.second, entry.value());
AD_CORRECTNESS_CHECK(distance.getDatatype() == Datatype::Double);
if (distance.getDouble() * 1000 <= static_cast<double>(maxDist.value())) {
addResultTableEntry(&result, idTableLeft, idTableRight, rowLeft,
// make sure, that no duplicate elements are inserted in the result
// table. As duplicates can only occur, when areas are not approximated
// as midpoints, the additional runtime can be saved in that case
if (useMidpointForAreas_) {
addResultTableEntry(&result, idTableLeft, idTableRight, rowLeft,
rowRight, distance);
} else if (pairs.insert(AddedPair(rowLeft, rowRight)).second) {
addResultTableEntry(&result, idTableLeft, idTableRight, rowLeft,
rowRight, distance);
}
}
});
}
Expand Down

0 comments on commit 61c6b98

Please sign in to comment.