Skip to content

Commit b8d338c

Browse files
committed
fix
1 parent fc5ce4b commit b8d338c

File tree

2 files changed

+61
-76
lines changed

2 files changed

+61
-76
lines changed

ydb/library/workload/stock/stock.cpp

Lines changed: 55 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ TStockWorkloadGenerator::TStockWorkloadGenerator(const TStockWorkloadParams* par
3030
, CustomerIdGenerator(1, MAX_CUSTOMERS)
3131
, ProductIdGenerator(1, params->ProductCount)
3232
{
33-
if (Params.TableType != "row" && Params.TableType != "column") {
34-
ythrow yexception() << "Unknown table type: '" << Params.TableType << "'.";
35-
}
3633
Gen.seed(Now().MicroSeconds());
3734
}
3835

@@ -41,51 +38,43 @@ std::string TStockWorkloadGenerator::GetDDLQueries() const {
4138
std::string ordersPartitionsDdl = "";
4239
std::string orderLinesPartitionsDdl = "";
4340

44-
if (Params.TableType == "row") {
41+
if (Params.GetStoreType() == TStockWorkloadParams::EStoreType::Row) {
4542
ordersPartitionsDdl = "WITH (READ_REPLICAS_SETTINGS = \"per_az:1\")";
4643
if (Params.PartitionsByLoad) {
4744
stockPartitionsDdl = std::format(R"(WITH (
48-
STORE = {0}
45+
STORE = ROW
4946
, AUTO_PARTITIONING_BY_LOAD = ENABLED
50-
, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {1}
51-
)", Params.TableType, Params.MinPartitions);
47+
, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {0}
48+
))", Params.MinPartitions);
5249
ordersPartitionsDdl = std::format(R"(WITH (
53-
STORE = {0}
50+
STORE = ROW
5451
, READ_REPLICAS_SETTINGS = "per_az:1"
5552
, AUTO_PARTITIONING_BY_LOAD = ENABLED
56-
, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {1}
53+
, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {0}
5754
, AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = 1000
58-
, UNIFORM_PARTITIONS = {1}
59-
))", Params.TableType, Params.MinPartitions);
55+
, UNIFORM_PARTITIONS = {0}
56+
))", Params.MinPartitions);
6057
orderLinesPartitionsDdl = std::format(R"(WITH (
61-
STORE = {0}
58+
STORE = ROW
6259
, AUTO_PARTITIONING_BY_LOAD = ENABLED
63-
, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {1}
60+
, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {0}
6461
, AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = 1000
65-
, UNIFORM_PARTITIONS = {1}
66-
))", Params.TableType, Params.MinPartitions);
62+
, UNIFORM_PARTITIONS = {0}
63+
))", Params.MinPartitions);
6764
}
68-
} else if (Params.TableType == "column") {
65+
} else {
6966
stockPartitionsDdl = std::format(R"(WITH (
70-
STORE = {0}
71-
, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {1}
72-
, AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = {1}
73-
, UNIFORM_PARTITIONS = {1}
74-
))", Params.TableType, Params.MinPartitions);
67+
STORE = COLUMN
68+
, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {0}
69+
))", Params.MinPartitions);
7570
ordersPartitionsDdl = std::format(R"(WITH (
76-
STORE = {0}
77-
, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {1}
78-
, AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = {1}
79-
, UNIFORM_PARTITIONS = {1}
80-
))", Params.TableType, Params.MinPartitions);
71+
STORE = COLUMN
72+
, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {0}
73+
))", Params.MinPartitions);
8174
orderLinesPartitionsDdl = std::format(R"(WITH (
82-
STORE = {0}
83-
, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {1}
84-
, AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = {1}
85-
, UNIFORM_PARTITIONS = {1}
86-
))", Params.TableType, Params.MinPartitions);
87-
} else {
88-
Y_UNREACHABLE();
75+
STORE = COLUMN
76+
, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {0}
77+
))", Params.MinPartitions);
8978
}
9079

