Skip to content

Commit

Permalink
Add EnablePgSyntax flag (#8765)
Browse files Browse the repository at this point in the history
  • Loading branch information
shnikd authored Sep 5, 2024
1 parent 3848f64 commit a30e3f0
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ydb/core/kqp/compile_service/kqp_compile_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ class TKqpCompileActor : public TActorBootstrapped<TKqpCompileActor> {
.SetIsEnableExternalDataSources(AppData(ctx)->FeatureFlags.GetEnableExternalDataSources())
.SetIsEnablePgConstsToParams(Config->EnablePgConstsToParams)
.SetApplicationName(ApplicationName)
.SetQueryParameters(QueryId.QueryParameterTypes);
.SetQueryParameters(QueryId.QueryParameterTypes)
.SetIsEnablePgSyntax(AppData(ctx)->FeatureFlags.GetEnablePgSyntax());

return ParseStatements(QueryId.Text, QueryId.Settings.Syntax, QueryId.IsSql(), settingsBuilder, PerStatementResult);
}
Expand Down
3 changes: 2 additions & 1 deletion ydb/core/kqp/host/kqp_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,8 @@ class TKqpHost : public IKqpHost {
.SetIsEnableExternalDataSources(SessionCtx->Config().FeatureFlags.GetEnableExternalDataSources())
.SetIsEnablePgConstsToParams(SessionCtx->Config().EnablePgConstsToParams)
.SetQueryParameters(query.ParameterTypes)
.SetApplicationName(ApplicationName);
.SetApplicationName(ApplicationName)
.SetIsEnablePgSyntax(SessionCtx->Config().FeatureFlags.GetEnablePgSyntax());
auto astRes = ParseQuery(query.Text, isSql, sqlVersion, TypesCtx->DeprecatedSQL, ctx, settingsBuilder, result.KeepInCache, result.CommandTagName);
if (astRes.ActualSyntaxType == NYql::ESyntaxType::Pg) {
SessionCtx->Config().IndexAutoChooserMode = NKikimrConfig::TTableServiceConfig_EIndexAutoChooseMode::TTableServiceConfig_EIndexAutoChooseMode_MAX_USED_PREFIX;
Expand Down
1 change: 1 addition & 0 deletions ydb/core/kqp/host/kqp_translate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ NSQLTranslation::TTranslationSettings TKqpTranslationSettingsBuilder::Build(NYql
settings.SaveWorldDependencies = true;
}

settings.PGDisable = !IsEnablePgSyntax;
settings.InferSyntaxVersion = true;
settings.V0ForceDisable = false;
settings.WarnOnV0 = false;
Expand Down
6 changes: 6 additions & 0 deletions ydb/core/kqp/host/kqp_translate.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class TKqpTranslationSettingsBuilder {
return *this;
}

TKqpTranslationSettingsBuilder& SetIsEnablePgSyntax(bool value) {
IsEnablePgSyntax = value;
return *this;
}

private:
const NYql::EKikimrQueryType QueryType;
const ui16 KqpYqlSyntaxVersion;
Expand All @@ -73,6 +78,7 @@ class TKqpTranslationSettingsBuilder {
TString KqpTablePathPrefix = {};
bool IsEnableExternalDataSources = false;
bool IsEnablePgConstsToParams = false;
bool IsEnablePgSyntax = false;
TMaybe<bool> SqlAutoCommit = {};
TGUCSettings::TPtr GUCSettings;
TMaybe<TString> ApplicationName = {};
Expand Down
1 change: 1 addition & 0 deletions ydb/core/kqp/ut/common/kqp_ut_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ TKikimrRunner::TKikimrRunner(const TKikimrSettings& settings) {
ServerSettings->SetEnableUniqConstraint(true);
ServerSettings->SetUseRealThreads(settings.UseRealThreads);
ServerSettings->SetEnableTablePgTypes(true);
ServerSettings->SetEnablePgSyntax(true);
ServerSettings->S3ActorsFactory = settings.S3ActorsFactory;

if (settings.Storage) {
Expand Down
3 changes: 2 additions & 1 deletion ydb/core/kqp/ut/pg/kqp_pg_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4685,7 +4685,8 @@ Y_UNIT_TEST_SUITE(KqpPg) {
ui16 mbusport = tp.GetPort(2134);
auto settings = Tests::TServerSettings(mbusport)
.SetDomainName("Root")
.SetUseRealThreads(false);
.SetUseRealThreads(false)
.SetEnablePgSyntax(true);

Tests::TServer::TPtr server = new Tests::TServer(settings);

Expand Down
1 change: 1 addition & 0 deletions ydb/core/protos/feature_flags.proto
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,5 @@ message TFeatureFlags {
optional bool EnableChangefeedsOnIndexTables = 134 [default = false];
optional bool EnableResourcePoolsCounters = 135 [default = false];
optional bool EnableOptionalColumnsInColumnShard = 136 [default = false];
optional bool EnablePgSyntax = 139 [default = false];
}
1 change: 1 addition & 0 deletions ydb/core/testlib/basics/feature_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class TTestFeatureFlagsHolder {
FEATURE_FLAG_SETTER(EnableTableDatetime64)
FEATURE_FLAG_SETTER(EnableResourcePools)
FEATURE_FLAG_SETTER(EnableChangefeedsOnIndexTables)
FEATURE_FLAG_SETTER(EnablePgSyntax)

#undef FEATURE_FLAG_SETTER
};
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/sql/settings/translation_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace NSQLTranslation {
, InferSyntaxVersion(false)
, V0Behavior(EV0Behavior::Disable)
, V0ForceDisable(InTestEnvironment())
, PGDisable(false)
, WarnOnV0(true)
, V0WarnAsError(ISqlFeaturePolicy::MakeAlwaysDisallow())
, DqDefaultAuto(ISqlFeaturePolicy::MakeAlwaysDisallow())
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/sql/settings/translation_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ namespace NSQLTranslation {
bool InferSyntaxVersion;
EV0Behavior V0Behavior;
bool V0ForceDisable;
bool PGDisable;
bool WarnOnV0;
ISqlFeaturePolicy::TPtr V0WarnAsError;
ISqlFeaturePolicy::TPtr DqDefaultAuto;
Expand Down
12 changes: 12 additions & 0 deletions ydb/library/yql/sql/sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ namespace NSQLTranslation {
return result;
}

if (parsedSettings.PgParser && parsedSettings.PGDisable) {
result.Issues.AddIssue(NYql::YqlIssue(NYql::TPosition(), NYql::TIssuesIds::DEFAULT_ERROR,
"PG syntax is disabled"));
return result;
}

if (parsedSettings.PgParser) {
return NSQLTranslationPG::PGToYql(query, parsedSettings, stmtParseInfo);
}
Expand Down Expand Up @@ -184,6 +190,12 @@ namespace NSQLTranslation {
return {};
}

if (parsedSettings.PgParser && parsedSettings.PGDisable) {
issues.AddIssue(NYql::YqlIssue(NYql::TPosition(), NYql::TIssuesIds::DEFAULT_ERROR,
"PG syntax is disabled"));
return result;
}

if (parsedSettings.PgParser) {
return NSQLTranslationPG::PGToYqlStatements(query, parsedSettings, stmtParseInfo);
}
Expand Down
2 changes: 1 addition & 1 deletion ydb/tests/functional/postgresql/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def setup_class(cls):
'KQP_COMPILE_REQUEST': LogLevels.DEBUG,
'KQP_PROXY': LogLevels.DEBUG
},
extra_feature_flags=['enable_table_pg_types', 'enable_temp_tables'],
extra_feature_flags=['enable_table_pg_types', 'enable_temp_tables', 'enable_pg_syntax'],
pgwire_port=cls.pgport
))
cls.cluster.start()
Expand Down
1 change: 1 addition & 0 deletions ydb/tests/library/harness/kikimr_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ def __init__(
self.yaml_config["table_service_config"]["index_auto_choose_mode"] = 'max_used_prefix'
self.yaml_config["feature_flags"]['enable_temp_tables'] = True
self.yaml_config["feature_flags"]['enable_table_pg_types'] = True
self.yaml_config['feature_flags']['enable_pg_syntax'] = True
self.yaml_config['feature_flags']['enable_uniq_constraint'] = True

# https://github.com/ydb-platform/ydb/issues/5152
Expand Down

0 comments on commit a30e3f0

Please sign in to comment.