Skip to content

Commit fdd2ace

Browse files
committed
Through human-readable error in case of a missing WITH (security_invoker = true)
First version just to check if other project's tests fail.
1 parent 6ee3d1c commit fdd2ace

File tree

5 files changed

+60
-15
lines changed

5 files changed

+60
-15
lines changed

ydb/core/kqp/ut/view/view_ut.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,28 @@ Y_UNIT_TEST_SUITE(TCreateAndDropViewTest) {
194194
UNIT_ASSERT_STRING_CONTAINS(creationResult.GetIssues().ToString(), "Error: Cannot divide type String and String");
195195
}
196196

197+
Y_UNIT_TEST(UnspecifiedSecurityInvoker) {
198+
TKikimrRunner kikimr(TKikimrSettings().SetWithSampleTables(false));
199+
EnableViewsFeatureFlag(kikimr);
200+
auto session = kikimr.GetTableClient().CreateSession().GetValueSync().GetSession();
201+
202+
constexpr const char* path = "/Root/TheView";
203+
constexpr const char* queryInView = "SELECT 1";
204+
205+
const TString creationQuery = std::format(R"(
206+
CREATE VIEW `{}` AS {};
207+
)",
208+
path,
209+
queryInView
210+
);
211+
212+
const auto creationResult = session.ExecuteSchemeQuery(creationQuery).ExtractValueSync();
213+
UNIT_ASSERT(!creationResult.IsSuccess());
214+
UNIT_ASSERT_STRING_CONTAINS(
215+
creationResult.GetIssues().ToString(), "SECURITY_INVOKER option must be explicitly enabled"
216+
);
217+
}
218+
197219
Y_UNIT_TEST(ListCreatedView) {
198220
TKikimrRunner kikimr(TKikimrSettings().SetWithSampleTables(false));
199221
EnableViewsFeatureFlag(kikimr);

ydb/library/yql/sql/v1/SQLv1.g.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ alter_external_data_source_action:
600600
drop_external_data_source_stmt: DROP EXTERNAL DATA SOURCE (IF EXISTS)? object_ref;
601601

602602
create_view_stmt: CREATE VIEW object_ref
603-
with_table_settings
603+
create_object_features?
604604
AS select_stmt
605605
;
606606

@@ -628,7 +628,7 @@ drop_object_stmt: DROP OBJECT (IF EXISTS)? object_ref
628628
;
629629
drop_object_features: WITH object_features;
630630

631-
object_feature_value: id_or_type | bind_parameter | STRING_VALUE;
631+
object_feature_value: id_or_type | bind_parameter | STRING_VALUE | bool_value;
632632
object_feature_kv: an_id_or_type EQUALS object_feature_value;
633633
object_feature_flag: an_id_or_type;
634634
object_feature: object_feature_kv | object_feature_flag;
@@ -750,11 +750,11 @@ local_index: LOCAL;
750750

751751
index_subtype: an_id;
752752

753-
with_index_settings: WITH LPAREN index_setting_entry (COMMA index_setting_entry)* COMMA? RPAREN;
753+
with_index_settings: WITH LPAREN index_setting_entry (COMMA index_setting_entry)* COMMA? RPAREN;
754754
index_setting_entry: an_id EQUALS index_setting_value;
755755
index_setting_value:
756756
id_or_type
757-
| STRING_VALUE
757+
| STRING_VALUE
758758
| integer
759759
| bool_value
760760
;

ydb/library/yql/sql/v1/SQLv1Antlr4.g.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ alter_external_data_source_action:
599599
drop_external_data_source_stmt: DROP EXTERNAL DATA SOURCE (IF EXISTS)? object_ref;
600600

601601
create_view_stmt: CREATE VIEW object_ref
602-
with_table_settings
602+
create_object_features?
603603
AS select_stmt
604604
;
605605

@@ -627,7 +627,7 @@ drop_object_stmt: DROP OBJECT (IF EXISTS)? object_ref
627627
;
628628
drop_object_features: WITH object_features;
629629

630-
object_feature_value: id_or_type | bind_parameter | STRING_VALUE;
630+
object_feature_value: id_or_type | bind_parameter | STRING_VALUE | bool_value;
631631
object_feature_kv: an_id_or_type EQUALS object_feature_value;
632632
object_feature_flag: an_id_or_type;
633633
object_feature: object_feature_kv | object_feature_flag;
@@ -749,11 +749,11 @@ local_index: LOCAL;
749749

750750
index_subtype: an_id;
751751

752-
with_index_settings: WITH LPAREN index_setting_entry (COMMA index_setting_entry)* COMMA? RPAREN;
752+
with_index_settings: WITH LPAREN index_setting_entry (COMMA index_setting_entry)* COMMA? RPAREN;
753753
index_setting_entry: an_id EQUALS index_setting_value;
754754
index_setting_value:
755755
id_or_type
756-
| STRING_VALUE
756+
| STRING_VALUE
757757
| integer
758758
| bool_value
759759
;

ydb/library/yql/sql/v1/sql_query.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
220220
if (rule.HasBlock2()) { // OR REPLACE
221221
replaceIfExists = true;
222222
Y_DEBUG_ABORT_UNLESS(
223-
(IS_TOKEN(rule.GetBlock2().GetToken1().GetId(), OR) &&
223+
(IS_TOKEN(rule.GetBlock2().GetToken1().GetId(), OR) &&
224224
IS_TOKEN(rule.GetBlock2().GetToken2().GetId(), REPLACE))
225225
);
226226
}
@@ -1239,7 +1239,21 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
12391239
}
12401240

12411241
std::map<TString, TDeferredAtom> features;
1242-
ParseViewOptions(features, node.GetRule_with_table_settings4());
1242+
/*
1243+
if (node.HasBlock4()) {
1244+
ParseViewOptions(features, node.GetBlock4().GetRule_with_table_settings1());
1245+
}
1246+
*/
1247+
if (node.HasBlock4()) {
1248+
if (!ParseObjectFeatures(features, node.GetBlock4().GetRule_create_object_features1().GetRule_object_features2())) {
1249+
return false;
1250+
}
1251+
}
1252+
if (const auto securityInvoker = features.find("security_invoker");
1253+
securityInvoker == features.end() || securityInvoker->second.Build()->GetLiteralValue() != "true") {
1254+
Ctx.Error(Ctx.Pos()) << "SECURITY_INVOKER option must be explicitly enabled";
1255+
return false;
1256+
}
12431257
ParseViewQuery(features, node.GetRule_select_stmt6());
12441258

12451259
const TString objectId = Id(node.GetRule_object_ref3().GetRule_id_or_at2(), *this).second;
@@ -1465,7 +1479,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
14651479

14661480
TVector<TString> columns;
14671481
if (analyzeTable.HasBlock2()) {
1468-
auto columnsNode =
1482+
auto columnsNode =
14691483
analyzeTable.GetBlock2().GetRule_column_list2();
14701484

14711485
if (columnsNode.HasRule_column_name1()) {

ydb/library/yql/sql/v1/sql_translation.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,8 @@ std::tuple<bool, bool, TString> TSqlTranslation::GetIndexSettingValue(const TRul
785785
return {true, value, stringValue};
786786
}
787787

788-
bool TSqlTranslation::CreateIndexSettingEntry(const TIdentifier &id,
789-
const TRule_index_setting_value& node,
788+
bool TSqlTranslation::CreateIndexSettingEntry(const TIdentifier &id,
789+
const TRule_index_setting_value& node,
790790
TIndexDescription::EType indexType,
791791
TIndexDescription::TIndexSettings& indexSettings) {
792792

@@ -4632,6 +4632,12 @@ bool TSqlTranslation::ObjectFeatureValueClause(const TRule_object_feature_value&
46324632
result = TDeferredAtom(Ctx.Pos(), strValue->Content);
46334633
break;
46344634
}
4635+
case TRule_object_feature_value::kAltObjectFeatureValue4:
4636+
{
4637+
TString value = to_lower(Ctx.Token(node.GetAlt_object_feature_value4().GetRule_bool_value1().GetToken1()));
4638+
result = TDeferredAtom(BuildLiteralBool(Ctx.Pos(), FromString<bool>(value)), Ctx);
4639+
break;
4640+
}
46354641
case TRule_object_feature_value::ALT_NOT_SET:
46364642
Y_ABORT("You should change implementation according to grammar changes");
46374643
}
@@ -4641,15 +4647,18 @@ bool TSqlTranslation::ObjectFeatureValueClause(const TRule_object_feature_value&
46414647
bool TSqlTranslation::AddObjectFeature(std::map<TString, TDeferredAtom>& result, const TRule_object_feature& feature) {
46424648
if (feature.has_alt_object_feature1()) {
46434649
auto& kv = feature.GetAlt_object_feature1().GetRule_object_feature_kv1();
4644-
const TString& key = Id(kv.GetRule_an_id_or_type1(), *this);
4650+
const TString key = to_lower(Id(kv.GetRule_an_id_or_type1(), *this));
46454651
auto& ruleValue = kv.GetRule_object_feature_value3();
46464652
TDeferredAtom value;
46474653
if (!ObjectFeatureValueClause(ruleValue, value)) {
46484654
return false;
46494655
}
46504656
result[key] = value;
46514657
} else if (feature.has_alt_object_feature2()) {
4652-
result[Id(feature.GetAlt_object_feature2().GetRule_object_feature_flag1().GetRule_an_id_or_type1(), *this)] = TDeferredAtom();
4658+
const TString key = to_lower(Id(
4659+
feature.GetAlt_object_feature2().GetRule_object_feature_flag1().GetRule_an_id_or_type1(), *this
4660+
));
4661+
result[key] = TDeferredAtom();
46534662
}
46544663
return true;
46554664
}

0 commit comments

Comments
 (0)