-
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.
* Added conversion str to int * templated function for toNumeric, add declaration to NaryExpression.h * str to num for SparqlExpression implemented + added test * Update src/engine/sparqlExpressions/StringExpressions.cpp Co-authored-by: Johannes Kalmbach <[email protected]> * Update src/engine/sparqlExpressions/StringExpressions.cpp Co-authored-by: Johannes Kalmbach <[email protected]> * Update src/engine/sparqlExpressions/StringExpressions.cpp Co-authored-by: Johannes Kalmbach <[email protected]> * Update src/engine/sparqlExpressions/StringExpressions.cpp Co-authored-by: Johannes Kalmbach <[email protected]> * using now absl::from_chars() and stripping whitespaces for string to number conv. * added new functions to processIriFuntionCall() (for string to number) * renaming to: toIntExpression and toDoubleExpression for later more general implementation * made format (clang-format-16) * Update src/parser/sparqlParser/SparqlQleverVisitor.cpp Co-authored-by: Johannes Kalmbach <[email protected]> * Update src/parser/sparqlParser/SparqlQleverVisitor.cpp Co-authored-by: Johannes Kalmbach <[email protected]> * renaming in NaryExpression.h for accordance with other function, adding correct prefix in Constants.h * added test coverage for function calls makeIntExpression and make DoubleExpression * toNumeric has now correct behavior and uses absl::from_chars() and std::from_chars() * made clang-format for NaryExpressionImpl.h * first implementation NOW() expression * fix spelling error * pass by reference * changes w.r.t. pull-request comments * last changes for #1377 --------- Co-authored-by: Johannes Kalmbach <[email protected]>
- Loading branch information
1 parent
f9e730c
commit 1be8381
Showing
6 changed files
with
121 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2024, University of Freiburg, | ||
// Chair of Algorithms and Data Structures | ||
// Author: Hannes Baumann <[email protected]> | ||
|
||
#include "engine/sparqlExpressions/SparqlExpression.h" | ||
#include "util/ChunkedForLoop.h" | ||
#include "util/Date.h" | ||
#include "util/Random.h" | ||
|
||
namespace sparqlExpression { | ||
|
||
// The expression `NOW()` is evaluated within NowDatetimeExpression.h. | ||
// `NowDatetimeExpression` has to be explicitly constructed from a | ||
// `date-formatted string`, which is for all evaluations within a Sparql | ||
// query the same. | ||
class NowDatetimeExpression : public SparqlExpression { | ||
private: | ||
DateOrLargeYear date_; | ||
|
||
public: | ||
explicit NowDatetimeExpression(const std::string& dateTimeFormat) | ||
: date_(DateOrLargeYear::parseXsdDatetime(dateTimeFormat)) {} | ||
|
||
std::string getCacheKey( | ||
[[maybe_unused]] const VariableToColumnMap& varColMap) const override { | ||
return absl::StrCat("NOW ", date_.toBits()); | ||
} | ||
|
||
ExpressionResult evaluate( | ||
[[maybe_unused]] EvaluationContext* context) const override { | ||
return Id::makeFromDate(date_); | ||
} | ||
|
||
private: | ||
std::span<SparqlExpression::Ptr> childrenImpl() override { return {}; } | ||
}; | ||
|
||
} // 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
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: Hannes Baumann <[email protected]> | ||
|
||
#include "./SparqlExpressionTestHelpers.h" | ||
#include "engine/sparqlExpressions/NowDatetimeExpression.h" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
|
||
using namespace sparqlExpression; | ||
|
||
TEST(NowDatetimeExpression, nowExpressionEvaluate) { | ||
std::string strDate = "2011-01-10T14:45:13.815-05:00"; | ||
TestContext testContext{}; | ||
auto& evaluationContext = testContext.context; | ||
|
||
// technically the evaluation context isn't necessary. | ||
evaluationContext._beginIndex = 43; | ||
evaluationContext._endIndex = 1044; | ||
|
||
// The result should hold an ID (from Date) given that NOW() should return by | ||
// definition a xsd:dateTime: "2011-01-10T14:45:13.815-05:00"^^xsd:dateTime | ||
auto resultAsVariant = | ||
NowDatetimeExpression{strDate}.evaluate(&evaluationContext); | ||
ASSERT_TRUE(std::holds_alternative<Id>(resultAsVariant)); | ||
const auto& resultDate = std::get<Id>(resultAsVariant); | ||
|
||
DateOrLargeYear dateNowTest = | ||
DateOrLargeYear(DateOrLargeYear::parseXsdDatetime(strDate)); | ||
|
||
ASSERT_EQ(resultDate.getDatatype(), Datatype::Date); | ||
ASSERT_EQ(resultDate.getDate(), dateNowTest); | ||
|
||
evaluationContext._isPartOfGroupBy = true; | ||
auto resultAsVariant2 = | ||
NowDatetimeExpression{strDate}.evaluate(&evaluationContext); | ||
ASSERT_TRUE(std::holds_alternative<Id>(resultAsVariant2)); | ||
DateOrLargeYear singleDateNow = std::get<Id>(resultAsVariant2).getDate(); | ||
ASSERT_EQ(singleDateNow, dateNowTest); | ||
} | ||
|
||
TEST(NowDatetimeExpression, getCacheKeyNowExpression) { | ||
std::string strDate1 = "2011-01-10T14:45:13.815-05:00"; | ||
std::string strDate2 = "2024-06-18T12:16:33.815-06:00"; | ||
NowDatetimeExpression dateNow1(strDate1); | ||
NowDatetimeExpression dateNow2(strDate2); | ||
ASSERT_TRUE(dateNow1.getUnaggregatedVariables().empty()); | ||
auto cacheKey1 = dateNow1.getCacheKey({}); | ||
ASSERT_THAT(cacheKey1, ::testing::StartsWith("NOW ")); | ||
ASSERT_EQ(cacheKey1, dateNow1.getCacheKey({})); | ||
// Given that these use the same date-time string the key should be equal. | ||
ASSERT_EQ(cacheKey1, NowDatetimeExpression{strDate1}.getCacheKey({})); | ||
// Given that dateNow1 and dateNow2 are constructed from different date-time | ||
// strings, it should be rather unlikely that their cache-keys are equal. | ||
auto cacheKey2 = dateNow2.getCacheKey({}); | ||
ASSERT_NE(cacheKey1, cacheKey2); | ||
} |
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