Skip to content

Commit 64f4d39

Browse files
Fix failed unit tests after enabling the EnableColumnStatistics feature flag (#11409)
Co-authored-by: pilik <pudge1000-7@ydb.tech>
1 parent fcf6826 commit 64f4d39

File tree

18 files changed

+367
-119
lines changed

18 files changed

+367
-119
lines changed

ydb/core/grpc_services/rpc_read_rows.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ class TReadRowsRPC : public TActorBootstrapped<TReadRowsRPC> {
8282

8383
static constexpr TDuration DEFAULT_TIMEOUT = TDuration::Seconds(60);
8484
public:
85-
explicit TReadRowsRPC(std::unique_ptr<IRequestNoOpCtx> request)
86-
: Request(std::move(request))
85+
explicit TReadRowsRPC(IRequestNoOpCtx* request)
86+
: Request(request)
8787
, PipeCache(MakePipePerNodeCacheID(true))
8888
, Span(TWilsonGrpc::RequestActor, Request->GetWilsonTraceId(), "ReadRowsRpc")
8989
{}
@@ -730,8 +730,13 @@ class TReadRowsRPC : public TActorBootstrapped<TReadRowsRPC> {
730730
NWilson::TSpan Span;
731731
};
732732

733-
void DoReadRowsRequest(std::unique_ptr<IRequestNoOpCtx> p, const IFacilityProvider& f) {
734-
f.RegisterActor(new TReadRowsRPC(std::move(p)));
733+
void DoReadRowsRequest(std::unique_ptr<IRequestNoOpCtx> p, const IFacilityProvider& f) {
734+
f.RegisterActor(new TReadRowsRPC(p.release()));
735+
}
736+
737+
template<>
738+
IActor* TEvReadRowsRequest::CreateRpcActor(NKikimr::NGRpcService::IRequestNoOpCtx* msg) {
739+
return new TReadRowsRPC(msg);
735740
}
736741

737742
} // namespace NKikimr::NGRpcService

ydb/core/kqp/opt/kqp_column_statistics_requester.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ IGraphTransformer::TStatus TKqpColumnStatisticsRequester::DoTransform(TExprNode:
9393
continue;
9494
}
9595

96-
if (!columns.contains(column)) {
96+
if (!columnsMeta.contains(column)) {
9797
YQL_CLOG(DEBUG, ProviderKikimr) << "Table: " + table + " doesn't contain " + column + " to request for column statistics";
98+
continue;
9899
}
99100

100101
NKikimr::NStat::TRequest req;

ydb/core/statistics/database/database.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,15 @@ class TLoadStatisticsQuery : public NKikimr::TQueryBase {
218218
const TPathId PathId;
219219
const ui64 StatType;
220220
const ui32 ColumnTag;
221-
const ui64 Cookie;
222221

223222
std::optional<TString> Data;
224223

225224
public:
226-
TLoadStatisticsQuery(const TString& database, const TPathId& pathId, ui64 statType, ui32 columnTag, ui64 cookie)
225+
TLoadStatisticsQuery(const TString& database, const TPathId& pathId, ui64 statType, ui32 columnTag)
227226
: NKikimr::TQueryBase(NKikimrServices::STATISTICS, {}, database, true)
228227
, PathId(pathId)
229228
, StatType(statType)
230229
, ColumnTag(columnTag)
231-
, Cookie(cookie)
232230
{}
233231

234232
void OnRunQuery() override {
@@ -287,7 +285,6 @@ class TLoadStatisticsQuery : public NKikimr::TQueryBase {
287285
response->Status = status;
288286
response->Issues = std::move(issues);
289287
response->Success = (status == Ydb::StatusIds::SUCCESS);
290-
response->Cookie = Cookie;
291288
if (response->Success) {
292289
response->Data = Data;
293290
}
@@ -302,21 +299,19 @@ class TLoadStatisticsRetryingQuery : public TActorBootstrapped<TLoadStatisticsRe
302299
const TPathId PathId;
303300
const ui64 StatType;
304301
const ui32 ColumnTag;
305-
const ui64 Cookie;
306302

307303
public:
308304
using TLoadRetryingQuery = TQueryRetryActor<
309305
TLoadStatisticsQuery, TEvStatistics::TEvLoadStatisticsQueryResponse,
310-
const TString&, const TPathId&, ui64, ui32, ui64>;
306+
const TString&, const TPathId&, ui64, ui32>;
311307

312308
TLoadStatisticsRetryingQuery(const NActors::TActorId& replyActorId, const TString& database,
313-
const TPathId& pathId, ui64 statType, ui32 columnTag, ui64 cookie)
309+
const TPathId& pathId, ui64 statType, ui32 columnTag)
314310
: ReplyActorId(replyActorId)
315311
, Database(database)
316312
, PathId(pathId)
317313
, StatType(statType)
318314
, ColumnTag(columnTag)
319-
, Cookie(cookie)
320315
{}
321316

322317
void Bootstrap() {
@@ -326,7 +321,7 @@ class TLoadStatisticsRetryingQuery : public TActorBootstrapped<TLoadStatisticsRe
326321
TLoadRetryingQuery::Retryable, TDuration::MilliSeconds(10),
327322
TDuration::MilliSeconds(200), TDuration::Seconds(1),
328323
std::numeric_limits<size_t>::max(), TDuration::Seconds(1)),
329-
Database, PathId, StatType, ColumnTag, Cookie
324+
Database, PathId, StatType, ColumnTag
330325
));
331326
Become(&TLoadStatisticsRetryingQuery::StateFunc);
332327
}
@@ -342,9 +337,9 @@ class TLoadStatisticsRetryingQuery : public TActorBootstrapped<TLoadStatisticsRe
342337
};
343338

344339
NActors::IActor* CreateLoadStatisticsQuery(const NActors::TActorId& replyActorId,
345-
const TString& database, const TPathId& pathId, ui64 statType, ui32 columnTag, ui64 cookie)
340+
const TString& database, const TPathId& pathId, ui64 statType, ui32 columnTag)
346341
{
347-
return new TLoadStatisticsRetryingQuery(replyActorId, database, pathId, statType, columnTag, cookie);
342+
return new TLoadStatisticsRetryingQuery(replyActorId, database, pathId, statType, columnTag);
348343
}
349344

