aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/sql_query.cpp
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-12-03 12:18:51 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-12-03 12:18:51 +0000
commitec1f32f19b8500d88807ecde78f48ad9fb55dc73 (patch)
tree4fcc87ab795c82ea93129912ac4ccfe8d4e64a9c /yql/essentials/sql/v1/sql_query.cpp
parente04e58d6f08f0c4fb5a61c3e9fbdba48475a2c80 (diff)
parent556c8da53b8579d7aceb68fe8fa3513851464a75 (diff)
downloadydb-ec1f32f19b8500d88807ecde78f48ad9fb55dc73.tar.gz
Merge branch 'rightlib' into mergelibs-241203-1217
Diffstat (limited to 'yql/essentials/sql/v1/sql_query.cpp')
-rw-r--r--yql/essentials/sql/v1/sql_query.cpp45
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;
}
}