Skip to content

Commit 3e4b81c

Browse files
committed
groups table range
1 parent a255f5c commit 3e4b81c

File tree

5 files changed

+51
-24
lines changed

5 files changed

+51
-24
lines changed

ydb/core/sys_view/auth/groups.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class TGroupsScan : public TAuthScanBase<TGroupsScan> {
3333

3434
TVector<const TDomainInfo::TGroup*> groups(::Reserve(entry.DomainInfo->Groups.size()));
3535
for (const auto& group : entry.DomainInfo->Groups) {
36+
if (!OneCellStringKeyIsInTableRange(group.Sid)) {
37+
continue;
38+
}
3639
groups.push_back(&group);
3740
}
3841
SortBatch(groups, [](const auto* left, const auto* right) {

ydb/core/sys_view/auth/owners.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,7 @@ class TOwnersScan : public TAuthScanBase<TOwnersScan> {
3434

3535
auto entryPath = CanonizePath(entry.Path);
3636

37-
bool isInRange = true;
38-
if (auto pathFrom = GetCellFrom(0); pathFrom) {
39-
int cmp = pathFrom->AsBuf().compare(entryPath);
40-
isInRange &= cmp < 0 || cmp == 0 && TableRange.FromInclusive;
41-
}
42-
if (auto pathTo = GetCellTo(0); pathTo) {
43-
int cmp = pathTo->AsBuf().compare(entryPath);
44-
isInRange &= cmp > 0 || cmp == 0 && TableRange.ToInclusive;
45-
}
46-
47-
if (isInRange) {
37+
if (OneCellStringKeyIsInTableRange(entryPath)) {
4838
for (auto& column : Columns) {
4939
switch (column.Tag) {
5040
case Schema::AuthOwners::Path::ColumnId:

ydb/core/sys_view/auth/users.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class TUsersScan : public TScanActorBase<TUsersScan> {
8989
if (!user.HasName() || !CanAccessUser(user.GetName())) {
9090
continue;
9191
}
92+
if (!OneCellStringKeyIsInTableRange(user.GetName())) {
93+
continue;
94+
}
9295
users.push_back(&user);
9396
}
9497
SortBatch(users, [](const auto* left, const auto* right) {
@@ -98,19 +101,6 @@ class TUsersScan : public TScanActorBase<TUsersScan> {
98101
TVector<TCell> cells(::Reserve(Columns.size()));
99102

100103
for (const auto* user : users) {
101-
bool isInRange = true;
102-
if (auto pathFrom = GetCellFrom(0); pathFrom) {
103-
int cmp = pathFrom->AsBuf().compare(user->GetName());
104-
isInRange &= cmp < 0 || cmp == 0 && TableRange.FromInclusive;
105-
}
106-
if (auto pathTo = GetCellTo(0); pathTo) {
107-
int cmp = pathTo->AsBuf().compare(user->GetName());
108-
isInRange &= cmp > 0 || cmp == 0 && TableRange.ToInclusive;
109-
}
110-
if (!isInRange) {
111-
continue;
112-
}
113-
114104
for (auto& column : Columns) {
115105
switch (column.Tag) {
116106
case Schema::AuthUsers::Sid::ColumnId:

ydb/core/sys_view/common/scan_actor_base_impl.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ class TScanActorBase : public TActorBootstrapped<TDerived> {
170170
return GetCell(TableRange.To.GetCells(), index);
171171
}
172172

173+
bool OneCellStringKeyIsInTableRange(const TString value) const {
174+
if (auto pathFrom = GetCellFrom(0); pathFrom) {
175+
if (int cmp = pathFrom->AsBuf().compare(value); cmp > 0 || cmp == 0 && !TableRange.FromInclusive) {
176+
return false;
177+
}
178+
}
179+
if (auto pathTo = GetCellTo(0); pathTo) {
180+
if (int cmp = pathTo->AsBuf().compare(value); cmp < 0 || cmp == 0 && !TableRange.ToInclusive) {
181+
return false;
182+
}
183+
}
184+
return true;
185+
}
186+
173187
private:
174188
virtual void ProceedToScan() = 0;
175189

ydb/core/sys_view/ut_kqp.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,36 @@ Y_UNIT_TEST_SUITE(SystemView) {
26902690
NKqp::CompareYson(expected, NKqp::StreamResultToYson(it));
26912691
}
26922692

2693+
Y_UNIT_TEST(AuthGroups_TableRange) {
2694+
TTestEnv env;
2695+
SetupAuthEnvironment(env);
2696+
TTableClient client(env.GetDriver());
2697+
2698+
for (auto group : {
2699+
"group1",
2700+
"group2",
2701+
"group3",
2702+
"group4",
2703+
}) {
2704+
env.GetClient().CreateGroup("/Root", group);
2705+
}
2706+
2707+
{
2708+
auto it = client.StreamExecuteScanQuery(R"(
2709+
SELECT Sid
2710+
FROM `Root/.sys/auth_groups`
2711+
WHERE Sid > "group1" AND Sid <= "group3"
2712+
)").GetValueSync();
2713+
2714+
auto expected = R"([
2715+
[["group2"]];
2716+
[["group3"]];
2717+
])";
2718+
2719+
NKqp::CompareYson(expected, NKqp::StreamResultToYson(it));
2720+
}
2721+
}
2722+
26932723
Y_UNIT_TEST(AuthGroupMembers) {
26942724
TTestEnv env;
26952725
SetupAuthEnvironment(env);

0 commit comments

Comments
 (0)