Skip to content

Commit 5283bad

Browse files
authored
Test for scale factor in tpch queries (#10990)
1 parent 6c73f29 commit 5283bad

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

ydb/library/workload/tpc_base/tpc_base.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,15 @@ void TTpcBaseWorkloadGenerator::PatchQuery(TString& query) const {
9696
}
9797

9898
void TTpcBaseWorkloadGenerator::FilterHeader(IOutputStream& result, TStringBuf header, const TString& query) const {
99+
const TString scaleFactor = "$scale_factor = " + ToString(Params.GetScale()) + ";";
99100
for(TStringBuf line; header.ReadLine(line);) {
100101
const auto pos = line.find('=');
101102
if (pos == line.npos) {
102103
continue;
103104
}
104105
const auto name = StripString(line.SubString(0, pos));
105106
if (name == "$scale_factor") {
106-
line = "$scale_factor = " + ToString(Params.GetScale()) + ";";
107+
line = scaleFactor;
107108
}
108109
for(auto posInQ = query.find(name); posInQ != query.npos; posInQ = query.find(name, posInQ)) {
109110
posInQ += name.length();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <ydb/library/workload/tpch/tpch.h>
2+
#include <library/cpp/testing/unittest/registar.h>
3+
#include <library/cpp/regex/pcre/regexp.h>
4+
5+
using namespace NYdbWorkload;
6+
7+
Y_UNIT_TEST_SUITE(TpchQueries) {
8+
Y_UNIT_TEST(ScaleFactor) {
9+
TTpchWorkloadParams params;
10+
NLastGetopt::TOpts opts;
11+
params.ConfigureOpts(opts, TWorkloadParams::ECommandType::Run, 0);
12+
const char* args[] = {"ut", "--scale", "10"};
13+
for (auto parser = NLastGetopt::TOptsParser(&opts, sizeof(args)/sizeof(*args), args); parser.Next();) {
14+
}
15+
auto generator = params.CreateGenerator();
16+
ui32 query_num = 0;
17+
for (const auto& query: generator->GetWorkload(0)) {
18+
if (query_num == 11) {
19+
UNIT_ASSERT_C(TRegExMatch("\\$scale_factor\\s*=\\s*10\\s*;").Match(query.Query.c_str()),
20+
"Scale factor is wrong for q11:" << Endl << query.Query);
21+
break;
22+
}
23+
++query_num;
24+
}
25+
}
26+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
UNITTEST_FOR(ydb/library/workload/tpch)
2+
3+
SIZE(SMALL)
4+
5+
SRCS(queries_ut.cpp)
6+
7+
PEERDIR(
8+
library/cpp/regex/pcre
9+
)
10+
11+
END()

ydb/library/workload/tpch/ya.make

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,5 @@ PEERDIR(
100100
)
101101

102102
END()
103+
104+
RECURSE_FOR_TESTS(ut)

0 commit comments

Comments
 (0)