9180
std::string changefeeds = "";
@@ -96,22 +85,14 @@ std::string TStockWorkloadGenerator::GetDDLQueries() const {
9685
);)", DbPath);
9786
}
9887

99-
if (Params.TableType == "row") {
100-
return std::format(R"(--!syntax_v1
101-
CREATE TABLE `{0}/stock`(product Utf8, quantity Int64, PRIMARY KEY(product)) {1};
102-
CREATE TABLE `{0}/orders`(id Uint64, customer Utf8, created Datetime, processed Datetime, PRIMARY KEY(id), INDEX ix_cust GLOBAL ON (customer, created) COVER (processed)) {2};
103-
CREATE TABLE `{0}/orderLines`(id_order Uint64, product Utf8, quantity Int64, PRIMARY KEY(id_order, product)) {3};
104-
{4}
105-
)", DbPath, stockPartitionsDdl, ordersPartitionsDdl, orderLinesPartitionsDdl, changefeeds);
106-
} else if (Params.TableType == "column") {
107-
return std::format(R"(--!syntax_v1
108-
CREATE TABLE `{0}/stock`(product Utf8 NOT NULL, quantity Int64, PRIMARY KEY(product)) {1};
109-
CREATE TABLE `{0}/orders`(id Uint64 NOT NULL, customer Utf8, created Datetime, processed Datetime, PRIMARY KEY(id)) {2};
110-
CREATE TABLE `{0}/orderLines`(id_order Uint64 NOT NULL, product Utf8 NOT NULL, quantity Int64, PRIMARY KEY(id_order, product)) {3};
111-
{4}
112-
)", DbPath, stockPartitionsDdl, ordersPartitionsDdl, orderLinesPartitionsDdl, changefeeds);
113-
}
114-
Y_UNREACHABLE();
88+
return std::format(R"(--!syntax_v1
89+
CREATE TABLE `{0}/stock`(product Utf8 {5}, quantity Int64, PRIMARY KEY(product)) {1};
90+
CREATE TABLE `{0}/orders`(id Uint64 {5}, customer Utf8, created Datetime, processed Datetime, PRIMARY KEY(id) {6}) {2};
91+
CREATE TABLE `{0}/orderLines`(id_order Uint64 {5}, product Utf8 {5}, quantity Int64 {5}, PRIMARY KEY(id_order, product)) {3};
92+
{4}
93+
)", DbPath, stockPartitionsDdl, ordersPartitionsDdl, orderLinesPartitionsDdl, changefeeds,
94+
Params.GetStoreType() == TStockWorkloadParams::EStoreType::Row ? "" : "NOT NULL",
95+
Params.GetStoreType() == TStockWorkloadParams::EStoreType::Row ? ", INDEX ix_cust GLOBAL ON (customer, created) COVER (processed)" : "");
11596
}
11697

