@@ -1162,39 +1162,34 @@ class TKqpSessionActor : public TActorBootstrapped<TKqpSessionActor> {
1162
1162
}
1163
1163
}
1164
1164
1165
- std::optional<TKqpTempTablesState::TTempTableInfo> GetTemporaryTableInfo (TKqpPhyTxHolder::TConstPtr tx) {
1165
+ std::optional<std::pair<bool , TKqpTempTablesState::TTempTableInfo>>
1166
+ GetTemporaryTableInfo (TKqpPhyTxHolder::TConstPtr tx) {
1166
1167
if (!tx) {
1167
1168
return std::nullopt;
1168
1169
}
1169
- const auto & schemeOperation = tx->GetSchemeOperation ();
1170
- switch (schemeOperation.GetOperationCase ()) {
1171
- case NKqpProto::TKqpSchemeOperation::kCreateTable : {
1172
- const auto & modifyScheme = schemeOperation.GetCreateTable ();
1173
- const NKikimrSchemeOp::TTableDescription* tableDesc = nullptr ;
1174
- switch (modifyScheme.GetOperationType ()) {
1175
- case NKikimrSchemeOp::ESchemeOpCreateTable: {
1176
- tableDesc = &modifyScheme.GetCreateTable ();
1177
- break ;
1178
- }
1179
- case NKikimrSchemeOp::ESchemeOpCreateIndexedTable: {
1180
- tableDesc = &modifyScheme.GetCreateIndexedTable ().GetTableDescription ();
1181
- break ;
1182
- }
1183
- default :
1184
- YQL_ENSURE (false , " Unexpected operation type" );
1185
- }
1186
- auto userToken = QueryState ? QueryState->UserToken : TIntrusiveConstPtr<NACLib::TUserToken>();
1187
- if (tableDesc->HasTemporary ()) {
1188
- if (tableDesc->GetTemporary ()) {
1189
- return {{tableDesc->GetName (), modifyScheme.GetWorkingDir (), Settings.Cluster , userToken, Settings.Database }};
1190
- }
1191
- }
1192
- break ;
1193
- }
1194
- default :
1195
- return std::nullopt;
1170
+ auto optPath = tx->GetSchemeOpTempTablePath ();
1171
+ if (!optPath) {
1172
+ return std::nullopt;
1196
1173
}
1197
- return std::nullopt;
1174
+ const auto & [isCreate, path] = *optPath;
1175
+ if (isCreate) {
1176
+ auto userToken = QueryState ? QueryState->UserToken : TIntrusiveConstPtr<NACLib::TUserToken>();
1177
+ return {{true , {path.second , path.first , Settings.Cluster , userToken, Settings.Database }}};
1178
+ }
1179
+
1180
+ TString name = path.second ;
1181
+ auto pos = name.find (*TempTablesState.SessionId );
1182
+
1183
+ if (pos == TString::npos) {
1184
+ return std::nullopt;
1185
+ }
1186
+ name.erase (pos, name.size ());
1187
+
1188
+ auto it = TempTablesState.TempTables .find (std::make_pair (Settings.Cluster , JoinPath ({path.first , name})));
1189
+ if (it == TempTablesState.TempTables .end ()) {
1190
+ return std::nullopt;
1191
+ }
1192
+ return {{false , it->second }};
1198
1193
}
1199
1194
1200
1195
void UpdateTempTablesState () {
@@ -1205,8 +1200,14 @@ class TKqpSessionActor : public TActorBootstrapped<TKqpSessionActor> {
1205
1200
if (!tx) {
1206
1201
return ;
1207
1202
}
1208
- if (auto tempTableInfo = GetTemporaryTableInfo (tx)) {
1209
- TempTablesState.TempTables [std::make_pair (tempTableInfo->Database , JoinPath ({tempTableInfo->WorkingDir , tempTableInfo->Name }))] = std::move (*tempTableInfo);
1203
+ auto optInfo = GetTemporaryTableInfo (tx);
1204
+ if (optInfo) {
1205
+ auto [isCreate, tempTableInfo] = *optInfo;
1206
+ if (isCreate) {
1207
+ TempTablesState.TempTables [std::make_pair (tempTableInfo.Database , JoinPath ({tempTableInfo.WorkingDir , tempTableInfo.Name }))] = tempTableInfo;
1208
+ } else {
1209
+ TempTablesState.TempTables .erase (std::make_pair (tempTableInfo.Database , JoinPath ({tempTableInfo.WorkingDir , tempTableInfo.Name })));
1210
+ }
1210
1211
QueryState->UpdateTempTablesState (TempTablesState);
1211
1212
}
1212
1213
}
0 commit comments