Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libspatialjoin integretion #1742

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ FetchContent_Declare(
GIT_TAG 1dc0b09abab1bdc7d085a78754abd5c6e37a5d0c # 0.12.0
)


#################################
# libspatialjoin
################################
FetchContent_Declare(
spatialjoin
GIT_REPOSITORY https://github.com/ad-freiburg/spatialjoin
GIT_TAG 9cd62b173a766be8a5e1bc9b446c877da24cdc91
)

################################
# Threading
Expand Down Expand Up @@ -340,7 +347,7 @@ FetchContent_Declare(
################################
# Apply FetchContent
################################
FetchContent_MakeAvailable(googletest ctre abseil re2 stxxl fsst s2 nlohmann-json antlr range-v3)
FetchContent_MakeAvailable(googletest ctre abseil re2 stxxl fsst s2 nlohmann-json antlr range-v3 spatialjoin)
# Disable some warnings in RE2, STXXL, and GTEST
target_compile_options(s2 PRIVATE -Wno-sign-compare -Wno-unused-parameter -Wno-class-memaccess -Wno-comment -Wno-redundant-move -Wno-unknown-warning-option -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-but-set-variable -Wno-unused-function)
target_compile_options(re2 PRIVATE -Wno-unused-parameter)
Expand Down
2 changes: 1 addition & 1 deletion src/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ add_library(engine
CountConnectedSubgraphs.cpp SpatialJoinAlgorithms.cpp PathSearch.cpp ExecuteUpdate.cpp
Describe.cpp GraphStoreProtocol.cpp
QueryExecutionContext.cpp)
qlever_target_link_libraries(engine util index parser sparqlExpressions http SortPerformanceEstimator Boost::iostreams s2)
qlever_target_link_libraries(engine util index parser sparqlExpressions http SortPerformanceEstimator Boost::iostreams s2 spatialjoin-dev pb_util)
25 changes: 22 additions & 3 deletions src/engine/SpatialJoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ bool SpatialJoin::isConstructed() const { return childLeft_ && childRight_; }
// ____________________________________________________________________________
std::optional<size_t> SpatialJoin::getMaxDist() const {
auto visitor = []<typename T>(const T& config) -> std::optional<size_t> {
return config.maxDist_;
if constexpr (std::is_same_v<T, SJConfig>) {
return std::nullopt;
} else {
return config.maxDist_;
}
};
return std::visit(visitor, config_.task_);
}
Expand All @@ -84,6 +88,8 @@ std::optional<size_t> SpatialJoin::getMaxResults() const {
auto visitor = []<typename T>(const T& config) -> std::optional<size_t> {
if constexpr (std::is_same_v<T, MaxDistanceConfig>) {
return std::nullopt;
} else if constexpr (std::is_same_v<T, SJConfig>) {
return std::nullopt;
} else {
static_assert(std::is_same_v<T, NearestNeighborsConfig>);
return config.maxResults_;
Expand Down Expand Up @@ -129,6 +135,12 @@ string SpatialJoin::getCacheKeyImpl() const {
os << "maxResults: " << maxResults.value() << "\n";
}

// Uses distance variable?
auto algo = getAlgorithm();
if (algo == SpatialJoinAlgorithm::LIBSPATIALJOIN) {
os << "libspatialjoin on: " << (int)config_.joinType_ << "\n";
}

// Uses distance variable?
if (config_.distanceVariable_.has_value()) {
os << "withDistanceVariable\n";
Expand Down Expand Up @@ -163,6 +175,9 @@ string SpatialJoin::getDescriptor() const {
if constexpr (std::is_same_v<T, MaxDistanceConfig>) {
return absl::StrCat("MaxDistJoin ", left, " to ", right, " of ",
config.maxDist_, " meter(s)");
} else if constexpr (std::is_same_v<T, SJConfig>) {
return absl::StrCat("Spatial Join ", left, " to ", right,
" of type ", config.joinType_);
} else {
static_assert(std::is_same_v<T, NearestNeighborsConfig>);
return absl::StrCat("NearestNeighborsJoin ", left, " to ", right,
Expand Down Expand Up @@ -225,7 +240,8 @@ size_t SpatialJoin::getCostEstimate() {
} else {
AD_CORRECTNESS_CHECK(
config_.algo_ == SpatialJoinAlgorithm::S2_GEOMETRY ||
config_.algo_ == SpatialJoinAlgorithm::BOUNDING_BOX,
config_.algo_ == SpatialJoinAlgorithm::BOUNDING_BOX ||
config_.algo_ == SpatialJoinAlgorithm::LIBSPATIALJOIN,
"Unknown SpatialJoin Algorithm.");

// Let n be the size of the left table and m the size of the right table.
Expand Down Expand Up @@ -370,6 +386,7 @@ PreparedSpatialJoinParams SpatialJoin::prepareJoin() const {
ColumnIndex leftJoinCol = childLeft_->getVariableColumn(config_.left_);
ColumnIndex rightJoinCol = childRight_->getVariableColumn(config_.right_);


// Payload cols and join col
auto varsAndColInfo = copySortedByColumnIndex(getVarColMapPayloadVars());
std::vector<ColumnIndex> rightSelectedCols;
Expand All @@ -383,7 +400,7 @@ PreparedSpatialJoinParams SpatialJoin::prepareJoin() const {
idTableRight, std::move(resultRight),
leftJoinCol, rightJoinCol,
rightSelectedCols, numColumns,
getMaxDist(), getMaxResults()};
getMaxDist(), getMaxResults(), config_.joinType_};
}

// ____________________________________________________________________________
Expand All @@ -397,6 +414,8 @@ Result SpatialJoin::computeResult([[maybe_unused]] bool requestLaziness) {
return algorithms.BaselineAlgorithm();
} else if (config_.algo_ == SpatialJoinAlgorithm::S2_GEOMETRY) {
return algorithms.S2geometryAlgorithm();
} else if (config_.algo_ == SpatialJoinAlgorithm::LIBSPATIALJOIN) {
return algorithms.LibspatialjoinAlgorithm();
} else {
AD_CORRECTNESS_CHECK(config_.algo_ == SpatialJoinAlgorithm::BOUNDING_BOX,
"Unknown SpatialJoin Algorithm.");
Expand Down
15 changes: 13 additions & 2 deletions src/engine/SpatialJoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include "parser/PayloadVariables.h"
#include "parser/data/Variable.h"

// Selection of a SpatialJoin join type
enum class SpatialJoinJoinType { INTERSECTS, CONTAINS, COVERS, CROSSES, TOUCHES, EQUALS, OVERLAPS };

// A nearest neighbor search with optionally a maximum distance.
struct NearestNeighborsConfig {
size_t maxResults_;
Expand All @@ -25,11 +28,16 @@ struct MaxDistanceConfig {
size_t maxDist_;
};

// Full spatial join on selected join type
struct SJConfig {
SpatialJoinJoinType joinType_;
};

// Configuration to restrict the results provided by the SpatialJoin
using SpatialJoinTask = std::variant<NearestNeighborsConfig, MaxDistanceConfig>;
using SpatialJoinTask = std::variant<NearestNeighborsConfig, MaxDistanceConfig, SJConfig>;

// Selection of a SpatialJoin algorithm
enum class SpatialJoinAlgorithm { BASELINE, S2_GEOMETRY, BOUNDING_BOX };
enum class SpatialJoinAlgorithm { BASELINE, S2_GEOMETRY, BOUNDING_BOX, LIBSPATIALJOIN };
const SpatialJoinAlgorithm SPATIAL_JOIN_DEFAULT_ALGORITHM =
SpatialJoinAlgorithm::S2_GEOMETRY;

Expand All @@ -54,6 +62,8 @@ struct SpatialJoinConfiguration {
// Choice of algorithm. Both algorithms have equal results, but different
// runtime characteristics.
SpatialJoinAlgorithm algo_ = SPATIAL_JOIN_DEFAULT_ALGORITHM;

SpatialJoinJoinType joinType_ = SpatialJoinJoinType::INTERSECTS;
};

// helper struct to improve readability in prepareJoin()
Expand All @@ -68,6 +78,7 @@ struct PreparedSpatialJoinParams {
size_t numColumns_;
std::optional<size_t> maxDist_;
std::optional<size_t> maxResults_;
std::optional<SpatialJoinJoinType> joinType_;
};

// The spatial join operation without a limit on the maximum number of results
Expand Down
Loading
Loading