11798
TQueryInfoList TStockWorkloadGenerator::GetInitialData() {
@@ -247,28 +228,15 @@ TQueryInfo TStockWorkloadGenerator::ExecuteOrder(const uint64_t orderID) {
247228

248229
TQueryInfo TStockWorkloadGenerator::SelectCustomerHistory(const std::string& customerId, const unsigned int limit) {
249230
const std::string query = [this]() {
250-
if (Params.TableType == "row") {
251-
return R"(--!syntax_v1
252-
DECLARE $cust as Utf8;
253-
DECLARE $limit as UInt32;
254-
select id, customer, created
255-
from orders view ix_cust
256-
where customer = $cust
257-
order by customer desc, created desc
258-
limit $limit;
259-
)";
260-
} else if (Params.TableType == "column") {
261-
return R"(--!syntax_v1
262-
DECLARE $cust as Utf8;
263-
DECLARE $limit as UInt32;
264-
select id, customer, created
265-
from orders
266-
where customer = $cust
267-
order by customer desc, created desc
268-
limit $limit;
269-
)";
270-
}
271-
Y_UNREACHABLE();
231+
return std::format(R"(--!syntax_v1
232+
DECLARE $cust as Utf8;
233+
DECLARE $limit as UInt32;
234+
select id, customer, created
235+
from orders {}
236+
where customer = $cust
237+
order by customer desc, created desc
238+
limit $limit;
239+
)", Params.GetStoreType() == TStockWorkloadParams::EStoreType::Row ? "view ix_cust" : "");
272240
}();
273241

274242
NYdb::TParamsBuilder paramsBuilder;
@@ -360,6 +328,20 @@ TQueryInfoList TStockWorkloadGenerator::GetCustomerHistory() {
360328
}
361329

362330
void TStockWorkloadParams::ConfigureOpts(NLastGetopt::TOpts& opts, const ECommandType commandType, int workloadType) {
331+
auto addStorageTypeParam = [&]() {
332+
opts.AddLongOption("store", "Storage type."
333+
" Options: row, column, external-s3\n"
334+
"row - use row-based storage engine;\n"
335+
"column - use column-based storage engine.")
336+
.DefaultValue(StoreType)
337+
.Handler1T<TStringBuf>([this](TStringBuf arg) {
338+
const auto l = to_lower(TString(arg));
339+
if (!TryFromString(arg, StoreType)) {
340+
throw yexception() << "Ivalid store type: " << arg;
341+
}
342+
});
343+
};
344+
363345
switch (commandType) {
364346
case TWorkloadParams::ECommandType::Init:
365347
opts.AddLongOption('p', "products", "Product count. Value in 1..500 000.")
@@ -374,12 +356,10 @@ void TStockWorkloadParams::ConfigureOpts(NLastGetopt::TOpts& opts, const EComman
374356
.DefaultValue(true).StoreResult(&PartitionsByLoad);
375357
opts.AddLongOption("enable-cdc", "Create changefeeds on tables.")
376358
.DefaultValue(false).StoreTrue(&EnableCdc).Hidden();
377-
opts.AddLongOption("store", "Tables type ('row' or 'column'). Default: 'row'.")
378-
.DefaultValue("row").StoreResult(&TableType).Hidden();
359+
addStorageTypeParam();
379360
break;
380361
case TWorkloadParams::ECommandType::Run:
381-
opts.AddLongOption("store", "Tables type ('row' or 'column'). Default: 'row'.")
382-
.DefaultValue("row").StoreResult(&TableType).Hidden();
362+
addStorageTypeParam();
383363
switch (static_cast<TStockWorkloadGenerator::EType>(workloadType)) {
384364
case TStockWorkloadGenerator::EType::InsertRandomOrder:
385365
case TStockWorkloadGenerator::EType::SubmitRandomOrder:

ydb/library/workload/stock/stock.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ namespace NYdbWorkload {
1010

1111
class TStockWorkloadParams final: public TWorkloadParams {
1212
public:
13+
enum class EStoreType {
14+
Row /* "row" */,
15+
Column /* "column" */,
16+
};
17+
1318
void ConfigureOpts(NLastGetopt::TOpts& opts, const ECommandType commandType, int workloadType) override;
1419
THolder<IWorkloadQueryGenerator> CreateGenerator() const override;
1520
TString GetWorkloadName() const override;
@@ -20,7 +25,7 @@ class TStockWorkloadParams final: public TWorkloadParams {
2025
unsigned int Limit = 0;
2126
bool PartitionsByLoad = true;
2227
bool EnableCdc = false;
23-
std::string TableType = "row";
28+
YDB_READONLY(EStoreType, StoreType, EStoreType::Row);
2429
};
2530

2631
class TStockWorkloadGenerator final: public TWorkloadQueryGeneratorBase<TStockWorkloadParams> {

0 commit comments

Comments
 (0)