Skip to content

Commit

Permalink
backup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan24680 committed Feb 10, 2025
1 parent 96a903a commit 47ba454
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 78 deletions.
79 changes: 10 additions & 69 deletions src/engine/SpatialJoinAlgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,72 +150,6 @@ Id SpatialJoinAlgorithms::computeDist(RtreeEntry& geo1, RtreeEntry& geo2) {
}
}

// ____________________________________________________________________________
Id SpatialJoinAlgorithms::computeDist(const IdTable* idTableLeft,
const IdTable* idTableRight,
size_t rowLeft, size_t rowRight,
ColumnIndex leftPointCol,
ColumnIndex rightPointCol) {
auto getAreaOrPointGeometry =
[&](const IdTable* idtable, size_t row, size_t col,
std::optional<GeoPoint> point) -> std::optional<size_t> {
if (!point) {
return getAnyGeometry(idtable, row, col);
}
return convertGeoPointToPoint(point.value());
};

// for now we need to get the data from the disk, but in the future, this
// information will be stored in an ID, just like GeoPoint
auto getAreaPoint = [&](const IdTable* idtable, size_t row,
size_t col) -> std::optional<GeoPoint> {
std::optional<size_t> geometryIndex = getAnyGeometry(idtable, row, col);
if (!geometryIndex) {
// nothing to do. When parsing a point or an area fails, a warning message
// gets printed at another place and the point/area just gets skipped
return std::nullopt;
}

Box areaBox = boost::apply_visitor(BoundingBoxVisitor(),
geometries_.at(geometryIndex.value()));

Point p = calculateMidpointOfBox(areaBox);
return GeoPoint(p.get<1>(), p.get<0>());
};

RtreeEntry entryLeft{rowLeft, std::nullopt, std::nullopt, std::nullopt};
RtreeEntry entryRight{rowRight, std::nullopt, std::nullopt, std::nullopt};
entryLeft.geoPoint_ = getPoint(idTableLeft, rowLeft, leftPointCol);
entryRight.geoPoint_ = getPoint(idTableRight, rowRight, rightPointCol);
if (entryLeft.geoPoint_ && entryRight.geoPoint_) {
return computeDist(entryLeft, entryRight);
} else if (useMidpointForAreas_) {
if (!entryLeft.geoPoint_) {
entryLeft.geoPoint_ = getAreaPoint(idTableLeft, rowLeft, leftPointCol);
}
if (!entryRight.geoPoint_) {
entryRight.geoPoint_ =
getAreaPoint(idTableRight, rowRight, rightPointCol);
}
if (entryLeft.geoPoint_ && entryRight.geoPoint_) {
return computeDist(entryLeft, entryRight);
} else {
return Id::makeUndefined();
}
} else {
entryLeft.geometryIndex_ = getAreaOrPointGeometry(
idTableLeft, rowLeft, leftPointCol, entryLeft.geoPoint_);
entryRight.geometryIndex_ = getAreaOrPointGeometry(
idTableRight, rowRight, rightPointCol, entryRight.geoPoint_);
if (entryLeft.geometryIndex_.has_value() &&
entryRight.geometryIndex_.has_value()) {
return computeDist(entryLeft, entryRight);
} else {
return Id::makeUndefined();
}
}
}

// ____________________________________________________________________________
void SpatialJoinAlgorithms::addResultTableEntry(IdTable* result,
const IdTable* idTableLeft,
Expand Down Expand Up @@ -281,11 +215,18 @@ Result SpatialJoinAlgorithms::BaselineAlgorithm() {
std::vector<std::pair<size_t, double>>,
decltype(compare)>
intermediate(compare);


auto entryLeft = getRtreeEntry(idTableLeft, rowLeft, leftJoinCol);

// Inner loop of cartesian product
for (size_t rowRight = 0; rowRight < idTableRight->size(); rowRight++) {
Id dist = computeDist(idTableLeft, idTableRight, rowLeft, rowRight,
leftJoinCol, rightJoinCol);
auto entryRight = getRtreeEntry(idTableRight, rowRight, rightJoinCol);

if (!entryLeft || !entryRight) {
continue;
}

Id dist = computeDist(entryLeft.value(), entryRight.value());

// Ensure `maxDist_` constraint
if (dist.getDatatype() != Datatype::Double ||
Expand Down
15 changes: 8 additions & 7 deletions src/engine/SpatialJoinAlgorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ class SpatialJoinAlgorithms {
useMidpointForAreas_ = useMidpointForAreas;
}

// Helper function, which computes the distance of two geometries, where each
// geometry comes from a different result table
Id computeDist(const IdTable* resLeft, const IdTable* resRight,
size_t rowLeft, size_t rowRight, ColumnIndex leftPointCol,
ColumnIndex rightPointCol);

// Helper function, which computes the distance of two geometries, where each
// geometry has already been parsed and is available as an RtreeEntry
Id computeDist(RtreeEntry& geo1, RtreeEntry& geo2);
Expand All @@ -138,6 +132,13 @@ class SpatialJoinAlgorithms {
std::optional<size_t> getAnyGeometry(const IdTable* idtable, size_t row,
size_t col);

// wrapper to access non const private function for testing
std::optional<RtreeEntry> onlyForTestingGetRtreeEntry(const IdTable* idTable,
const size_t row,
const ColumnIndex col) {
return getRtreeEntry(idTable, row, col);
}

private:
// Helper function which returns a GeoPoint if the element of the given table
// represents a GeoPoint
Expand Down Expand Up @@ -183,7 +184,7 @@ class SpatialJoinAlgorithms {
std::optional<RtreeEntry> getRtreeEntry(const IdTable* idTable,
const size_t row,
const ColumnIndex col);

// this helper function converts a GeoPoint into a boost geometry Point
size_t convertGeoPointToPoint(GeoPoint point);

Expand Down
5 changes: 3 additions & 2 deletions test/engine/SpatialJoinAlgorithmsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1601,9 +1601,10 @@ TEST(SpatialJoin, trueAreaDistance) {
SpatialJoinAlgorithms algorithms{
qec, params, spatialJoin->onlyForTestingGetConfig(), std::nullopt};
algorithms.setUseMidpointForAreas_(useMidpointForAreas);
auto entryLeft = algorithms.onlyForTestingGetRtreeEntry(params.idTableLeft_, 0, params.leftJoinCol_);
auto entryRight = algorithms.onlyForTestingGetRtreeEntry(params.idTableRight_, 0, params.rightJoinCol_);
auto distID =
algorithms.computeDist(params.idTableLeft_, params.idTableRight_, 0, 0,
params.leftJoinCol_, params.rightJoinCol_);
algorithms.computeDist(entryLeft.value(), entryRight.value());
return distID.getDouble();
};
auto qec = buildMixedAreaPointQEC(true);
Expand Down

0 comments on commit 47ba454

Please sign in to comment.