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 2cc0fef commit 96a903a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
37 changes: 17 additions & 20 deletions src/engine/SpatialJoinAlgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ std::string_view SpatialJoinAlgorithms::betweenQuotes(

std::optional<size_t> SpatialJoinAlgorithms::getAnyGeometry(
const IdTable* idtable, size_t row, size_t col) {
auto printWarning = [this, &spatialJoin = spatialJoin_]() mutable {
if (this->nrOfFailedParsedGeometries_ == 0) {
auto printWarning = [this, &spatialJoin = spatialJoin_]() {
if (this->numFailedParsedGeometries_ == 0) {
std::string warning =
"The input to a spatial join contained at least one element, "
"that is not a Point, Linestring, Polygon, MultiPoint, "
"MultiLinestring or MultiPolygon geometry and is thus skipped. Note "
"that QLever currently only accepts those geometries for "
"the spatial joins";
AD_LOG_WARN << warning << std::endl;
this->nrOfFailedParsedGeometries_ += 1;
this->numFailedParsedGeometries_ += 1;
if (spatialJoin.has_value()) {
AD_CORRECTNESS_CHECK(spatialJoin.value() != nullptr);
spatialJoin.value()->addWarning(warning);
Expand Down Expand Up @@ -91,11 +91,11 @@ std::optional<size_t> SpatialJoinAlgorithms::getAnyGeometry(

// ____________________________________________________________________________
double SpatialJoinAlgorithms::computeDist(
const std::optional<size_t> geometryIndex1,
const std::optional<size_t> geometryIndex2) const {
const size_t geometryIndex1,
const size_t geometryIndex2) const {
return boost::apply_visitor(ClosestPointVisitor(),
geometries_.at(geometryIndex1.value()),
geometries_.at(geometryIndex2.value()));
geometries_.at(geometryIndex1),
geometries_.at(geometryIndex2));
};

// ____________________________________________________________________________
Expand All @@ -105,7 +105,7 @@ size_t SpatialJoinAlgorithms::convertGeoPointToPoint(GeoPoint point) {
};

// ____________________________________________________________________________
Id SpatialJoinAlgorithms::computeDist(rtreeEntry& geo1, rtreeEntry& geo2) {
Id SpatialJoinAlgorithms::computeDist(RtreeEntry& geo1, RtreeEntry& geo2) {
auto convertPoint = [&](size_t geometryIndex, std::optional<Box> bbox) {
if (!bbox.has_value()) {
bbox = boost::apply_visitor(BoundingBoxVisitor(),
Expand Down Expand Up @@ -136,7 +136,7 @@ Id SpatialJoinAlgorithms::computeDist(rtreeEntry& geo1, rtreeEntry& geo2) {
} else if (geo1.geometryIndex_.has_value() &&
geo2.geometryIndex_.has_value()) {
return Id::makeFromDouble(
computeDist(geo1.geometryIndex_, geo2.geometryIndex_));
computeDist(geo1.geometryIndex_.value(), geo2.geometryIndex_.value()));
} else {
// one point and one area
if (!geo1.geometryIndex_) {
Expand All @@ -145,7 +145,7 @@ Id SpatialJoinAlgorithms::computeDist(rtreeEntry& geo1, rtreeEntry& geo2) {
geo2.geometryIndex_ = convertGeoPointToPoint(geo2.geoPoint_.value());
}
return Id::makeFromDouble(
computeDist(geo1.geometryIndex_, geo2.geometryIndex_));
computeDist(geo1.geometryIndex_.value(), geo2.geometryIndex_.value()));
}
}
}
Expand All @@ -160,9 +160,6 @@ Id SpatialJoinAlgorithms::computeDist(const IdTable* idTableLeft,
[&](const IdTable* idtable, size_t row, size_t col,
std::optional<GeoPoint> point) -> std::optional<size_t> {
if (!point) {
// 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 getAnyGeometry(idtable, row, col);
}
return convertGeoPointToPoint(point.value());
Expand All @@ -186,8 +183,8 @@ Id SpatialJoinAlgorithms::computeDist(const IdTable* idTableLeft,
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};
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_) {
Expand Down Expand Up @@ -632,9 +629,9 @@ double SpatialJoinAlgorithms::getMaxDistFromMidpointToAnyPointInsideTheBox(
}

// ____________________________________________________________________________
std::optional<rtreeEntry> SpatialJoinAlgorithms::getRtreeEntry(
std::optional<RtreeEntry> SpatialJoinAlgorithms::getRtreeEntry(
const IdTable* idTable, const size_t row, const ColumnIndex col) {
rtreeEntry entry{row, std::nullopt, std::nullopt, std::nullopt};
RtreeEntry entry{row, std::nullopt, std::nullopt, std::nullopt};
entry.geoPoint_ = getPoint(idTable, row, col);

if (!entry.geoPoint_) {
Expand All @@ -656,7 +653,7 @@ std::optional<rtreeEntry> SpatialJoinAlgorithms::getRtreeEntry(

// ____________________________________________________________________________
std::vector<Box> SpatialJoinAlgorithms::getQueryBox(
const std::optional<rtreeEntry>& entry) const {
const std::optional<RtreeEntry>& entry) const {
if (!entry.value().geoPoint_) {
auto midpoint = calculateMidpointOfBox(entry.value().boundingBox_.value());
return computeQueryBox(midpoint,
Expand Down Expand Up @@ -694,7 +691,7 @@ Result SpatialJoinAlgorithms::BoundingBoxAlgorithm() {
bgi::equal_to<Value>{}, qec_->getAllocator());
for (size_t i = 0; i < smallerResult->numRows(); i++) {
// add every box together with the additional information into the rtree
std::optional<rtreeEntry> entry =
std::optional<RtreeEntry> entry =
getRtreeEntry(smallerResult, i, smallerResJoinCol);
if (!entry) {
// nothing to do. When parsing a point or an area fails, a warning
Expand All @@ -710,7 +707,7 @@ Result SpatialJoinAlgorithms::BoundingBoxAlgorithm() {
std::vector<Value, ad_utility::AllocatorWithLimit<Value>> results{
qec_->getAllocator()};
for (size_t i = 0; i < otherResult->numRows(); i++) {
std::optional<rtreeEntry> entry =
std::optional<RtreeEntry> entry =
getRtreeEntry(otherResult, i, otherResJoinCol);
if (!entry) {
// nothing to do. When parsing a point or an area fails, a warning
Expand Down
22 changes: 11 additions & 11 deletions src/engine/SpatialJoinAlgorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct BoundingBoxVisitor : public boost::static_visitor<Box> {
}
};

// this struct is used to calculate the distance between two arbitraty
// this struct is used to calculate the distance between two arbitrary
// geometries. It calculates the two closest points (in euclidean geometry),
// transforms the two closest points, to a GeoPoint and then calculates the
// distance of the two points on the earth. As the closest points are calculated
Expand All @@ -59,22 +59,22 @@ struct ClosestPointVisitor : public boost::static_visitor<double> {
}
};

struct rtreeEntry {
struct RtreeEntry {
size_t row_;
std::optional<size_t> geometryIndex_;
std::optional<GeoPoint> geoPoint_;
std::optional<Box> boundingBox_;
};

using Value = std::pair<Box, rtreeEntry>;
using Value = std::pair<Box, RtreeEntry>;

} // namespace BoostGeometryNamespace

class SpatialJoinAlgorithms {
using Point = BoostGeometryNamespace::Point;
using Box = BoostGeometryNamespace::Box;
using AnyGeometry = BoostGeometryNamespace::AnyGeometry;
using rtreeEntry = BoostGeometryNamespace::rtreeEntry;
using RtreeEntry = BoostGeometryNamespace::RtreeEntry;

public:
// initialize the Algorithm with the needed parameters
Expand Down Expand Up @@ -123,8 +123,8 @@ class SpatialJoinAlgorithms {
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);
// geometry has already been parsed and is available as an RtreeEntry
Id computeDist(RtreeEntry& geo1, RtreeEntry& geo2);

// this function calculates the maximum distance from the midpoint of the box
// to any other point, which is contained in the box. If the midpoint has
Expand Down Expand Up @@ -174,13 +174,13 @@ class SpatialJoinAlgorithms {
// Only for the poles, the conversion will be way to large (for the longitude
// difference). Note, that this function is expensive and should only be
// called when needed
double computeDist(const std::optional<size_t> geometryIndex1,
const std::optional<size_t> geometryIndex2) const;
double computeDist(const size_t geometryIndex1,
const size_t geometryIndex2) const;

// this helper function takes an idtable, a row and a column. It then tries
// to parse a geometry or a geoPoint of that cell in the idtable. If it
// succeeds, it returns an rtree entry of that geometry/geopoint
std::optional<rtreeEntry> getRtreeEntry(const IdTable* idTable,
std::optional<RtreeEntry> getRtreeEntry(const IdTable* idTable,
const size_t row,
const ColumnIndex col);

Expand All @@ -192,7 +192,7 @@ class SpatialJoinAlgorithms {
// query must be contained in. It returns a vector, because if the box crosses
// the poles or the -180/180 longitude line, then it is disjoint in the
// cartesian coordinates. The boxes themselves are disjoint to each other.
std::vector<Box> getQueryBox(const std::optional<rtreeEntry>& entry) const;
std::vector<Box> getQueryBox(const std::optional<RtreeEntry>& entry) const;

QueryExecutionContext* qec_;
PreparedSpatialJoinParams params_;
Expand Down Expand Up @@ -223,7 +223,7 @@ class SpatialJoinAlgorithms {
// to print the warning once, but it could also be used to print how many
// geometries failed. It is mutable to let parsing function which are const
// still modify the the nr of failed parsings.
mutable size_t nrOfFailedParsedGeometries_ = 0;
size_t numFailedParsedGeometries_ = 0;

// this vector stores the geometries, which have already been parsed
std::vector<AnyGeometry> geometries_;
Expand Down

0 comments on commit 96a903a

Please sign in to comment.