Skip to content

Commit

Permalink
Revert "Format fix"
Browse files Browse the repository at this point in the history
Accidentiall fixed too many formats

This reverts commit 0d6977f.
  • Loading branch information
JoBuRo committed Apr 15, 2024
1 parent 6cf3af1 commit d2ea890
Show file tree
Hide file tree
Showing 16 changed files with 488 additions and 754 deletions.
34 changes: 16 additions & 18 deletions src/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
add_subdirectory(sparqlExpressions) add_library(
SortPerformanceEstimator SortPerformanceEstimator.cpp)
qlever_target_link_libraries(SortPerformanceEstimator) add_library(
engine Engine.cpp QueryExecutionTree.cpp Operation.cpp ResultTable
.cpp LocalVocab.cpp IndexScan.cpp Join.cpp Sort.cpp Distinct
.cpp OrderBy.cpp Filter.cpp Server.cpp QueryPlanner
.cpp QueryPlanningCostFactors.cpp OptionalJoin
.cpp CountAvailablePredicates.cpp GroupBy.cpp HasPredicateScan
.cpp Union.cpp MultiColumnJoin.cpp TransitivePathBase
.cpp TransitivePathHashMap.cpp TransitivePathBinSearch.cpp Service
.cpp Values.cpp Bind.cpp Minus.cpp RuntimeInformation
.cpp CheckUsePatternTrick.cpp VariableToColumnMap
.cpp ExportQueryExecutionTrees.cpp CartesianProductJoin
.cpp TextIndexScanForWord.cpp TextIndexScanForEntity.cpp idTable /
CompressedExternalIdTable.h)
qlever_target_link_libraries(
engine util index parser sparqlExpressions http
SortPerformanceEstimator Boost::iostreams)
add_subdirectory(sparqlExpressions)
add_library(SortPerformanceEstimator SortPerformanceEstimator.cpp)
qlever_target_link_libraries(SortPerformanceEstimator)
add_library(engine
Engine.cpp QueryExecutionTree.cpp Operation.cpp ResultTable.cpp LocalVocab.cpp
IndexScan.cpp Join.cpp Sort.cpp
Distinct.cpp OrderBy.cpp Filter.cpp
Server.cpp QueryPlanner.cpp QueryPlanningCostFactors.cpp
OptionalJoin.cpp CountAvailablePredicates.cpp GroupBy.cpp HasPredicateScan.cpp
Union.cpp MultiColumnJoin.cpp TransitivePathBase.cpp
TransitivePathHashMap.cpp TransitivePathBinSearch.cpp Service.cpp
Values.cpp Bind.cpp Minus.cpp RuntimeInformation.cpp CheckUsePatternTrick.cpp
VariableToColumnMap.cpp ExportQueryExecutionTrees.cpp
CartesianProductJoin.cpp TextIndexScanForWord.cpp TextIndexScanForEntity.cpp
idTable/CompressedExternalIdTable.h)
qlever_target_link_libraries(engine util index parser sparqlExpressions http SortPerformanceEstimator Boost::iostreams)
5 changes: 3 additions & 2 deletions src/engine/GroupByHashMapOptimization.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
static constexpr auto valueAdder = []() {
auto numericValueAdder =
[]<typename T>(T value, double& sum, [[maybe_unused]] const bool& error)
requires std::is_arithmetic_v<T>
{ sum += static_cast<double>(value); };
requires std::is_arithmetic_v<T> {
sum += static_cast<double>(value);
};
auto nonNumericValueAdder = [](sparqlExpression::detail::NotNumeric,
[[maybe_unused]] const double& sum,
bool& error) { error = true; };
Expand Down
6 changes: 3 additions & 3 deletions src/engine/idTable/IdTableRow.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ class RowReferenceImpl {
}

// Assignment from a `const` RowReference to a `mutable` RowReference
This& operator=(
const RowReferenceWithRestrictedAccess<
Table, ad_utility::IsConst::True>& other) && requires(!isConst) {
This& operator=(const RowReferenceWithRestrictedAccess<
Table, ad_utility::IsConst::True>& other) &&
requires(!isConst) {
return assignmentImpl(*this, other);
}

Expand Down
2 changes: 2 additions & 0 deletions src/engine/raw_thoughts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,5 @@ I don't see a problem why it couldn't also be a parameter per context variable.
HARDER THAN BROCCOLI:
cross product with contexts
cross product (not full) with co-occurring n-tuples of entities (?x ?y ?z - see graphs above).


28 changes: 19 additions & 9 deletions src/engine/sparqlExpressions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
add_library(
sparqlExpressions SparqlExpressionValueGetters.cpp NaryExpression
.cpp SetOfIntervals.cpp SparqlExpressionPimpl.cpp SampleExpression
.cpp RelationalExpressions.cpp AggregateExpression.cpp RegexExpression
.cpp LangExpression.cpp NumericUnaryExpressions
.cpp NumericBinaryExpressions.cpp DateExpressions.cpp StringExpressions
.cpp IsSomethingExpressions.cpp ConditionalExpressions
.cpp SparqlExpressionTypes.cpp SparqlExpression.cpp)
add_library(sparqlExpressions
SparqlExpressionValueGetters.cpp
NaryExpression.cpp
SetOfIntervals.cpp
SparqlExpressionPimpl.cpp
SampleExpression.cpp
RelationalExpressions.cpp
AggregateExpression.cpp
RegexExpression.cpp
LangExpression.cpp
NumericUnaryExpressions.cpp
NumericBinaryExpressions.cpp
DateExpressions.cpp
StringExpressions.cpp
IsSomethingExpressions.cpp
ConditionalExpressions.cpp
SparqlExpressionTypes.cpp
SparqlExpression.cpp)

qlever_target_link_libraries(sparqlExpressions util index Boost::url)
qlever_target_link_libraries(sparqlExpressions util index Boost::url)
68 changes: 34 additions & 34 deletions src/engine/sparqlExpressions/ConditionalExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,35 @@ class CoalesceExpression : public VariadicExpression {

auto visitConstantExpressionResult =
[&nextUnboundIndices, &unboundIndices, &isUnbound, &result,
ctx]<SingleExpressionResult T>(T&& childResult)
ctx ]<SingleExpressionResult T>(T && childResult)
requires isConstantResult<T> {
IdOrString constantResult{AD_FWD(childResult)};
if (isUnbound(constantResult)) {
nextUnboundIndices = std::move(unboundIndices);
return;
}
ad_utility::chunkedForLoop<CHUNK_SIZE>(
0, unboundIndices.size(),
[&unboundIndices, &result, &constantResult](size_t idx) {
// GCC 12 & 13 report this as potential uninitialized
// use of a variable when compiling with -O3, which seems to
// be a false positive, so we suppress the warning here. See
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109561 for
// more information.
DISABLE_UNINITIALIZED_WARNINGS
result[unboundIndices[idx]] = constantResult;
},
[ctx]() { ctx->cancellationHandle_->throwIfCancelled(); });
};
IdOrString constantResult{AD_FWD(childResult)};
if (isUnbound(constantResult)) {
nextUnboundIndices = std::move(unboundIndices);
return;
}
ad_utility::chunkedForLoop<CHUNK_SIZE>(
0, unboundIndices.size(),
[&unboundIndices, &result, &constantResult](size_t idx) {
// GCC 12 & 13 report this as potential uninitialized
// use of a variable when compiling with -O3, which seems to
// be a false positive, so we suppress the warning here. See
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109561 for
// more information.
DISABLE_UNINITIALIZED_WARNINGS
result[unboundIndices[idx]] = constantResult;
},
[ctx]() { ctx->cancellationHandle_->throwIfCancelled(); });
};
ENABLE_UNINITIALIZED_WARNINGS

// For a single child result, write the result at the indices where the
// result so far is unbound, and the child result is bound. While doing so,
// set up the `nextUnboundIndices` vector for the next step.
auto visitVectorExpressionResult =
[&result, &unboundIndices, &nextUnboundIndices, &ctx,
&isUnbound]<SingleExpressionResult T>(T&& childResult)
requires std::is_rvalue_reference_v<T&&>
{
[&result, &unboundIndices, &nextUnboundIndices, &ctx, &
isUnbound ]<SingleExpressionResult T>(T && childResult)
requires std::is_rvalue_reference_v<T&&> {
static_assert(!isConstantResult<T>);
auto gen = detail::makeGenerator(AD_FWD(childResult), ctx->size(), ctx);
// Iterator to the next index where the result so far is unbound.
Expand Down Expand Up @@ -127,17 +126,18 @@ class CoalesceExpression : public VariadicExpression {
[ctx]() { ctx->cancellationHandle_->throwIfCancelled(); });
};
auto visitExpressionResult =
[&visitConstantExpressionResult,
&visitVectorExpressionResult]<SingleExpressionResult T>(
T&& childResult) requires std::is_rvalue_reference_v<T&&> {
// If the previous expression result is a constant, we can skip the
// loop.
if constexpr (isConstantResult<T>) {
visitConstantExpressionResult(AD_FWD(childResult));
} else {
visitVectorExpressionResult(AD_FWD(childResult));
}
};
[
&visitConstantExpressionResult, &visitVectorExpressionResult
]<SingleExpressionResult T>(T && childResult)
requires std::is_rvalue_reference_v<T&&> {
// If the previous expression result is a constant, we can skip the
// loop.
if constexpr (isConstantResult<T>) {
visitConstantExpressionResult(AD_FWD(childResult));
} else {
visitVectorExpressionResult(AD_FWD(childResult));
}
};

// Evaluate the children one by one, stopping as soon as all result are
// bound.
Expand Down
75 changes: 30 additions & 45 deletions src/engine/sparqlExpressions/SparqlExpressionGenerators.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace sparqlExpression::detail {

/// Convert a variable to a vector of all the Ids it is bound to in the
/// `context`.
inline std::span<const ValueId> getIdsFromVariable(
const ::Variable& variable, const EvaluationContext* context,
size_t beginIndex, size_t endIndex) {
inline std::span<const ValueId> getIdsFromVariable(const ::Variable& variable,
const EvaluationContext* context,
size_t beginIndex, size_t endIndex) {
const auto& inputTable = context->_inputTable;

const auto& varToColMap = context->_variableToColumnMap;
Expand All @@ -28,18 +28,15 @@ inline std::span<const ValueId> getIdsFromVariable(

std::span<const ValueId> completeColumn = inputTable.getColumn(columnIndex);

AD_CONTRACT_CHECK(beginIndex <= endIndex &&
endIndex <= completeColumn.size());
return {completeColumn.begin() + beginIndex,
completeColumn.begin() + endIndex};
AD_CONTRACT_CHECK(beginIndex <= endIndex && endIndex <= completeColumn.size());
return {completeColumn.begin() + beginIndex, completeColumn.begin() + endIndex};
}

// Overload that reads the `beginIndex` and the `endIndex` directly from the
// `context
inline std::span<const ValueId> getIdsFromVariable(
const ::Variable& variable, const EvaluationContext* context) {
return getIdsFromVariable(variable, context, context->_beginIndex,
context->_endIndex);
inline std::span<const ValueId> getIdsFromVariable(const ::Variable& variable,
const EvaluationContext* context) {
return getIdsFromVariable(variable, context, context->_beginIndex, context->_endIndex);
}

/// Generators that yield `numItems` items for the various
Expand All @@ -48,9 +45,8 @@ inline std::span<const ValueId> getIdsFromVariable(
/// `SparqlExpressionValueGetters` with an already bound `EvaluationContext`.
template <SingleExpressionResult T, typename Transformation = std::identity>
requires isConstantResult<T> && std::invocable<Transformation, T>
cppcoro::generator<const std::decay_t<std::invoke_result_t<Transformation, T>>>
resultGenerator(T constant, size_t numItems,
Transformation transformation = {}) {
cppcoro::generator<const std::decay_t<std::invoke_result_t<Transformation, T>>> resultGenerator(
T constant, size_t numItems, Transformation transformation = {}) {
auto transformed = transformation(constant);
for (size_t i = 0; i < numItems; ++i) {
co_yield transformed;
Expand All @@ -59,10 +55,9 @@ resultGenerator(T constant, size_t numItems,

template <typename T, typename Transformation = std::identity>
requires std::ranges::input_range<T>
auto resultGenerator(T vector, size_t numItems,
Transformation transformation = {})
-> cppcoro::generator<std::decay_t<std::invoke_result_t<
Transformation, std::remove_reference_t<decltype(*vector.begin())>>>> {
auto resultGenerator(T vector, size_t numItems, Transformation transformation = {})
-> cppcoro::generator<std::decay_t<
std::invoke_result_t<Transformation, std::remove_reference_t<decltype(*vector.begin())>>>> {
AD_CONTRACT_CHECK(numItems == vector.size());
for (auto& element : vector) {
auto cpy = transformation(std::move(element));
Expand All @@ -71,8 +66,7 @@ auto resultGenerator(T vector, size_t numItems,
}

template <typename Transformation = std::identity>
inline cppcoro::generator<
const std::decay_t<std::invoke_result_t<Transformation, Id>>>
inline cppcoro::generator<const std::decay_t<std::invoke_result_t<Transformation, Id>>>
resultGenerator(ad_utility::SetOfIntervals set, size_t targetSize,
Transformation transformation = {}) {
size_t i = 0;
Expand All @@ -96,43 +90,36 @@ resultGenerator(ad_utility::SetOfIntervals set, size_t targetSize,
/// Return a generator that yields `numItems` many items for the various
/// `SingleExpressionResult`
template <SingleExpressionResult Input, typename Transformation = std::identity>
auto makeGenerator(Input&& input, size_t numItems,
const EvaluationContext* context,
auto makeGenerator(Input&& input, size_t numItems, const EvaluationContext* context,
Transformation transformation = {}) {
if constexpr (ad_utility::isSimilar<::Variable, Input>) {
std::span<const ValueId> inputWithVariableResolved{
getIdsFromVariable(std::forward<Input>(input), context)};
return resultGenerator(inputWithVariableResolved, numItems, transformation);
} else {
return resultGenerator(std::forward<Input>(input), numItems,
transformation);
return resultGenerator(std::forward<Input>(input), numItems, transformation);
}
}

/// Generate `numItems` many values from the `input` and apply the
/// `valueGetter` to each of the values.
inline auto valueGetterGenerator =
[]<typename ValueGetter, SingleExpressionResult Input>(
size_t numElements, EvaluationContext* context, Input&& input,
ValueGetter&& valueGetter) {
auto transformation =
[context, valueGetter]<typename I>(I&& i)
requires std::invocable<ValueGetter, I&&, EvaluationContext*> {
context->cancellationHandle_->throwIfCancelled();
return valueGetter(AD_FWD(i), context);
};
return makeGenerator(std::forward<Input>(input), numElements, context,
transformation);
};
inline auto valueGetterGenerator = []<typename ValueGetter, SingleExpressionResult Input>(
size_t numElements, EvaluationContext* context,
Input&& input, ValueGetter&& valueGetter) {
auto transformation = [ context, valueGetter ]<typename I>(I && i)
requires std::invocable<ValueGetter, I&&, EvaluationContext*> {
context->cancellationHandle_->throwIfCancelled();
return valueGetter(AD_FWD(i), context);
};
return makeGenerator(std::forward<Input>(input), numElements, context, transformation);
};

/// Do the following `numItems` times: Obtain the next elements e_1, ..., e_n
/// from the `generators` and yield `function(e_1, ..., e_n)`, also as a
/// generator.
inline auto applyFunction = []<typename Function, typename... Generators>(
Function&& function, size_t numItems,
Generators... generators)
-> cppcoro::generator<
std::invoke_result_t<Function, typename Generators::value_type...>> {
Function&& function, size_t numItems, Generators... generators)
-> cppcoro::generator<std::invoke_result_t<Function, typename Generators::value_type...>> {
// A tuple holding one iterator to each of the generators.
std::tuple iterators{generators.begin()...};

Expand Down Expand Up @@ -163,8 +150,7 @@ auto applyOperation(size_t numElements, Operation&&, EvaluationContext* context,

// Function that takes all the generators as a parameter pack and computes the
// generator for the operation result;
auto getResultFromGenerators =
std::bind_front(applyFunction, Function{}, numElements);
auto getResultFromGenerators = std::bind_front(applyFunction, Function{}, numElements);

/// The `ValueGetters` are stored in a `std::tuple`, so we have to extract
/// them via `std::apply`. First set up a lambda that performs the actual
Expand All @@ -173,8 +159,7 @@ auto applyOperation(size_t numElements, Operation&&, EvaluationContext* context,
// Both `operands` and `valueGetters` are parameter packs of equal size,
// so there will be one call to `getValue` for each pair of
// (`operands`, `valueGetter`)
return getResultFromGenerators(
getValue(std::forward<Operands>(operands), valueGetters)...);
return getResultFromGenerators(getValue(std::forward<Operands>(operands), valueGetters)...);
};

return std::apply(getResultFromValueGetters, ValueGetters{});
Expand Down
5 changes: 2 additions & 3 deletions src/engine/sparqlExpressions/StringExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,8 @@ class ConcatExpression : public detail::VariadicExpression {
// were constants (see above).
std::variant<std::string, StringVec> result{std::string{""}};
auto visitSingleExpressionResult =
[&ctx, &result]<SingleExpressionResult T>(T&& s)
requires std::is_rvalue_reference_v<T&&>
{
[&ctx, &result ]<SingleExpressionResult T>(T && s)
requires std::is_rvalue_reference_v<T&&> {
if constexpr (isConstantResult<T>) {
std::string strFromConstant = StringValueGetter{}(s, ctx).value_or("");
if (std::holds_alternative<std::string>(result)) {
Expand Down
14 changes: 8 additions & 6 deletions src/index/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
add_subdirectory(vocabulary)
add_library(index Index.cpp IndexImpl.cpp IndexImpl.Text.cpp Vocabulary
.cpp VocabularyOnDisk.cpp Permutation.cpp TextMetaData
.cpp DocsDB.cpp FTSAlgorithms.cpp PrefixHeuristic
.cpp CompressedRelation.cpp PatternCreator.cpp)
qlever_target_link_libraries(
index util parser vocabulary compilationInfo ${STXXL_LIBRARIES})
add_library(index
Index.cpp IndexImpl.cpp IndexImpl.Text.cpp
Vocabulary.cpp VocabularyOnDisk.cpp
Permutation.cpp TextMetaData.cpp
DocsDB.cpp FTSAlgorithms.cpp
PrefixHeuristic.cpp CompressedRelation.cpp
PatternCreator.cpp)
qlever_target_link_libraries(index util parser vocabulary compilationInfo ${STXXL_LIBRARIES})
Loading

0 comments on commit d2ea890

Please sign in to comment.