Skip to content

Commit

Permalink
Merge remote-tracking branch 'ad-freiburg/master' into refactor-resul…
Browse files Browse the repository at this point in the history
…t-table
  • Loading branch information
RobinTF committed Aug 2, 2024
2 parents 23713cc + 3fad814 commit c56dd82
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/engine/GroupBy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ string GroupBy::getCacheKeyImpl() const {
}

string GroupBy::getDescriptor() const {
// TODO<C++23>:: Use std::views::join_with.
if (_groupByVariables.empty()) {
return "GroupBy (implicit)";
}
return "GroupBy on " +
absl::StrJoin(_groupByVariables, " ", &Variable::AbslFormatter);
}
Expand Down
7 changes: 7 additions & 0 deletions test/DateYearDurationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@

using ad_utility::source_location;

namespace {

ad_utility::SlowRandomIntGenerator yearGenerator{-9999, 9999};
ad_utility::SlowRandomIntGenerator monthGenerator{1, 12};
ad_utility::SlowRandomIntGenerator dayGenerator{1, 31};
ad_utility::SlowRandomIntGenerator hourGenerator{0, 23};
ad_utility::SlowRandomIntGenerator minuteGenerator{0, 59};
ad_utility::RandomDoubleGenerator secondGenerator{0, 59.9999};
ad_utility::SlowRandomIntGenerator timeZoneGenerator{-23, 23};
} // namespace

TEST(Date, Size) {
ASSERT_EQ(sizeof(Date), 8);
Expand Down Expand Up @@ -61,6 +64,7 @@ TEST(Date, SetAndExtract) {
}
}

namespace {
Date getRandomDate() {
auto year = yearGenerator();
auto month = monthGenerator();
Expand All @@ -72,6 +76,7 @@ Date getRandomDate() {

return {year, month, day, hour, minute, second, timeZone};
}
} // namespace

TEST(Date, RangeChecks) {
Date date = getRandomDate();
Expand Down Expand Up @@ -130,6 +135,7 @@ TEST(Date, RangeChecks) {
ASSERT_EQ(date, dateCopy);
}

namespace {
auto dateLessComparator = [](Date a, Date b) -> bool {
if (a.getYear() != b.getYear()) {
return a.getYear() < b.getYear();
Expand Down Expand Up @@ -168,6 +174,7 @@ void testSorting(std::vector<Date> dates) {
std::sort(datesCopy.begin(), datesCopy.end(), dateLessComparator);
ASSERT_EQ(dates, datesCopy);
}
} // namespace

TEST(Date, OrderRandomValues) {
auto dates = getRandomDates(100);
Expand Down
5 changes: 5 additions & 0 deletions test/DurationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ TEST(DayTimeDuration, DurationOverflowException) {
}
}

namespace {
//______________________________________________________________________________
// Given that we have a slightly different approach for retrieving the
// individual units in DayTimeDuration (see getValues()) from the total
Expand Down Expand Up @@ -216,6 +217,7 @@ DayTimeDuration::DurationValue toAndFromMilliseconds(int days, int hours,
seconds = remainingMilliseconds / 1000.0;
return {days, hours, minutes, seconds};
}
} // anonymous namespace

//______________________________________________________________________________
TEST(DayTimeDuration, checkInternalConversionForLargeValues) {
Expand Down Expand Up @@ -282,6 +284,8 @@ TEST(DayTimeDuration, testDayTimeDurationOverflow) {
DurationOverflowException);
}

namespace {

//______________________________________________________________________________
ad_utility::SlowRandomIntGenerator randomSign{0, 1};
ad_utility::SlowRandomIntGenerator randomDay{0, 1048575};
Expand Down Expand Up @@ -353,6 +357,7 @@ void testSorting(std::vector<DayTimeDuration> durations) {
std::sort(durationsCopy.begin(), durationsCopy.end(), compareDurationLess);
ASSERT_EQ(durations, durationsCopy);
}
} // anonymous namespace

//______________________________________________________________________________
TEST(DayTimeDuration, testOrderOnBytes) {
Expand Down
16 changes: 15 additions & 1 deletion test/GroupByTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Author: Florian Kramer ([email protected])
// Authors: Florian Kramer ([email protected])
// Johannes Kalmbach ([email protected])

#include <gmock/gmock.h>

Expand All @@ -12,6 +13,7 @@
#include "engine/GroupBy.h"
#include "engine/IndexScan.h"
#include "engine/Join.h"
#include "engine/NeutralElementOperation.h"
#include "engine/QueryPlanner.h"
#include "engine/Sort.h"
#include "engine/Values.h"
Expand Down Expand Up @@ -1932,3 +1934,15 @@ TEST(GroupBy, AddedHavingRows) {
auto expected = makeIdTableFromVector({{i(0), i(3), Id::makeFromBool(true)}});
EXPECT_EQ(table, expected);
}

TEST(GroupBy, Descriptor) {
// Group by with variables
auto* qec = ad_utility::testing::getQec();
auto subtree = ad_utility::makeExecutionTree<ValuesForTesting>(
qec, makeIdTableFromVector({{3}}),
std::vector<std::optional<Variable>>{Variable{"?a"}});
GroupBy groupBy{qec, {Variable{"?a"}}, {}, subtree};
EXPECT_EQ(groupBy.getDescriptor(), "GroupBy on ?a");
GroupBy groupBy2{qec, {}, {}, subtree};
EXPECT_EQ(groupBy2.getDescriptor(), "GroupBy (implicit)");
}

0 comments on commit c56dd82

Please sign in to comment.