@@ -76,7 +76,7 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
76
76
TKqpSchemeExecuter (
77
77
TKqpPhyTxHolder::TConstPtr phyTx, NKikimrKqp::EQueryType queryType, const TActorId& target, const TMaybe<TString>& requestType,
78
78
const TString& database, TIntrusiveConstPtr<NACLib::TUserToken> userToken, const TString& clientAddress,
79
- bool temporary, bool isCreateTableAs, TString sessionId , TIntrusivePtr<TUserRequestContext> ctx,
79
+ bool temporary, bool createTmpDir, bool isCreateTableAs, TString tempDirName , TIntrusivePtr<TUserRequestContext> ctx,
80
80
const TActorId& kqpTempTablesAgentActor)
81
81
: PhyTx(phyTx)
82
82
, QueryType(queryType)
@@ -85,8 +85,9 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
85
85
, UserToken(userToken)
86
86
, ClientAddress(clientAddress)
87
87
, Temporary(temporary)
88
+ , CreateTmpDir(createTmpDir)
88
89
, IsCreateTableAs(isCreateTableAs)
89
- , SessionId(sessionId )
90
+ , TempDirName(tempDirName )
90
91
, RequestContext(std::move(ctx))
91
92
, RequestType(requestType)
92
93
, KqpTempTablesAgentActor(kqpTempTablesAgentActor)
@@ -153,9 +154,10 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
153
154
modifyScheme->SetWorkingDir (GetSessionDirsBasePath (Database));
154
155
modifyScheme->SetOperationType (NKikimrSchemeOp::EOperationType::ESchemeOpMkDir);
155
156
modifyScheme->SetAllowCreateInTempDir (false );
157
+ modifyScheme->SetFailOnExist (true );
156
158
157
159
auto * makeDir = modifyScheme->MutableMkDir ();
158
- makeDir->SetName (SessionId );
160
+ makeDir->SetName (TempDirName );
159
161
ActorIdToProto (KqpTempTablesAgentActor, modifyScheme->MutableTempDirOwnerActorId ());
160
162
161
163
if (UserToken) {
@@ -327,11 +329,12 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
327
329
switch (schemeOp.GetOperationCase ()) {
328
330
case NKqpProto::TKqpSchemeOperation::kCreateTable : {
329
331
auto modifyScheme = schemeOp.GetCreateTable ();
332
+ AFL_ENSURE (!IsCreateTableAs || Temporary);
330
333
if (Temporary) {
331
334
auto changePath = [this ](NKikimrSchemeOp::TTableDescription* tableDesc) {
332
335
const auto fullPath = JoinPath ({tableDesc->GetPath (), tableDesc->GetName ()});
333
336
YQL_ENSURE (fullPath.size () > 1 );
334
- tableDesc->SetName (GetCreateTempTablePath (Database, SessionId , fullPath));
337
+ tableDesc->SetName (GetCreateTempTablePath (Database, TempDirName , fullPath));
335
338
tableDesc->SetPath (Database);
336
339
};
337
340
@@ -346,7 +349,7 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
346
349
}
347
350
case NKikimrSchemeOp::ESchemeOpCreateColumnTable: {
348
351
modifyScheme.MutableCreateColumnTable ()->SetName (
349
- GetCreateTempTablePath (Database, SessionId , modifyScheme.GetCreateColumnTable ().GetName ()));
352
+ GetCreateTempTablePath (Database, TempDirName , modifyScheme.GetCreateColumnTable ().GetName ()));
350
353
break ;
351
354
}
352
355
default :
@@ -367,6 +370,7 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
367
370
368
371
case NKqpProto::TKqpSchemeOperation::kAlterTable : {
369
372
const auto & modifyScheme = schemeOp.GetAlterTable ();
373
+ AFL_ENSURE (!IsCreateTableAs || modifyScheme.GetOperationType () == NKikimrSchemeOp::ESchemeOpMoveTable);
370
374
ev->Record .MutableTransaction ()->MutableModifyScheme ()->CopyFrom (modifyScheme);
371
375
break ;
372
376
}
@@ -741,7 +745,8 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
741
745
} else if (IsCreateTableAs && schemeOp.GetOperationCase () == NKqpProto::TKqpSchemeOperation::kAlterTable ) {
742
746
FindWorkingDirForCTAS ();
743
747
} else {
744
- if (Temporary) {
748
+ if (CreateTmpDir) {
749
+ AFL_ENSURE (Temporary);
745
750
CreateTmpDirectory ();
746
751
} else {
747
752
MakeSchemeOperationRequest ();
@@ -800,7 +805,7 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
800
805
void Handle (TEvPrivate::TEvMakeSessionDirResult::TPtr& result) {
801
806
if (!result->Get ()->Result .Success ()) {
802
807
InternalError (TStringBuilder ()
803
- << " Error creating directory for session " << SessionId
808
+ << " Error creating directory for session " << TempDirName
804
809
<< " : " << result->Get ()->Result .Issues ().ToString (true ));
805
810
}
806
811
MakeSchemeOperationRequest ();
@@ -1097,8 +1102,9 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
1097
1102
const TString ClientAddress;
1098
1103
std::unique_ptr<TEvKqpExecuter::TEvTxResponse> ResponseEv;
1099
1104
bool Temporary;
1105
+ bool CreateTmpDir;
1100
1106
bool IsCreateTableAs;
1101
- TString SessionId ;
1107
+ TString TempDirName ;
1102
1108
ui64 TxId = 0 ;
1103
1109
TActorId SchemePipeActorId_;
1104
1110
ui64 SchemeShardTabletId = 0 ;
@@ -1113,12 +1119,12 @@ IActor* CreateKqpSchemeExecuter(
1113
1119
TKqpPhyTxHolder::TConstPtr phyTx, NKikimrKqp::EQueryType queryType, const TActorId& target,
1114
1120
const TMaybe<TString>& requestType, const TString& database,
1115
1121
TIntrusiveConstPtr<NACLib::TUserToken> userToken, const TString& clientAddress,
1116
- bool temporary, bool isCreateTableAs,
1117
- TString sessionId , TIntrusivePtr<TUserRequestContext> ctx, const TActorId& kqpTempTablesAgentActor)
1122
+ bool temporary, bool createTmpDir, bool isCreateTableAs,
1123
+ TString tempDirName , TIntrusivePtr<TUserRequestContext> ctx, const TActorId& kqpTempTablesAgentActor)
1118
1124
{
1119
1125
return new TKqpSchemeExecuter (
1120
1126
phyTx, queryType, target, requestType, database, userToken, clientAddress,
1121
- temporary, isCreateTableAs, sessionId , std::move (ctx), kqpTempTablesAgentActor);
1127
+ temporary, createTmpDir, isCreateTableAs, tempDirName , std::move (ctx), kqpTempTablesAgentActor);
1122
1128
}
1123
1129
1124
1130
} // namespace NKikimr::NKqp
0 commit comments