350345

ydb/core/statistics/database/database.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ NActors::IActor* CreateStatisticsTableCreator(std::unique_ptr<NActors::IEventBas
1010
NActors::IActor* CreateSaveStatisticsQuery(const NActors::TActorId& replyActorId, const TString& database,
1111
const TPathId& pathId, ui64 statType, std::vector<ui32>&& columnTags, std::vector<TString>&& data);
1212

13-
NActors::IActor* CreateLoadStatisticsQuery(const NActors::TActorId& replyActorId, const TString& database,
14-
const TPathId& pathId, ui64 statType, ui32 columnTag, ui64 cookie);
13+
NActors::IActor* CreateLoadStatisticsQuery(const NActors::TActorId& replyActorId, const TString& database,
14+
const TPathId& pathId, ui64 statType, ui32 columnTag);
1515

16-
NActors::IActor* CreateDeleteStatisticsQuery(const NActors::TActorId& replyActorId, const TString& database,
16+
NActors::IActor* CreateDeleteStatisticsQuery(const NActors::TActorId& replyActorId, const TString& database,
1717
const TPathId& pathId);
1818

1919
};

ydb/core/statistics/database/ut/ut_database.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ Y_UNIT_TEST_SUITE(StatisticsSaveLoad) {
3333
auto saveResponse = runtime.GrabEdgeEventRethrow<TEvStatistics::TEvSaveStatisticsQueryResponse>(sender);
3434
UNIT_ASSERT(saveResponse->Get()->Success);
3535

36-
runtime.Register(CreateLoadStatisticsQuery(sender, "/Root/Database", pathId, statType, 1, 1),
36+
runtime.Register(CreateLoadStatisticsQuery(sender, "/Root/Database", pathId, statType, 1),
3737
0, 0, TMailboxType::Simple, 0, sender);
3838
auto loadResponseA = runtime.GrabEdgeEventRethrow<TEvStatistics::TEvLoadStatisticsQueryResponse>(sender);
3939
UNIT_ASSERT(loadResponseA->Get()->Success);
4040
UNIT_ASSERT(loadResponseA->Get()->Data);
4141
UNIT_ASSERT_VALUES_EQUAL(*loadResponseA->Get()->Data, "dataA");
4242

43-
runtime.Register(CreateLoadStatisticsQuery(sender, "/Root/Database", pathId, statType, 2, 1),
43+
runtime.Register(CreateLoadStatisticsQuery(sender, "/Root/Database", pathId, statType, 2),
4444
0, 0, TMailboxType::Simple, 0, sender);
4545
auto loadResponseB = runtime.GrabEdgeEventRethrow<TEvStatistics::TEvLoadStatisticsQueryResponse>(sender);
4646
UNIT_ASSERT(loadResponseB->Get()->Success);
@@ -76,7 +76,7 @@ Y_UNIT_TEST_SUITE(StatisticsSaveLoad) {
7676
auto deleteResponse = runtime.GrabEdgeEvent<TEvStatistics::TEvDeleteStatisticsQueryResponse>(sender);
7777
UNIT_ASSERT(deleteResponse->Get()->Success);
7878

79-
runtime.Register(CreateLoadStatisticsQuery(sender, "/Root/Database", pathId, statType, 1, 1),
79+
runtime.Register(CreateLoadStatisticsQuery(sender, "/Root/Database", pathId, statType, 1),
8080
0, 0, TMailboxType::Simple, 0, sender);
8181
auto loadResponseA = runtime.GrabEdgeEvent<TEvStatistics::TEvLoadStatisticsQueryResponse>(sender);
8282
UNIT_ASSERT(!loadResponseA->Get()->Success);

ydb/core/statistics/database/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ LIBRARY()
22

33
SRCS(
44
database.h
5-
database.cpp
5+
database.cpp
66
)
77

88
PEERDIR(

ydb/core/statistics/events.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ struct TEvStatistics {
203203
Ydb::StatusIds::StatusCode Status;
204204
NYql::TIssues Issues;
205205
bool Success = true;
206-
ui64 Cookie = 0;
207206
std::optional<TString> Data;
208207
};
209208

ydb/core/statistics/service/http_request.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "http_request.h"
22

3+
#include <ydb/core/statistics/service/service.h>
34
#include <ydb/core/base/path.h>
45
#include <ydb/core/io_formats/cell_maker/cell_maker.h>
56
#include <ydb/core/statistics/database/database.h>
@@ -118,15 +119,17 @@ void THttpRequest::Handle(TEvStatistics::TEvAnalyzeStatusResponse::TPtr& ev) {
118119
}
119120
}
120121

121-
void THttpRequest::Handle(TEvStatistics::TEvLoadStatisticsQueryResponse::TPtr& ev) {
122+
void THttpRequest::Handle(TEvStatistics::TEvGetStatisticsResult::TPtr& ev) {
122123
const auto msg = ev->Get();
123-
if (!msg->Success || !msg->Data) {
124-
const auto status = std::to_string(static_cast<ui32>(msg->Status));
125-
HttpReply("Error occurred while loading statistics. Status: " + status);
124+
125+
if (!msg->Success
126+
|| msg->StatResponses.empty() || !msg->StatResponses[0].Success
127+
|| msg->StatResponses[0].CountMinSketch.CountMin == nullptr) {
128+
HttpReply("Error occurred while loading statistics.");
126129
return;
127130
}
128131

129-
const auto typeId = static_cast<NScheme::TTypeId>(msg->Cookie);
132+
const auto typeId = static_cast<NScheme::TTypeId>(ev->Cookie);
130133
const NScheme::TTypeInfo typeInfo(typeId);
131134
const TStringBuf value(Params[EParamType::CELL_VALUE]);
132135
TMemoryPool pool(64);
@@ -138,7 +141,7 @@ void THttpRequest::Handle(TEvStatistics::TEvLoadStatisticsQueryResponse::TPtr& e
138141
return;
139142
}
140143

141-
auto countMinSketch = std::unique_ptr<TCountMinSketch>(TCountMinSketch::FromString(msg->Data->Data(), msg->Data->Size()));
144+
const auto countMinSketch = msg->StatResponses[0].CountMinSketch.CountMin.get();
142145
const auto probe = countMinSketch->Probe(cell.Data(), cell.Size());
143146
HttpReply(Params[EParamType::PATH] + "[" + Params[EParamType::COLUMN_NAME] + "]=" + std::to_string(probe));
144147
}
@@ -217,10 +220,16 @@ void THttpRequest::DoCountMinSketchProbe(const TNavigate::TEntry& entry) {
217220

218221
for (const auto& [_, tableInfo]: entry.Columns) {
219222
if (tableInfo.Name == columnName) {
220-
const auto columnTag = tableInfo.Id;
223+
auto request = std::make_unique<TEvStatistics::TEvGetStatistics>();
224+
request->StatType = EStatType::COUNT_MIN_SKETCH;
225+
TRequest req;
226+
req.PathId = entry.TableId.PathId;
227+
req.ColumnTag = tableInfo.Id;
228+
request->StatRequests.emplace_back(std::move(req));
229+
221230
const auto typeId = tableInfo.PType.GetTypeId();
222-
const auto& pathId = entry.TableId.PathId;
223-
Register(CreateLoadStatisticsQuery(SelfId(), Params[EParamType::DATABASE], pathId, EStatType::COUNT_MIN_SKETCH, columnTag, typeId));
231+
const auto statService = MakeStatServiceID(SelfId().NodeId());
232+
Send(statService, request.release(), 0, typeId);
224233
return;
225234
}
226235
}

ydb/core/statistics/service/http_request.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class THttpRequest : public NActors::TActorBootstrapped<THttpRequest> {
4646
hFunc(TEvTxProxySchemeCache::TEvNavigateKeySetResult, Handle);
4747
hFunc(TEvStatistics::TEvAnalyzeStatusResponse, Handle);
4848
hFunc(TEvPipeCache::TEvDeliveryProblem, Handle);
49-
hFunc(TEvStatistics::TEvLoadStatisticsQueryResponse, Handle);
49+
hFunc(TEvStatistics::TEvGetStatisticsResult, Handle);
5050
IgnoreFunc(TEvStatistics::TEvAnalyzeResponse);
5151
default:
5252
LOG_CRIT_S(TlsActivationContext->AsActorContext(), NKikimrServices::STATISTICS,
@@ -57,7 +57,7 @@ class THttpRequest : public NActors::TActorBootstrapped<THttpRequest> {
5757
void Handle(TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr& ev);
5858
void Handle(TEvStatistics::TEvAnalyzeStatusResponse::TPtr& ev);
5959
void Handle(TEvPipeCache::TEvDeliveryProblem::TPtr& ev);
60-
void Handle(TEvStatistics::TEvLoadStatisticsQueryResponse::TPtr& ev);
60+
void Handle(TEvStatistics::TEvGetStatisticsResult::TPtr& ev);
6161

6262
void DoRequest(const TNavigate::TEntry& entry);
6363
void DoAnalyze(const TNavigate::TEntry& entry);

0 commit comments

Comments
 (0)