-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow selecting all variables as payload in spatial search SERVICE (#…
…1656) In the spatial search service (triggered via `SERVICE spatialSearch:`) all variables from the right hand side of the join (except for the join column) that shall be part of the result have to be explicitly selected via the `<payload>` parameter. This PR adds a special value `<all>` for this parameter, which automatically selects all the variables from the right side as payload.
- Loading branch information
Showing
12 changed files
with
413 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2024, University of Freiburg, | ||
// Chair of Algorithms and Data Structures. | ||
// Author: Christoph Ullinger <[email protected]> | ||
|
||
#include "parser/PayloadVariables.h" | ||
|
||
// ____________________________________________________________________________ | ||
PayloadVariables::PayloadVariables(std::vector<Variable> variables) | ||
: variables_{std::move(variables)} {}; | ||
|
||
// ____________________________________________________________________________ | ||
PayloadVariables PayloadVariables::all() { | ||
PayloadVariables pv{}; | ||
pv.setToAll(); | ||
return pv; | ||
}; | ||
|
||
// ____________________________________________________________________________ | ||
void PayloadVariables::addVariable(const Variable& variable) { | ||
// Helper visitor to check if the payload variables has not been set to all | ||
// and a variable can be added. If yes, add it. | ||
auto addVarVisitor = [&]<typename T>(T& value) { | ||
if constexpr (std::is_same_v<T, std::vector<Variable>>) { | ||
value.push_back(variable); | ||
} | ||
}; | ||
|
||
std::visit(addVarVisitor, variables_); | ||
}; | ||
|
||
// ____________________________________________________________________________ | ||
void PayloadVariables::setToAll() { | ||
variables_ = detail::PayloadAllVariables{}; | ||
}; | ||
|
||
// ____________________________________________________________________________ | ||
bool PayloadVariables::empty() const { | ||
// Helper visitor to check if the payload variables are empty | ||
auto emptyVisitor = []<typename T>(const T& value) -> bool { | ||
if constexpr (std::is_same_v<T, detail::PayloadAllVariables>) { | ||
return false; | ||
} else { | ||
static_assert(std::is_same_v<T, std::vector<Variable>>); | ||
return value.empty(); | ||
} | ||
}; | ||
|
||
return std::visit(emptyVisitor, variables_); | ||
}; | ||
|
||
// ____________________________________________________________________________ | ||
bool PayloadVariables::isAll() const { | ||
return std::holds_alternative<detail::PayloadAllVariables>(variables_); | ||
}; | ||
|
||
// ____________________________________________________________________________ | ||
const std::vector<Variable>& PayloadVariables::getVariables() const { | ||
// Helper visitor to check if the payload variables has been set to all: then | ||
// throw, otherwise return the vector | ||
auto getVarVisitor = | ||
[]<typename T>(const T& value) -> const std::vector<Variable>& { | ||
if constexpr (std::is_same_v<T, std::vector<Variable>>) { | ||
return value; | ||
} else { | ||
AD_THROW( | ||
"getVariables may only be called on a non-all PayloadVariables " | ||
"object."); | ||
} | ||
}; | ||
|
||
return std::visit(getVarVisitor, variables_); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2024, University of Freiburg, | ||
// Chair of Algorithms and Data Structures. | ||
// Author: Christoph Ullinger <[email protected]> | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include "parser/data/Variable.h" | ||
|
||
namespace detail { | ||
// Represents the selection of all variables as payload | ||
struct PayloadAllVariables : std::monostate { | ||
bool operator==([[maybe_unused]] const std::vector<Variable>& other) const { | ||
return false; | ||
}; | ||
}; | ||
} // namespace detail | ||
|
||
// This class represents a list of variables to be included in the result of | ||
// an operation. This is currently used in the spatial search. | ||
class PayloadVariables { | ||
public: | ||
// Construct an empty payload variables object | ||
PayloadVariables() = default; | ||
|
||
// Construct a payload variables object from a vector of variables | ||
PayloadVariables(std::vector<Variable> variables); | ||
|
||
// Construct a payload variables object that is set to all | ||
static PayloadVariables all(); | ||
|
||
// Add a variable to the payload variables or do nothing if all variables are | ||
// already selected | ||
void addVariable(const Variable& variable); | ||
|
||
// Select all variables. | ||
void setToAll(); | ||
|
||
// Returns whether the payload variables object is empty. | ||
bool empty() const; | ||
|
||
// Returns whether all variables have been selected. | ||
bool isAll() const; | ||
|
||
// Returns a vector of variables if all has not been set. Otherwise throws. | ||
const std::vector<Variable>& getVariables() const; | ||
|
||
// For testing: equality operator | ||
bool operator==(const PayloadVariables& other) const { | ||
return variables_ == other.variables_; | ||
}; | ||
|
||
private: | ||
std::variant<detail::PayloadAllVariables, std::vector<Variable>> variables_ = | ||
std::vector<Variable>{}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.