diff options
author | ilnaz <ilnaz@yandex-team.com> | 2024-12-03 13:17:06 +0300 |
---|---|---|
committer | ilnaz <ilnaz@yandex-team.com> | 2024-12-03 13:33:17 +0300 |
commit | 556c8da53b8579d7aceb68fe8fa3513851464a75 (patch) | |
tree | 549beca12e961d2c2fbee142cc6856ae0a22b336 /yql/essentials/sql/v1/sql_query.cpp | |
parent | 6e7f04fb442b3763c07903c984fed7e40dc0dd5f (diff) | |
download | ydb-556c8da53b8579d7aceb68fe8fa3513851464a75.tar.gz |
New options for ASYNC REPLICATION
commit_hash:7ee0e4b59035ed5c8dedc69e00f95457eca65b88
Diffstat (limited to 'yql/essentials/sql/v1/sql_query.cpp')
-rw-r--r-- | yql/essentials/sql/v1/sql_query.cpp | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/yql/essentials/sql/v1/sql_query.cpp b/yql/essentials/sql/v1/sql_query.cpp index 37cd7ea1eb..781e5d7a5f 100644 --- a/yql/essentials/sql/v1/sql_query.cpp +++ b/yql/essentials/sql/v1/sql_query.cpp @@ -45,10 +45,15 @@ void TSqlQuery::AddStatementToBlocks(TVector<TNodePtr>& blocks, TNodePtr node) { } static bool AsyncReplicationSettingsEntry(std::map<TString, TNodePtr>& out, - const TRule_replication_settings_entry& in, TTranslation& ctx, bool create) + const TRule_replication_settings_entry& in, TSqlExpression& ctx, bool create) { auto key = IdEx(in.GetRule_an_id1(), ctx); - auto value = BuildLiteralSmartString(ctx.Context(), ctx.Token(in.GetToken3())); + auto value = ctx.Build(in.GetRule_expr3()); + + if (!value) { + ctx.Context().Error() << "Invalid replication setting: " << key.Name; + return false; + } TSet<TString> configSettings = { "connection_string", @@ -61,13 +66,18 @@ static bool AsyncReplicationSettingsEntry(std::map<TString, TNodePtr>& out, "password_secret_name", }; + TSet<TString> modeSettings = { + "consistency_mode", + "commit_interval", + }; + TSet<TString> stateSettings = { "state", "failover_mode", }; const auto keyName = to_lower(key.Name); - if (!configSettings.count(keyName) && !stateSettings.count(keyName)) { + if (!configSettings.count(keyName) && !modeSettings.count(keyName) && !stateSettings.count(keyName)) { ctx.Context().Error() << "Unknown replication setting: " << key.Name; return false; } @@ -77,6 +87,23 @@ static bool AsyncReplicationSettingsEntry(std::map<TString, TNodePtr>& out, return false; } + if (!create && modeSettings.count(keyName)) { + ctx.Context().Error() << key.Name << " is not supported in ALTER"; + return false; + } + + if (keyName == "commit_interval") { + if (value->GetOpName() != "Interval") { + ctx.Context().Error() << "Literal of Interval type is expected for " << key.Name; + return false; + } + } else { + if (!value->IsLiteral() || value->GetLiteralType() != "String") { + ctx.Context().Error() << "Literal of String type is expected for " << key.Name; + return false; + } + } + if (!out.emplace(keyName, value).second) { ctx.Context().Error() << "Duplicate replication setting: " << key.Name; } @@ -85,7 +112,7 @@ static bool AsyncReplicationSettingsEntry(std::map<TString, TNodePtr>& out, } static bool AsyncReplicationSettings(std::map<TString, TNodePtr>& out, - const TRule_replication_settings& in, TTranslation& ctx, bool create) + const TRule_replication_settings& in, TSqlExpression& ctx, bool create) { if (!AsyncReplicationSettingsEntry(out, in.GetRule_replication_settings_entry1(), ctx, create)) { return false; @@ -110,7 +137,7 @@ static bool AsyncReplicationTarget(std::vector<std::pair<TString, TString>>& out } static bool AsyncReplicationAlterAction(std::map<TString, TNodePtr>& settings, - const TRule_alter_replication_action& in, TTranslation& ctx) + const TRule_alter_replication_action& in, TSqlExpression& ctx) { // TODO(ilnaz): support other actions return AsyncReplicationSettings(settings, in.GetRule_alter_replication_set_setting1().GetRule_replication_settings3(), ctx, false); @@ -982,7 +1009,8 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& } std::map<TString, TNodePtr> settings; - if (!AsyncReplicationSettings(settings, node.GetRule_replication_settings10(), *this, true)) { + TSqlExpression expr(Ctx, Mode); + if (!AsyncReplicationSettings(settings, node.GetRule_replication_settings10(), expr, true)) { return false; } @@ -1302,11 +1330,12 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& } std::map<TString, TNodePtr> settings; - if (!AsyncReplicationAlterAction(settings, node.GetRule_alter_replication_action5(), *this)) { + TSqlExpression expr(Ctx, Mode); + if (!AsyncReplicationAlterAction(settings, node.GetRule_alter_replication_action5(), expr)) { return false; } for (auto& block : node.GetBlock6()) { - if (!AsyncReplicationAlterAction(settings, block.GetRule_alter_replication_action2(), *this)) { + if (!AsyncReplicationAlterAction(settings, block.GetRule_alter_replication_action2(), expr)) { return false; } } |