Skip to content

Commit 3432e75

Browse files
reduce deps for sys view usage (#4295)
1 parent f78f8bc commit 3432e75

File tree

18 files changed

+248
-69
lines changed

18 files changed

+248
-69
lines changed

ydb/core/tx/columnshard/engines/reader/abstract/constructor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "constructor.h"
2+
#include <ydb/core/tx/columnshard/engines/reader/sys_view/abstract/policy.h>
23
#include <ydb/core/tx/program/program.h>
34

45
namespace NKikimr::NOlap::NReader {

ydb/core/tx/columnshard/engines/reader/abstract/constructor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class IScannerConstructor {
1717
const TString& serializedProgram, TReadDescription& read, const IColumnResolver& columnResolver) const;
1818
private:
1919
virtual TConclusion<std::shared_ptr<TReadMetadataBase>> DoBuildReadMetadata(const NColumnShard::TColumnShard* self, const TReadDescription& read) const = 0;
20-
2120
public:
2221
virtual ~IScannerConstructor() = default;
2322

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include "filler.h"
2+
#include "metadata.h"
3+
#include <ydb/core/tx/columnshard/engines/column_engine_logs.h>
4+
#include <ydb/core/tx/columnshard/columnshard_impl.h>
5+
6+
namespace NKikimr::NOlap::NReader::NSysView::NAbstract {
7+
8+
NKikimr::TConclusionStatus TMetadataFromStore::DoFillMetadata(const NColumnShard::TColumnShard* shard, const std::shared_ptr<TReadMetadataBase>& metadataExt, const TReadDescription& read) const {
9+
std::shared_ptr<TReadStatsMetadata> metadata = dynamic_pointer_cast<TReadStatsMetadata>(metadataExt);
10+
if (!metadata) {
11+
return TConclusionStatus::Fail("incorrect metadata class for filler");
12+
}
13+
const TColumnEngineForLogs* logsIndex = dynamic_cast<const TColumnEngineForLogs*>(shard->GetIndexOptional());
14+
if (!logsIndex) {
15+
return TConclusionStatus::Success();
16+
}
17+
18+
THashSet<ui64> pathIds;
19+
for (auto&& filter : read.PKRangesFilter) {
20+
const ui64 fromPathId = *filter.GetPredicateFrom().Get<arrow::UInt64Array>(0, 0, 1);
21+
const ui64 toPathId = *filter.GetPredicateTo().Get<arrow::UInt64Array>(0, 0, Max<ui64>());
22+
auto pathInfos = logsIndex->GetTables(fromPathId, toPathId);
23+
for (auto&& pathInfo : pathInfos) {
24+
if (pathIds.emplace(pathInfo->GetPathId()).second) {
25+
metadata->IndexGranules.emplace_back(NAbstract::TGranuleMetaView(*pathInfo, metadata->IsDescSorted()));
26+
}
27+
}
28+
}
29+
std::sort(metadata->IndexGranules.begin(), metadata->IndexGranules.end());
30+
if (metadata->IsDescSorted()) {
31+
std::reverse(metadata->IndexGranules.begin(), metadata->IndexGranules.end());
32+
}
33+
return TConclusionStatus::Success();
34+
}
35+
36+
NKikimr::TConclusionStatus TMetadataFromTable::DoFillMetadata(const NColumnShard::TColumnShard* shard, const std::shared_ptr<TReadMetadataBase>& metadataExt, const TReadDescription& read) const {
37+
std::shared_ptr<TReadStatsMetadata> metadata = dynamic_pointer_cast<TReadStatsMetadata>(metadataExt);
38+
if (!metadata) {
39+
return TConclusionStatus::Fail("incorrect metadata class for filler");
40+
}
41+
const TColumnEngineForLogs* logsIndex = dynamic_cast<const TColumnEngineForLogs*>(shard->GetIndexOptional());
42+
if (!logsIndex) {
43+
return TConclusionStatus::Success();
44+
}
45+
for (auto&& filter : read.PKRangesFilter) {
46+
const ui64 fromPathId = *filter.GetPredicateFrom().Get<arrow::UInt64Array>(0, 0, 1);
47+
const ui64 toPathId = *filter.GetPredicateTo().Get<arrow::UInt64Array>(0, 0, Max<ui64>());
48+
if (fromPathId <= read.PathId && read.PathId <= toPathId) {
49+
auto pathInfo = logsIndex->GetGranuleOptional(read.PathId);
50+
if (!pathInfo) {
51+
continue;
52+
}
53+
metadata->IndexGranules.emplace_back(NAbstract::TGranuleMetaView(*pathInfo, metadata->IsDescSorted()));
54+
break;
55+
}
56+
}
57+
std::sort(metadata->IndexGranules.begin(), metadata->IndexGranules.end());
58+
if (metadata->IsDescSorted()) {
59+
std::reverse(metadata->IndexGranules.begin(), metadata->IndexGranules.end());
60+
}
61+
return TConclusionStatus::Success();
62+
}
63+
64+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
#include <ydb/core/tx/columnshard/engines/reader/abstract/read_metadata.h>
3+
#include <ydb/core/tx/columnshard/engines/reader/common/description.h>
4+
5+
namespace NKikimr::NOlap::NReader::NSysView::NAbstract {
6+
7+
class IMetadataFiller {
8+
private:
9+
virtual TConclusionStatus DoFillMetadata(const NColumnShard::TColumnShard* shard, const std::shared_ptr<TReadMetadataBase>& metadata, const TReadDescription& read) const = 0;
10+
public:
11+
virtual ~IMetadataFiller() = default;
12+
13+
TConclusionStatus FillMetadata(const NColumnShard::TColumnShard* shard, const std::shared_ptr<TReadMetadataBase>& metadata, const TReadDescription& read) const {
14+
return DoFillMetadata(shard, metadata, read);
15+
}
16+
};
17+
18+
class TMetadataFromStore: public IMetadataFiller {
19+
protected:
20+
virtual TConclusionStatus DoFillMetadata(const NColumnShard::TColumnShard* shard, const std::shared_ptr<TReadMetadataBase>& metadata, const TReadDescription& read) const override;
21+
public:
22+
23+
};
24+
25+
class TMetadataFromTable: public IMetadataFiller {
26+
protected:
27+
virtual TConclusionStatus DoFillMetadata(const NColumnShard::TColumnShard* shard, const std::shared_ptr<TReadMetadataBase>& metadata, const TReadDescription& read) const override;
28+
public:
29+
30+
};
31+
32+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "policy.h"
2+
#include <util/folder/path.h>
3+
#include <ydb/core/sys_view/common/path.h>
4+
5+
namespace NKikimr::NOlap::NReader::NSysView::NAbstract {
6+
7+
THolder<ISysViewPolicy> ISysViewPolicy::BuildByPath(const TString& tablePath) {
8+
auto fixed = TFsPath(tablePath).Fix();
9+
if (fixed.Parent().GetName() != ::NKikimr::NSysView::SysPathName) {
10+
return nullptr;
11+
} else {
12+
return TFactory::MakeHolder(fixed.GetName());
13+
}
14+
}
15+
16+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
#include "filler.h"
3+
4+
#include <ydb/core/tx/columnshard/common/snapshot.h>
5+
#include <ydb/core/tx/columnshard/engines/reader/abstract/constructor.h>
6+
7+
#include <library/cpp/object_factory/object_factory.h>
8+
9+
namespace NKikimr::NOlap::NReader::NSysView::NAbstract {
10+
11+
class ISysViewPolicy {
12+
private:
13+
virtual std::unique_ptr<IScannerConstructor> DoCreateConstructor(const TSnapshot& snapshot, const ui64 itemsLimit, const bool reverse) const = 0;
14+
virtual std::shared_ptr<IMetadataFiller> DoCreateMetadataFiller() const = 0;
15+
public:
16+
virtual ~ISysViewPolicy() = default;
17+
18+
using TFactory = NObjectFactory::TObjectFactory<ISysViewPolicy, TString>;
19+
20+
static THolder<ISysViewPolicy> BuildByPath(const TString& tablePath);
21+
22+
std::shared_ptr<IMetadataFiller> CreateMetadataFiller() const {
23+
auto result = DoCreateMetadataFiller();
24+
AFL_VERIFY(!!result);
25+
return result;
26+
}
27+
std::unique_ptr<IScannerConstructor> CreateConstructor(const TSnapshot& snapshot, const ui64 itemsLimit, const bool reverse) const {
28+
auto result = DoCreateConstructor(snapshot, itemsLimit, reverse);
29+
AFL_VERIFY(!!result);
30+
return result;
31+
}
32+
};
33+
34+
}

ydb/core/tx/columnshard/engines/reader/sys_view/abstract/ya.make

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ SRCS(
88
iterator.cpp
99
metadata.cpp
1010
granule_view.cpp
11+
filler.cpp
12+
policy.cpp
1113
)
1214

1315
END()

ydb/core/tx/columnshard/engines/reader/sys_view/chunks/chunks.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,30 @@ class TStatsIterator: public NAbstract::TStatsIterator<NKikimr::NSysView::Schema
3636
using TBase::TBase;
3737
};
3838

39+
class TStoreSysViewPolicy: public NAbstract::ISysViewPolicy {
40+
protected:
41+
virtual std::unique_ptr<IScannerConstructor> DoCreateConstructor(const TSnapshot& snapshot, const ui64 itemsLimit, const bool reverse) const override {
42+
return std::make_unique<TConstructor>(snapshot, itemsLimit, reverse);
43+
}
44+
virtual std::shared_ptr<NAbstract::IMetadataFiller> DoCreateMetadataFiller() const override {
45+
return std::make_shared<NAbstract::TMetadataFromStore>();
46+
}
47+
public:
48+
static const inline TFactory::TRegistrator<TStoreSysViewPolicy> Registrator = TFactory::TRegistrator<TStoreSysViewPolicy>(TString(::NKikimr::NSysView::StorePrimaryIndexStatsName));
49+
50+
};
51+
52+
class TTableSysViewPolicy: public NAbstract::ISysViewPolicy {
53+
protected:
54+
virtual std::unique_ptr<IScannerConstructor> DoCreateConstructor(const TSnapshot& snapshot, const ui64 itemsLimit, const bool reverse) const override {
55+
return std::make_unique<TConstructor>(snapshot, itemsLimit, reverse);
56+
}
57+
virtual std::shared_ptr<NAbstract::IMetadataFiller> DoCreateMetadataFiller() const override {
58+
return std::make_shared<NAbstract::TMetadataFromTable>();
59+
}
60+
public:
61+
static const inline TFactory::TRegistrator<TTableSysViewPolicy> Registrator = TFactory::TRegistrator<TTableSysViewPolicy>(TString(::NKikimr::NSysView::TablePrimaryIndexStatsName));
62+
63+
};
64+
3965
}

ydb/core/tx/columnshard/engines/reader/sys_view/chunks/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PEERDIR(
55
)
66

77
SRCS(
8-
chunks.cpp
8+
GLOBAL chunks.cpp
99
)
1010

1111
END()

ydb/core/tx/columnshard/engines/reader/sys_view/constructor/constructor.h

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <ydb/core/tx/columnshard/engines/reader/abstract/constructor.h>
33
#include <ydb/core/tx/columnshard/engines/reader/abstract/read_metadata.h>
44
#include <ydb/core/tx/columnshard/engines/reader/sys_view/abstract/iterator.h>
5+
#include <ydb/core/tx/columnshard/engines/reader/sys_view/abstract/policy.h>
56
#include <ydb/core/tx/columnshard/engines/column_engine_logs.h>
67
#include <ydb/core/tx/columnshard/columnshard_impl.h>
78

@@ -32,43 +33,17 @@ class TStatScannerConstructor: public IScannerConstructor {
3233
out->ReadColumnIds.assign(readColumnIds.begin(), readColumnIds.end());
3334
out->ResultColumnIds = read.ColumnIds;
3435

35-
const TColumnEngineForLogs* logsIndex = dynamic_cast<const TColumnEngineForLogs*>(self->GetIndexOptional());
36-
if (!logsIndex) {
37-
return dynamic_pointer_cast<TReadMetadataBase>(out);
36+
auto policy = NAbstract::ISysViewPolicy::BuildByPath(read.TableName);
37+
if (!policy) {
38+
return TConclusionStatus::Fail("undefined table name: " + TFsPath(read.TableName).GetName());
3839
}
39-
THashSet<ui64> pathIds;
40-
for (auto&& filter : read.PKRangesFilter) {
41-
const ui64 fromPathId = *filter.GetPredicateFrom().Get<arrow::UInt64Array>(0, 0, 1);
42-
const ui64 toPathId = *filter.GetPredicateTo().Get<arrow::UInt64Array>(0, 0, Max<ui64>());
43-
if (read.TableName.EndsWith(IIndexInfo::TABLE_INDEX_STATS_TABLE)
44-
|| read.TableName.EndsWith(IIndexInfo::TABLE_INDEX_PORTION_STATS_TABLE)
45-
|| read.TableName.EndsWith(IIndexInfo::TABLE_INDEX_GRANULE_STATS_TABLE)
46-
) {
47-
if (fromPathId <= read.PathId && read.PathId <= toPathId) {
48-
auto pathInfo = logsIndex->GetGranuleOptional(read.PathId);
49-
if (!pathInfo) {
50-
continue;
51-
}
52-
if (pathIds.emplace(pathInfo->GetPathId()).second) {
53-
out->IndexGranules.emplace_back(NAbstract::TGranuleMetaView(*pathInfo, out->IsDescSorted()));
54-
}
55-
}
56-
} else if (read.TableName.EndsWith(IIndexInfo::STORE_INDEX_STATS_TABLE)
57-
|| read.TableName.EndsWith(IIndexInfo::STORE_INDEX_PORTION_STATS_TABLE)
58-
|| read.TableName.EndsWith(IIndexInfo::STORE_INDEX_GRANULE_STATS_TABLE)
59-
) {
60-
auto pathInfos = logsIndex->GetTables(fromPathId, toPathId);
61-
for (auto&& pathInfo : pathInfos) {
62-
if (pathIds.emplace(pathInfo->GetPathId()).second) {
63-
out->IndexGranules.emplace_back(NAbstract::TGranuleMetaView(*pathInfo, out->IsDescSorted()));
64-
}
65-
}
66-
}
67-
}
68-
std::sort(out->IndexGranules.begin(), out->IndexGranules.end());
69-
if (out->IsDescSorted()) {
70-
std::reverse(out->IndexGranules.begin(), out->IndexGranules.end());
40+
auto filler = policy->CreateMetadataFiller();
41+
42+
auto fillConclusion = filler->FillMetadata(self, out, read);
43+
if (fillConclusion.IsFail()) {
44+
return fillConclusion;
7145
}
46+
7247
return dynamic_pointer_cast<TReadMetadataBase>(out);
7348
}
7449
public:

0 commit comments

Comments
 (0)