Skip to content

Commit

Permalink
Add EnablePgSyntax flag (#8764)
Browse files Browse the repository at this point in the history
  • Loading branch information
shnikd authored Sep 11, 2024
1 parent 8b46f5b commit bea5f8c
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 12 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 @@ -134,8 +134,9 @@ class TKqpCompileActor : public TActorBootstrapped<TKqpCompileActor> {
NSQLTranslation::EBindingsMode bindingsMode = Config->BindingsMode;
bool isEnableExternalDataSources = AppData(ctx)->FeatureFlags.GetEnableExternalDataSources();
bool isEnablePgConstsToParams = Config->EnablePgConstsToParams;
bool isPgSyntaxEnable = AppData(ctx)->FeatureFlags.GetEnablePgSyntax();

auto astResult = ParseQuery(ConvertType(QueryId.Settings.QueryType), QueryId.Settings.Syntax, QueryId.Text, QueryId.QueryParameterTypes, QueryId.IsSql(), cluster, kqpTablePathPrefix, kqpYqlSyntaxVersion, bindingsMode, isEnableExternalDataSources, isEnablePgConstsToParams);
auto astResult = ParseQuery(ConvertType(QueryId.Settings.QueryType), QueryId.Settings.Syntax, QueryId.Text, QueryId.QueryParameterTypes, QueryId.IsSql(), cluster, kqpTablePathPrefix, kqpYqlSyntaxVersion, bindingsMode, isEnableExternalDataSources, isEnablePgConstsToParams, isPgSyntaxEnable);
YQL_ENSURE(astResult.Ast);
if (astResult.Ast->IsOk()) {
AstResult = std::move(astResult);
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 @@ -1102,7 +1102,8 @@ class TKqpHost : public IKqpHost {
query.Text, query.ParameterTypes, isSql, sqlAutoCommit, sqlVersion, TypesCtx->DeprecatedSQL,
Cluster, SessionCtx->Config()._KqpTablePathPrefix.Get().GetRef(),
SessionCtx->Config()._KqpYqlSyntaxVersion.Get().GetRef(), SessionCtx->Config().BindingsMode,
SessionCtx->Config().FeatureFlags.GetEnableExternalDataSources(), ctx, SessionCtx->Config().EnablePgConstsToParams);
SessionCtx->Config().FeatureFlags.GetEnableExternalDataSources(), ctx, SessionCtx->Config().EnablePgConstsToParams,
SessionCtx->Config().FeatureFlags.GetEnablePgSyntax());
queryAst = std::make_shared<NYql::TAstParseResult>(std::move(astRes));
} else {
queryAst = query.AstResult->Ast;
Expand Down
11 changes: 6 additions & 5 deletions ydb/core/kqp/host/kqp_translate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ NYql::EKikimrQueryType ConvertType(NKikimrKqp::EQueryType type) {
NSQLTranslation::TTranslationSettings GetTranslationSettings(NYql::EKikimrQueryType queryType, const TMaybe<bool>& usePgParser, bool sqlAutoCommit,
const TString& queryText, std::shared_ptr<std::map<TString, Ydb::Type>> queryParameters, TMaybe<ui16>& sqlVersion, TString cluster,
TString kqpTablePathPrefix, ui16 kqpYqlSyntaxVersion, NSQLTranslation::EBindingsMode bindingsMode, bool isEnableExternalDataSources,
NYql::TExprContext& ctx, bool isEnablePgConstsToParams) {
NYql::TExprContext& ctx, bool isEnablePgConstsToParams, bool isEnablePgSyntax) {
NSQLTranslation::TTranslationSettings settings{};

if (usePgParser) {
Expand Down Expand Up @@ -89,6 +89,7 @@ NSQLTranslation::TTranslationSettings GetTranslationSettings(NYql::EKikimrQueryT
settings.BindingsMode = bindingsMode;
}

settings.PGDisable = !isEnablePgSyntax;
settings.InferSyntaxVersion = true;
settings.V0ForceDisable = false;
settings.WarnOnV0 = false;
Expand Down Expand Up @@ -148,10 +149,10 @@ NYql::TAstParseResult ParseQuery(NYql::EKikimrQueryType queryType, const TMaybe<
std::shared_ptr<std::map<TString, Ydb::Type>> queryParameters, bool isSql, bool sqlAutoCommit,
TMaybe<ui16>& sqlVersion, bool& deprecatedSQL, TString cluster, TString kqpTablePathPrefix,
ui16 kqpYqlSyntaxVersion, NSQLTranslation::EBindingsMode bindingsMode, bool isEnableExternalDataSources,
NYql::TExprContext& ctx, bool isEnablePgConstsToParams) {
NYql::TExprContext& ctx, bool isEnablePgConstsToParams, bool isEnablePgSyntax) {
NYql::TAstParseResult astRes;
if (isSql) {
auto settings = GetTranslationSettings(queryType, usePgParser, sqlAutoCommit, queryText, queryParameters, sqlVersion, cluster, kqpTablePathPrefix, kqpYqlSyntaxVersion, bindingsMode, isEnableExternalDataSources, ctx, isEnablePgConstsToParams);
auto settings = GetTranslationSettings(queryType, usePgParser, sqlAutoCommit, queryText, queryParameters, sqlVersion, cluster, kqpTablePathPrefix, kqpYqlSyntaxVersion, bindingsMode, isEnableExternalDataSources, ctx, isEnablePgConstsToParams, isEnablePgSyntax);
ui16 actualSyntaxVersion = 0;
auto ast = NSQLTranslation::SqlToYql(queryText, settings, nullptr, &actualSyntaxVersion);
deprecatedSQL = (actualSyntaxVersion == 0);
Expand All @@ -168,7 +169,7 @@ NYql::TAstParseResult ParseQuery(NYql::EKikimrQueryType queryType, const TMaybe<
}

TQueryAst ParseQuery(NYql::EKikimrQueryType queryType, const TMaybe<Ydb::Query::Syntax>& syntax, const TString& queryText, std::shared_ptr<std::map<TString, Ydb::Type>> queryParameters, bool isSql,
TString cluster, TString kqpTablePathPrefix, ui16 kqpYqlSyntaxVersion, NSQLTranslation::EBindingsMode bindingsMode, bool isEnableExternalDataSources, bool isEnablePgConstsToParams) {
TString cluster, TString kqpTablePathPrefix, ui16 kqpYqlSyntaxVersion, NSQLTranslation::EBindingsMode bindingsMode, bool isEnableExternalDataSources, bool isEnablePgConstsToParams, bool isEnablePgSyntax) {
bool deprecatedSQL;
TMaybe<ui16> sqlVersion;
TMaybe<bool> usePgParser;
Expand All @@ -191,7 +192,7 @@ TQueryAst ParseQuery(NYql::EKikimrQueryType queryType, const TMaybe<Ydb::Query::
} else {
sqlAutoCommit = false;
}
auto astRes = ParseQuery(queryType, usePgParser, queryText, queryParameters, isSql, sqlAutoCommit, sqlVersion, deprecatedSQL, cluster, kqpTablePathPrefix, kqpYqlSyntaxVersion, bindingsMode, isEnableExternalDataSources, ctx, isEnablePgConstsToParams);
auto astRes = ParseQuery(queryType, usePgParser, queryText, queryParameters, isSql, sqlAutoCommit, sqlVersion, deprecatedSQL, cluster, kqpTablePathPrefix, kqpYqlSyntaxVersion, bindingsMode, isEnableExternalDataSources, ctx, isEnablePgConstsToParams, isEnablePgSyntax);
return TQueryAst(std::make_shared<NYql::TAstParseResult>(std::move(astRes)), sqlVersion, deprecatedSQL);
}

Expand Down
6 changes: 3 additions & 3 deletions ydb/core/kqp/host/kqp_translate.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ NYql::EKikimrQueryType ConvertType(NKikimrKqp::EQueryType type);
NSQLTranslation::TTranslationSettings GetTranslationSettings(NYql::EKikimrQueryType queryType, const TMaybe<bool>& usePgParser, bool sqlAutoCommit,
const TString& queryText, std::shared_ptr<std::map<TString, Ydb::Type>> queryParameters, TMaybe<ui16>& sqlVersion, TString cluster,
TString kqpTablePathPrefix, ui16 kqpYqlSyntaxVersion, NSQLTranslation::EBindingsMode bindingsMode, bool isEnableExternalDataSources, NYql::TExprContext& ctx,
bool isEnablePgConstsToParams);
bool isEnablePgConstsToParams, bool isEnablePgSyntax);

NYql::TAstParseResult ParseQuery(NYql::EKikimrQueryType queryType, const TMaybe<bool>& usePgParser, const TString& queryText,
std::shared_ptr<std::map<TString, Ydb::Type>> queryParameters, bool isSql, bool sqlAutoCommit, TMaybe<ui16>& sqlVersion,
bool& deprecatedSQL, TString cluster, TString kqpTablePathPrefix, ui16 kqpYqlSyntaxVersion, NSQLTranslation::EBindingsMode bindingsMode,
bool isEnableExternalDataSources, NYql::TExprContext& ctx, bool isEnablePgConstsToParams);
bool isEnableExternalDataSources, NYql::TExprContext& ctx, bool isEnablePgConstsToParams, bool isEnablePgSyntax);

TQueryAst ParseQuery(NYql::EKikimrQueryType queryType, const TMaybe<Ydb::Query::Syntax>& syntax, const TString& queryText,
std::shared_ptr<std::map<TString, Ydb::Type>> queryParameters, bool isSql, TString cluster, TString kqpTablePathPrefix,
ui16 kqpYqlSyntaxVersion, NSQLTranslation::EBindingsMode bindingsMode, bool isEnableExternalDataSources, bool isEnablePgConstsToParams);
ui16 kqpYqlSyntaxVersion, NSQLTranslation::EBindingsMode bindingsMode, bool isEnableExternalDataSources, bool isEnablePgConstsToParams, bool isEnablePgSyntax);

} // namespace NKqp
} // namespace NKikimr
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 @@ -130,6 +130,7 @@ TKikimrRunner::TKikimrRunner(const TKikimrSettings& settings) {
ServerSettings->SetEnableUniqConstraint(true);
ServerSettings->SetUseRealThreads(settings.UseRealThreads);
ServerSettings->SetEnableTablePgTypes(true);
ServerSettings->SetEnablePgSyntax(true);

if (settings.Storage) {
ServerSettings->SetCustomDiskParams(*settings.Storage);
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 @@ -133,4 +133,5 @@ message TFeatureFlags {
optional bool EnableStableNodeNames = 122 [default = false];
optional bool EnableVolatileTransactionArbiters = 124 [default = false];
optional bool EnableChangefeedsOnIndexTables = 134 [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 @@ -60,6 +60,7 @@ class TTestFeatureFlagsHolder {
FEATURE_FLAG_SETTER(EnableReplaceIfExistsForExternalEntities)
FEATURE_FLAG_SETTER(EnableCMSRequestPriorities)
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 @@ -53,6 +53,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 @@ -100,6 +100,7 @@ namespace NSQLTranslation {
bool InferSyntaxVersion;
EV0Behavior V0Behavior;
bool V0ForceDisable;
bool PGDisable;
bool WarnOnV0;
ISqlFeaturePolicy::TPtr V0WarnAsError;
ISqlFeaturePolicy::TPtr DqDefaultAuto;
Expand Down
6 changes: 6 additions & 0 deletions ydb/library/yql/sql/sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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);
}
Expand Down
7 changes: 5 additions & 2 deletions ydb/tests/functional/postgresql/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def setup_class(cls):
'KQP_COMPILE_ACTOR': LogLevels.DEBUG,
'KQP_COMPILE_REQUEST': LogLevels.DEBUG,
'KQP_PROXY': LogLevels.DEBUG
}
},
extra_feature_flags=['enable_pg_syntax']
))
cls.cluster.start()

Expand All @@ -94,7 +95,9 @@ def teardown_class(cls):
class TestPgwireSidecar(object):
@classmethod
def setup_class(cls):
cls.cluster = kikimr_cluster_factory()
cls.cluster = kikimr_cluster_factory(KikimrConfigGenerator(
extra_feature_flags=['enable_pg_syntax']
))
cls.cluster.start()
cls.endpoint = '%s:%s' % (cls.cluster.nodes[1].host, cls.cluster.nodes[1].port)
cls.pgwireListenPort = pm.get_port()
Expand Down

0 comments on commit bea5f8c

Please sign in to comment.