Skip to content

Commit 8c6c176

Browse files
authored
[Stable-25-1] EnableTempTables flag (#22604)
2 parents 276f8c9 + c736ffe commit 8c6c176

File tree

12 files changed

+89
-50
lines changed

12 files changed

+89
-50
lines changed

ydb/core/kqp/compile_service/kqp_compile_actor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ void ApplyServiceConfig(TKikimrConfiguration& kqpConfig, const TTableServiceConf
656656
kqpConfig.EnableSpillingInHashJoinShuffleConnections = serviceConfig.GetEnableSpillingInHashJoinShuffleConnections();
657657
kqpConfig.EnableOlapScalarApply = serviceConfig.GetEnableOlapScalarApply();
658658
kqpConfig.EnableOlapSubstringPushdown = serviceConfig.GetEnableOlapSubstringPushdown();
659+
kqpConfig.EnableTempTablesForUser = serviceConfig.GetEnableTempTablesForUser();
659660

660661
if (const auto limit = serviceConfig.GetResourceManager().GetMkqlHeavyProgramMemoryLimit()) {
661662
kqpConfig._KqpYqlCombinerMemoryLimit = std::max(1_GB, limit - (limit >> 2U));

ydb/core/kqp/compile_service/kqp_compile_service.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
322322
bool enableOlapScalarApply = TableServiceConfig.GetEnableOlapScalarApply();
323323
bool enableOlapSubstringPushdown = TableServiceConfig.GetEnableOlapSubstringPushdown();
324324

325+
bool enableTempTablesForUser = TableServiceConfig.GetEnableTempTablesForUser();
326+
325327
TableServiceConfig.Swap(event.MutableConfig()->MutableTableServiceConfig());
326328
LOG_INFO(*TlsActivationContext, NKikimrServices::KQP_COMPILE_SERVICE, "Updated config");
327329

@@ -357,7 +359,8 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
357359
TableServiceConfig.GetDefaultEnableShuffleElimination() != defaultEnableShuffleElimination ||
358360
TableServiceConfig.GetEnableSpillingInHashJoinShuffleConnections() != enableSpillingInHashJoinShuffleConnections ||
359361
TableServiceConfig.GetEnableOlapScalarApply() != enableOlapScalarApply ||
360-
TableServiceConfig.GetEnableOlapSubstringPushdown() != enableOlapSubstringPushdown
362+
TableServiceConfig.GetEnableOlapSubstringPushdown() != enableOlapSubstringPushdown ||
363+
TableServiceConfig.GetEnableTempTablesForUser() != enableTempTablesForUser
361364
)
362365
{
363366

ydb/core/kqp/host/kqp_statement_rewrite.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ namespace {
245245
}
246246
settingsNodes.push_back(
247247
exprCtx.NewList(pos, {exprCtx.NewAtom(pos, "temporary")}));
248+
settingsNodes.push_back(
249+
exprCtx.NewList(pos, {exprCtx.NewAtom(pos, "ctas")}));
248250
create = exprCtx.ReplaceNode(std::move(create), *create->Child(4), exprCtx.NewList(pos, std::move(settingsNodes)));
249251
create = exprCtx.ReplaceNode(std::move(create), *tableNameNode, exprCtx.NewAtom(pos, tmpTableName));
250252

ydb/core/kqp/provider/yql_kikimr_datasink.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,11 @@ class TKikimrDataSink : public TDataProviderBase
879879
? settings.Temporary.Cast()
880880
: Build<TCoAtom>(ctx, node->Pos()).Value("false").Done();
881881

882+
if (temporary.Value() == "true") {
883+
ctx.AddError(TIssue(ctx.GetPosition(node->Pos()), "Creating temporary sequence data is not supported."));
884+
return nullptr;
885+
}
886+
882887
auto existringOk = (settings.Mode.Cast().Value() == "create_if_not_exists");
883888

884889
return Build<TKiCreateSequence>(ctx, node->Pos())
@@ -1269,6 +1274,24 @@ class TKikimrDataSink : public TDataProviderBase
12691274
auto temporary = settings.Temporary.IsValid()
12701275
? settings.Temporary.Cast()
12711276
: Build<TCoAtom>(ctx, node->Pos()).Value("false").Done();
1277+
1278+
const bool isCreateTableAs = std::any_of(
1279+
settings.Other.Ptr()->Children().begin(),
1280+
settings.Other.Ptr()->Children().end(),
1281+
[&](const TExprNode::TPtr& child) {
1282+
NYql::NNodes::TExprBase expr(child);
1283+
if (auto maybeTuple = expr.Maybe<TCoNameValueTuple>()) {
1284+
const auto tuple = maybeTuple.Cast();
1285+
const auto name = tuple.Name().Value();
1286+
return name == "ctas";
1287+
}
1288+
return false;
1289+
});
1290+
1291+
if (temporary.Value() == "true" && !SessionCtx->Config().EnableTempTablesForUser && !isCreateTableAs) {
1292+
ctx.AddError(TIssue(ctx.GetPosition(node->Pos()), "Creating temporary table is not supported."));
1293+
return nullptr;
1294+
}
12721295

12731296
auto replaceIfExists = (settings.Mode.Cast().Value() == "create_or_replace");
12741297
auto existringOk = (settings.Mode.Cast().Value() == "create_if_not_exists");

ydb/core/kqp/provider/yql_kikimr_settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ struct TKikimrConfiguration : public TKikimrSettings, public NCommon::TSettingDi
197197
bool EnableSpillingInHashJoinShuffleConnections = false;
198198
bool EnableOlapScalarApply = false;
199199
bool EnableOlapSubstringPushdown = false;
200+
bool EnableTempTablesForUser = false;
200201

201202
NDq::EHashShuffleFuncType DefaultHashShuffleFuncType = NDq::EHashShuffleFuncType::HashV1;
202203
NDq::EHashShuffleFuncType DefaultColumnShardHashShuffleFuncType = NDq::EHashShuffleFuncType::ColumnShardHashV1;

ydb/core/kqp/session_actor/kqp_session_actor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,6 @@ class TKqpSessionActor : public TActorBootstrapped<TKqpSessionActor> {
13741374
}
13751375

13761376
SendToSchemeExecuter(tx);
1377-
++QueryState->CurrentTx;
13781377
return false;
13791378

13801379
case NKqpProto::TKqpPhyTx::TYPE_DATA:
@@ -1541,6 +1540,8 @@ class TKqpSessionActor : public TActorBootstrapped<TKqpSessionActor> {
15411540
temporary, TempTablesState.SessionId, QueryState->UserRequestContext, KqpTempTablesAgentActor);
15421541

15431542
ExecuterId = RegisterWithSameMailbox(executerActor);
1543+
1544+
++QueryState->CurrentTx;
15441545
}
15451546

15461547
static ui32 GetResultsCount(const IKqpGateway::TExecPhysicalRequest& req) {

ydb/core/kqp/ut/pg/kqp_pg_ut.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,11 +2282,9 @@ Y_UNIT_TEST_SUITE(KqpPg) {
22822282
}
22832283

22842284
Y_UNIT_TEST(CreateTempTable) {
2285-
NKikimrConfig::TAppConfig appConfig;
22862285
auto setting = NKikimrKqp::TKqpSetting();
2287-
auto serverSettings = TKikimrSettings()
2288-
.SetAppConfig(appConfig)
2289-
.SetKqpSettings({setting});
2286+
auto serverSettings = TKikimrSettings().SetKqpSettings({setting});
2287+
serverSettings.AppConfig.MutableTableServiceConfig()->SetEnableTempTablesForUser(true);
22902288
TKikimrRunner kikimr(
22912289
serverSettings.SetWithSampleTables(false).SetEnableTempTables(true));
22922290
auto clientConfig = NGRpcProxy::TGRpcClientConfig(kikimr.GetEndpoint());
@@ -2332,11 +2330,9 @@ Y_UNIT_TEST_SUITE(KqpPg) {
23322330
}
23332331

23342332
Y_UNIT_TEST(CreateTempTableSerial) {
2335-
NKikimrConfig::TAppConfig appConfig;
23362333
auto setting = NKikimrKqp::TKqpSetting();
2337-
auto serverSettings = TKikimrSettings()
2338-
.SetAppConfig(appConfig)
2339-
.SetKqpSettings({setting});
2334+
auto serverSettings = TKikimrSettings().SetKqpSettings({setting});
2335+
serverSettings.AppConfig.MutableTableServiceConfig()->SetEnableTempTablesForUser(true);
23402336
TKikimrRunner kikimr(
23412337
serverSettings.SetWithSampleTables(false).SetEnableTempTables(true));
23422338
auto clientConfig = NGRpcProxy::TGRpcClientConfig(kikimr.GetEndpoint());
@@ -3001,11 +2997,9 @@ Y_UNIT_TEST_SUITE(KqpPg) {
30012997
}
30022998

30032999
Y_UNIT_TEST(TempTablesSessionsIsolation) {
3004-
NKikimrConfig::TAppConfig appConfig;
30053000
auto setting = NKikimrKqp::TKqpSetting();
3006-
auto serverSettings = TKikimrSettings()
3007-
.SetAppConfig(appConfig)
3008-
.SetKqpSettings({setting});
3001+
auto serverSettings = TKikimrSettings().SetKqpSettings({setting});
3002+
serverSettings.AppConfig.MutableTableServiceConfig()->SetEnableTempTablesForUser(true);
30093003
TKikimrRunner kikimr(
30103004
serverSettings.SetWithSampleTables(false).SetEnableTempTables(true));
30113005
auto clientConfig = NGRpcProxy::TGRpcClientConfig(kikimr.GetEndpoint());
@@ -3052,11 +3046,9 @@ Y_UNIT_TEST_SUITE(KqpPg) {
30523046
}
30533047

30543048
Y_UNIT_TEST(TempTablesDrop) {
3055-
NKikimrConfig::TAppConfig appConfig;
30563049
auto setting = NKikimrKqp::TKqpSetting();
3057-
auto serverSettings = TKikimrSettings()
3058-
.SetAppConfig(appConfig)
3059-
.SetKqpSettings({setting});
3050+
auto serverSettings = TKikimrSettings().SetKqpSettings({setting});
3051+
serverSettings.AppConfig.MutableTableServiceConfig()->SetEnableTempTablesForUser(true);
30603052
TKikimrRunner kikimr(
30613053
serverSettings.SetWithSampleTables(false).SetEnableTempTables(true));
30623054
auto clientConfig = NGRpcProxy::TGRpcClientConfig(kikimr.GetEndpoint());
@@ -3127,11 +3119,9 @@ Y_UNIT_TEST_SUITE(KqpPg) {
31273119
}
31283120

31293121
Y_UNIT_TEST(TempTablesWithCache) {
3130-
NKikimrConfig::TAppConfig appConfig;
31313122
auto setting = NKikimrKqp::TKqpSetting();
3132-
auto serverSettings = TKikimrSettings()
3133-
.SetAppConfig(appConfig)
3134-
.SetKqpSettings({setting});
3123+
auto serverSettings = TKikimrSettings().SetKqpSettings({setting});
3124+
serverSettings.AppConfig.MutableTableServiceConfig()->SetEnableTempTablesForUser(true);
31353125
TKikimrRunner kikimr(
31363126
serverSettings.SetWithSampleTables(false).SetEnableTempTables(true));
31373127
auto clientConfig = NGRpcProxy::TGRpcClientConfig(kikimr.GetEndpoint());

ydb/core/kqp/ut/query/kqp_query_ut.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,14 +1438,11 @@ Y_UNIT_TEST_SUITE(KqpQuery) {
14381438
}
14391439

14401440
Y_UNIT_TEST(OlapTemporary) {
1441-
NKikimrConfig::TAppConfig appConfig;
1442-
appConfig.MutableTableServiceConfig()->SetEnableOlapSink(true);
1443-
appConfig.MutableTableServiceConfig()->SetEnableCreateTableAs(true);
1444-
appConfig.MutableTableServiceConfig()->SetEnablePerStatementQueryExecution(true);
1445-
auto settings = TKikimrSettings()
1446-
.SetAppConfig(appConfig)
1447-
.SetEnableTempTables(true)
1448-
.SetWithSampleTables(false);
1441+
auto settings = TKikimrSettings().SetEnableTempTables(true).SetWithSampleTables(false);
1442+
settings.AppConfig.MutableTableServiceConfig()->SetEnableTempTablesForUser(true);
1443+
settings.AppConfig.MutableTableServiceConfig()->SetEnableOlapSink(true);
1444+
settings.AppConfig.MutableTableServiceConfig()->SetEnableCreateTableAs(true);
1445+
settings.AppConfig.MutableTableServiceConfig()->SetEnablePerStatementQueryExecution(true);
14491446
TKikimrRunner kikimr(settings);
14501447

14511448
auto client = kikimr.GetQueryClient();

ydb/core/kqp/ut/scheme/kqp_acl_ut.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -703,13 +703,10 @@ Y_UNIT_TEST_SUITE(KqpAcl) {
703703
}
704704

705705
Y_UNIT_TEST_QUAD(AclTemporary, IsOlap, UseAdmin) {
706-
NKikimrConfig::TAppConfig appConfig;
707-
appConfig.MutableTableServiceConfig()->SetEnableOltpSink(true);
708-
appConfig.MutableTableServiceConfig()->SetEnableOlapSink(true);
709-
auto settings = NKqp::TKikimrSettings()
710-
.SetAppConfig(appConfig)
711-
.SetWithSampleTables(false)
712-
.SetEnableTempTables(true);
706+
auto settings = NKqp::TKikimrSettings().SetWithSampleTables(false).SetEnableTempTables(true);
707+
settings.AppConfig.MutableTableServiceConfig()->SetEnableOltpSink(true);
708+
settings.AppConfig.MutableTableServiceConfig()->SetEnableOlapSink(true);
709+
settings.AppConfig.MutableTableServiceConfig()->SetEnableTempTablesForUser(true);
713710
TKikimrRunner kikimr(settings);
714711
if (UseAdmin) {
715712
kikimr.GetTestClient().GrantConnect("user_write@builtin");

ydb/core/kqp/ut/service/kqp_qs_queries_ut.cpp

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,12 +1900,9 @@ Y_UNIT_TEST_SUITE(KqpQueryService) {
19001900
}
19011901

19021902
Y_UNIT_TEST(CreateTempTable) {
1903-
NKikimrConfig::TAppConfig appConfig;
19041903
auto setting = NKikimrKqp::TKqpSetting();
1905-
auto serverSettings = TKikimrSettings()
1906-
.SetAppConfig(appConfig)
1907-
.SetKqpSettings({setting})
1908-
.SetAuthToken("user0@builtin");
1904+
auto serverSettings = TKikimrSettings().SetKqpSettings({setting}).SetAuthToken("user0@builtin");
1905+
serverSettings.AppConfig.MutableTableServiceConfig()->SetEnableTempTablesForUser(true);
19091906
TKikimrRunner kikimr(
19101907
serverSettings.SetWithSampleTables(false).SetEnableTempTables(true));
19111908
auto clientConfig = NGRpcProxy::TGRpcClientConfig(kikimr.GetEndpoint());
@@ -1980,12 +1977,38 @@ Y_UNIT_TEST_SUITE(KqpQueryService) {
19801977
}
19811978
}
19821979

1980+
Y_UNIT_TEST(CreateTempTableDisabled) {
1981+
auto setting = NKikimrKqp::TKqpSetting();
1982+
auto serverSettings = TKikimrSettings().SetKqpSettings({setting}).SetAuthToken("user0@builtin");
1983+
serverSettings.AppConfig.MutableTableServiceConfig()->SetEnableTempTablesForUser(false);
1984+
TKikimrRunner kikimr(
1985+
serverSettings.SetWithSampleTables(false).SetEnableTempTables(true));
1986+
auto clientConfig = NGRpcProxy::TGRpcClientConfig(kikimr.GetEndpoint());
1987+
auto client = kikimr.GetQueryClient();
1988+
1989+
TString SessionId;
1990+
{
1991+
auto session = client.GetSession().GetValueSync().GetSession();
1992+
auto id = session.GetId();
1993+
1994+
const auto queryCreate = Q_(R"(
1995+
--!syntax_v1
1996+
CREATE TEMP TABLE Temp (
1997+
Key Uint64 NOT NULL,
1998+
Value String,
1999+
PRIMARY KEY (Key)
2000+
);)");
2001+
2002+
auto resultCreate = session.ExecuteQuery(queryCreate, NYdb::NQuery::TTxControl::NoTx()).ExtractValueSync();
2003+
UNIT_ASSERT_VALUES_EQUAL_C(resultCreate.GetStatus(), NYdb::EStatus::GENERIC_ERROR, resultCreate.GetIssues().ToString());
2004+
UNIT_ASSERT_STRING_CONTAINS_C(resultCreate.GetIssues().ToString(), "Creating temporary table is not supported", resultCreate.GetIssues().ToString());
2005+
}
2006+
}
2007+
19832008
Y_UNIT_TEST(AlterTempTable) {
1984-
NKikimrConfig::TAppConfig appConfig;
19852009
auto setting = NKikimrKqp::TKqpSetting();
1986-
auto serverSettings = TKikimrSettings()
1987-
.SetAppConfig(appConfig)
1988-
.SetKqpSettings({setting});
2010+
auto serverSettings = TKikimrSettings().SetKqpSettings({setting});
2011+
serverSettings.AppConfig.MutableTableServiceConfig()->SetEnableTempTablesForUser(true);
19892012
TKikimrRunner kikimr(
19902013
serverSettings.SetWithSampleTables(false).SetEnableTempTables(true));
19912014
auto clientConfig = NGRpcProxy::TGRpcClientConfig(kikimr.GetEndpoint());
@@ -2143,11 +2166,9 @@ Y_UNIT_TEST_SUITE(KqpQueryService) {
21432166
}
21442167

21452168
Y_UNIT_TEST(TempTablesDrop) {
2146-
NKikimrConfig::TAppConfig appConfig;
21472169
auto setting = NKikimrKqp::TKqpSetting();
2148-
auto serverSettings = TKikimrSettings()
2149-
.SetAppConfig(appConfig)
2150-
.SetKqpSettings({setting});
2170+
auto serverSettings = TKikimrSettings().SetKqpSettings({setting});
2171+
serverSettings.AppConfig.MutableTableServiceConfig()->SetEnableTempTablesForUser(true);
21512172
TKikimrRunner kikimr(
21522173
serverSettings.SetWithSampleTables(false).SetEnableTempTables(true));
21532174
auto clientConfig = NGRpcProxy::TGRpcClientConfig(kikimr.GetEndpoint());

0 commit comments

Comments
 (0)