-
Notifications
You must be signed in to change notification settings - Fork 56
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
Implement functions UUID()
and STRUUID()
#1366
Merged
Merged
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
99da434
Added conversion str to int
realHannes 424d023
templated function for toNumeric, add declaration to NaryExpression.h
realHannes 0117e82
str to num for SparqlExpression implemented + added test
realHannes 35fd0b1
Merge branch 'ad-freiburg:master' into master
realHannes 94356c2
Update src/engine/sparqlExpressions/StringExpressions.cpp
realHannes decc8ba
Update src/engine/sparqlExpressions/StringExpressions.cpp
realHannes 850152c
Update src/engine/sparqlExpressions/StringExpressions.cpp
realHannes d650d67
Update src/engine/sparqlExpressions/StringExpressions.cpp
realHannes 46cc697
using now absl::from_chars() and stripping whitespaces for string to …
realHannes 7fc5c28
added new functions to processIriFuntionCall() (for string to number)
realHannes efb0e24
renaming to: toIntExpression and toDoubleExpression for later more ge…
realHannes a88537c
made format (clang-format-16)
realHannes ca1e2e0
Update src/parser/sparqlParser/SparqlQleverVisitor.cpp
realHannes 4adc831
Update src/parser/sparqlParser/SparqlQleverVisitor.cpp
realHannes d0f0d63
renaming in NaryExpression.h for accordance with other function, addi…
realHannes a118609
added test coverage for function calls makeIntExpression and make Dou…
realHannes 062052e
toNumeric has now correct behavior and uses absl::from_chars() and st…
realHannes 6d0f42a
made clang-format for NaryExpressionImpl.h
realHannes f90b8e2
Merge branch 'ad-freiburg:master' into master
realHannes fb88493
Merge branch 'ad-freiburg:master' into master
realHannes b2eb514
Merge remote-tracking branch 'upstream/master'
realHannes b165ac1
Merge branch 'ad-freiburg:master' into master
realHannes 7a3dfb2
Merge branch 'master' of https://github.com/realHannes/qlever
realHannes fc0ad3a
Merge branch 'ad-freiburg:master' into master
realHannes f3e6086
Merge branch 'ad-freiburg:master' into master
realHannes 4dcffc0
started implementation for Uuid
realHannes 1f02cae
implemented struuid() and uuid()
realHannes 3c27e9d
moved uuid expressions to separate file + fix in random
realHannes d25d402
added test coverage + changes for sonarcloud
realHannes c40f846
Merge branch 'ad-freiburg:master' into uuid_and_str_uuid
realHannes 635b27e
implemented suggested changes #1366
realHannes d749b7d
made format
realHannes c5535e5
use namespace detail
realHannes 15a929f
Merge branch 'ad-freiburg:master' into uuid_and_str_uuid
realHannes 35b061b
correct usage of namespace #1366
realHannes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2024, University of Freiburg, | ||
// Chair of Algorithms and Data Structures | ||
// Author: Hannes Baumann <[email protected]> | ||
|
||
// Test for UuidExpressionImpl can be found in RandomExpressionTest.cpp | ||
|
||
#pragma once | ||
|
||
#include "engine/sparqlExpressions/SparqlExpression.h" | ||
#include "util/ChunkedForLoop.h" | ||
#include "util/Random.h" | ||
|
||
namespace sparqlExpression { | ||
namespace detail::uuidExpression { | ||
|
||
using LiteralOrIri = ad_utility::triple_component::LiteralOrIri; | ||
|
||
inline constexpr auto fromLiteral = [](std::string_view str) { | ||
return LiteralOrIri{ | ||
ad_utility::triple_component::Literal::literalWithNormalizedContent( | ||
asNormalizedStringViewUnsafe(str))}; | ||
}; | ||
|
||
inline constexpr auto fromIri = [](std::string_view str) { | ||
return LiteralOrIri{ | ||
ad_utility::triple_component::Iri::fromStringRepresentation( | ||
absl::StrCat("<urn:uuid:"sv, str, ">"sv))}; | ||
}; | ||
|
||
inline constexpr auto litUuidKey = [](int64_t randId) { | ||
return absl::StrCat("STRUUID "sv, randId); | ||
}; | ||
|
||
inline constexpr auto iriUuidKey = [](int64_t randId) { | ||
return absl::StrCat("UUID "sv, randId); | ||
}; | ||
|
||
// With UuidExpressionImpl<fromIri, iriUuidKey>, the UUIDs are returned as an | ||
// Iri object: <urn:uuid:b9302fb5-642e-4d3b-af19-29a8f6d894c9> (example). With | ||
// UuidExpressionImpl<fromLiteral,, litUuidKey>, the UUIDs are returned as an | ||
// Literal object: "73cd4307-8a99-4691-a608-b5bda64fb6c1" (example). | ||
template <auto FuncConv, auto FuncKey> | ||
class UuidExpressionImpl : public SparqlExpression { | ||
private: | ||
int64_t randId_ = ad_utility::FastRandomIntGenerator<int64_t>{}(); | ||
|
||
public: | ||
ExpressionResult evaluate(EvaluationContext* context) const override { | ||
VectorWithMemoryLimit<IdOrLiteralOrIri> result{context->_allocator}; | ||
const size_t numElements = context->_endIndex - context->_beginIndex; | ||
result.reserve(numElements); | ||
ad_utility::UuidGenerator uuidGen; | ||
|
||
if (context->_isPartOfGroupBy) { | ||
return FuncConv(uuidGen()); | ||
} | ||
|
||
ad_utility::chunkedForLoop<1000>( | ||
0, numElements, | ||
[&result, &uuidGen](size_t) { result.push_back(FuncConv(uuidGen())); }, | ||
[context]() { context->cancellationHandle_->throwIfCancelled(); }); | ||
return result; | ||
} | ||
|
||
string getCacheKey( | ||
[[maybe_unused]] const VariableToColumnMap& varColMap) const override { | ||
return FuncKey(randId_); | ||
} | ||
|
||
private: | ||
std::span<SparqlExpression::Ptr> childrenImpl() override { return {}; } | ||
}; | ||
|
||
} // namespace detail::uuidExpression | ||
|
||
using namespace detail::uuidExpression; | ||
realHannes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
using UuidExpression = UuidExpressionImpl<fromIri, iriUuidKey>; | ||
using StrUuidExpression = UuidExpressionImpl<fromLiteral, litUuidKey>; | ||
|
||
} // namespace sparqlExpression |
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 |
---|---|---|
|
@@ -2,8 +2,11 @@ | |
// Chair of Algorithms and Data Structures. | ||
// Author: Johannes Kalmbach <[email protected]> | ||
|
||
#include <unordered_set> | ||
|
||
#include "./SparqlExpressionTestHelpers.h" | ||
#include "engine/sparqlExpressions/RandomExpression.h" | ||
#include "engine/sparqlExpressions/UuidExpressions.h" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
|
||
|
@@ -58,3 +61,89 @@ TEST(RandomExpression, simpleMemberFunctions) { | |
// probability of `1 / 2^64` of a spurious failure. | ||
ASSERT_NE(cacheKey, RandomExpression{}.getCacheKey({})); | ||
} | ||
|
||
// The tests for UUID expressions follow almost exactly the pattern | ||
// of the above defined test for RandomExpression. | ||
TEST(UuidExpression, simpleMemberFunctionStrUuid) { | ||
StrUuidExpression strUuid; | ||
ASSERT_TRUE(strUuid.getUnaggregatedVariables().empty()); | ||
auto cacheKeyStrUuid = strUuid.getCacheKey({}); | ||
ASSERT_THAT(cacheKeyStrUuid, ::testing::StartsWith("STRUUID ")); | ||
ASSERT_EQ(cacheKeyStrUuid, strUuid.getCacheKey({})); | ||
StrUuidExpression strUuid2; | ||
ASSERT_NE(cacheKeyStrUuid, strUuid2.getCacheKey({})); | ||
} | ||
|
||
TEST(UuidExpression, simpleMemberFunctionLitUuid) { | ||
UuidExpression iriUuid; | ||
ASSERT_TRUE(iriUuid.getUnaggregatedVariables().empty()); | ||
auto cacheKeyIriUuid = iriUuid.getCacheKey({}); | ||
ASSERT_THAT(cacheKeyIriUuid, ::testing::StartsWith("UUID ")); | ||
ASSERT_EQ(cacheKeyIriUuid, iriUuid.getCacheKey({})); | ||
UuidExpression iriUuid2; | ||
ASSERT_NE(cacheKeyIriUuid, iriUuid2.getCacheKey({})); | ||
} | ||
|
||
TEST(UuidExpression, evaluateStrUuidExpression) { | ||
TestContext testContext{}; | ||
auto& evaluationContext = testContext.context; | ||
evaluationContext._beginIndex = 43; | ||
evaluationContext._endIndex = 1044; | ||
auto resultAsVariant = StrUuidExpression{}.evaluate(&evaluationContext); | ||
|
||
using V = VectorWithMemoryLimit<IdOrLiteralOrIri>; | ||
ASSERT_TRUE(std::holds_alternative<V>(resultAsVariant)); | ||
const auto& resultVector = std::get<V>(resultAsVariant); | ||
ASSERT_EQ(resultVector.size(), 1001); | ||
|
||
// check that none of the results equals all previous results | ||
std::unordered_set<std::string> strUuids; | ||
for (auto uuid : resultVector) { | ||
ASSERT_TRUE(std::holds_alternative<LiteralOrIri>(uuid)); | ||
LiteralOrIri litUuid = std::get<LiteralOrIri>(uuid); | ||
ASSERT_TRUE(litUuid.isLiteral()); | ||
std::string_view strUuid = | ||
asStringViewUnsafe(litUuid.getLiteral().getContent()); | ||
ASSERT_EQ(strUuids.find(std::string(strUuid)), strUuids.end()); | ||
strUuids.insert(std::string(strUuid)); | ||
} | ||
|
||
evaluationContext._isPartOfGroupBy = true; | ||
auto resultAsVariant2 = StrUuidExpression{}.evaluate(&evaluationContext); | ||
ASSERT_TRUE(std::holds_alternative<IdOrLiteralOrIri>(resultAsVariant2)); | ||
IdOrLiteralOrIri litOrIriUuid = std::get<IdOrLiteralOrIri>(resultAsVariant2); | ||
ASSERT_TRUE(std::holds_alternative<LiteralOrIri>(litOrIriUuid)); | ||
ASSERT_TRUE(std::get<LiteralOrIri>(litOrIriUuid).isLiteral()); | ||
} | ||
|
||
TEST(UuidExpression, evaluateUuidExpression) { | ||
TestContext testContext{}; | ||
auto& evaluationContext = testContext.context; | ||
evaluationContext._beginIndex = 43; | ||
evaluationContext._endIndex = 1044; | ||
auto resultAsVariant = UuidExpression{}.evaluate(&evaluationContext); | ||
|
||
using V = VectorWithMemoryLimit<IdOrLiteralOrIri>; | ||
ASSERT_TRUE(std::holds_alternative<V>(resultAsVariant)); | ||
const auto& resultVector = std::get<V>(resultAsVariant); | ||
ASSERT_EQ(resultVector.size(), 1001); | ||
|
||
// check that none of the results equals all of the other results | ||
std::unordered_set<std::string> strUuids; | ||
for (auto uuid : resultVector) { | ||
ASSERT_TRUE(std::holds_alternative<LiteralOrIri>(uuid)); | ||
LiteralOrIri litUuid = std::get<LiteralOrIri>(uuid); | ||
ASSERT_TRUE(litUuid.isIri()); | ||
std::string_view iriUuid = | ||
asStringViewUnsafe(litUuid.getIri().getContent()); | ||
ASSERT_EQ(strUuids.find(std::string(iriUuid)), strUuids.end()); | ||
strUuids.insert(std::string(iriUuid)); | ||
} | ||
|
||
evaluationContext._isPartOfGroupBy = true; | ||
auto resultAsVariant2 = UuidExpression{}.evaluate(&evaluationContext); | ||
ASSERT_TRUE(std::holds_alternative<IdOrLiteralOrIri>(resultAsVariant2)); | ||
IdOrLiteralOrIri litOrIriUuid = std::get<IdOrLiteralOrIri>(resultAsVariant2); | ||
ASSERT_TRUE(std::holds_alternative<LiteralOrIri>(litOrIriUuid)); | ||
ASSERT_TRUE(std::get<LiteralOrIri>(litOrIriUuid).isIri()); | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inline
is redundant forconstexpr
values, so it can be dropped.sparqlExpression::uuidExpression::detail
or something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow the tests for
builtInCall
don't pass if i remove theinline
.