@@ -11,6 +11,110 @@ using namespace NYdb;
11
11
using namespace NYdb ::NTable;
12
12
13
13
Y_UNIT_TEST_SUITE (KqpNewEngine) {
14
+ Y_UNIT_TEST (StreamLookupWithView) {
15
+ TKikimrSettings settings = TKikimrSettings ().SetWithSampleTables (false );
16
+ NKikimrConfig::TAppConfig appConfig;
17
+ appConfig.MutableTableServiceConfig ()->SetIndexAutoChooseMode (NKikimrConfig::TTableServiceConfig_EIndexAutoChooseMode_MAX_USED_PREFIX);
18
+ appConfig.MutableFeatureFlags ()->SetEnableViews (true );
19
+ settings.SetDomainRoot (KikimrDefaultUtDomainRoot);
20
+ settings.SetAppConfig (appConfig);
21
+
22
+ auto kikimr = TKikimrRunner{settings};
23
+ kikimr.GetTestServer ().GetRuntime ()->GetAppData (0 ).FeatureFlags .SetEnableViews (true );
24
+
25
+ auto db = kikimr.GetTableClient ();
26
+ auto session = db.CreateSession ().GetValueSync ().GetSession ();
27
+
28
+ AssertSuccessResult (session.ExecuteSchemeQuery (R"(
29
+ --!syntax_v1
30
+
31
+ CREATE TABLE `object_table`
32
+ (
33
+ object_id utf8,
34
+ role utf8,
35
+ id utf8 not NULL,
36
+ primary key (id)
37
+ );
38
+
39
+ ALTER TABLE `object_table` ADD INDEX `object_id_index` GLOBAL ON (object_id);
40
+ ALTER TABLE `object_table` ADD INDEX `role_index` GLOBAL ON (role);
41
+
42
+ CREATE TABLE `role_table`
43
+ (
44
+ granted_by_role utf8,
45
+ granted_role utf8,
46
+ role_type utf8,
47
+ role utf8,
48
+ id utf8 not NULL,
49
+ primary key (id)
50
+ );
51
+
52
+ ALTER TABLE `role_table` ADD INDEX `granted_by_role_index` GLOBAL ON (granted_by_role);
53
+ ALTER TABLE `role_table` ADD INDEX `granted_role_index` GLOBAL ON (granted_role);
54
+ ALTER TABLE `role_table` ADD INDEX `role_index` GLOBAL ON (role);
55
+
56
+ CREATE TABLE `access_table`
57
+ (
58
+ endpoints utf8,
59
+ name utf8,
60
+ class utf8,
61
+ type utf8,
62
+ id utf8 not NULL,
63
+ primary key (id)
64
+ );
65
+
66
+ ALTER TABLE `access_table` ADD INDEX `endpoints_index` GLOBAL ON (endpoints);
67
+ ALTER TABLE `access_table` ADD INDEX `class_index` GLOBAL ON (class);
68
+ )" ).GetValueSync ());
69
+
70
+ AssertSuccessResult (session.ExecuteSchemeQuery (R"(
71
+ --!syntax_v1
72
+ CREATE VIEW granted_privilege WITH (security_invoker = TRUE) AS
73
+ SELECT DISTINCT
74
+ object_table.object_id AS object_id,
75
+ role_table.granted_role AS granted_role,
76
+ access_table.id AS id,
77
+ role_table.role AS role,
78
+ access_table.`type` AS object_type,
79
+ FROM `/Root/access_table` AS access_table
80
+ INNER JOIN `/Root/object_table` AS object_table ON access_table.id = object_table.object_id
81
+ INNER JOIN `/Root/role_table` AS role_table ON object_table.role = role_table.granted_role
82
+ )" ).GetValueSync ());
83
+
84
+ auto result = session.ExecuteDataQuery (R"(
85
+ UPSERT INTO `access_table` (id, type) VALUES
86
+ ("10", "OPERATION_PRIVILEGE");
87
+ UPSERT INTO `role_table` (id, granted_role, role_type) VALUES
88
+ ("10", "admin", "USER_ROLE");
89
+ UPSERT INTO `object_table` (id, object_id, role) VALUES
90
+ ("10", "10", "admin");
91
+ )" , TTxControl::BeginTx (TTxSettings::SerializableRW ()).CommitTx ()).ExtractValueSync ();
92
+ AssertSuccessResult (result);
93
+
94
+ auto testQueryParams = [&] (TString query, TParams params) {
95
+ auto result = session.ExecuteDataQuery (query, TTxControl::BeginTx (TTxSettings::SerializableRW ()).CommitTx (), params).GetValueSync ();
96
+ AssertSuccessResult (result);
97
+
98
+ Cerr << FormatResultSetYson (result.GetResultSet (0 )) << Endl;
99
+ };
100
+
101
+ auto params = kikimr.GetTableClient ().GetParamsBuilder ()
102
+ .AddParam (" $jp1" ).Utf8 (" admin" ).Build ()
103
+ .AddParam (" $jp2" ).Utf8 (" 10" ).Build ()
104
+ .AddParam (" $jp3" ).Uint64 (2 ).Build ()
105
+ .Build ();
106
+
107
+ testQueryParams (R"(
108
+ --!syntax_v1
109
+ DECLARE $jp1 AS Text;
110
+ DECLARE $jp2 AS Text;
111
+ DECLARE $jp3 AS Uint64;
112
+ select g1_0.id from granted_privilege g1_0 where (
113
+ g1_0.role = 'admin'
114
+ ) and g1_0.role=$jp1 and g1_0.object_type=$jp2 limit $jp3
115
+ )" , params);
116
+ }
117
+
14
118
Y_UNIT_TEST (Select1) {
15
119
auto settings = TKikimrSettings ()
16
120
.SetWithSampleTables (false );
0 commit comments