MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / performAtomicRename

Function performAtomicRename

src/Client/ClientBase.cpp:218–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218void performAtomicRename(const DB::ASTPtr & parsed_query, const String & out_file)
219{
220 if (const auto * query_with_output = dynamic_cast<const DB::ASTQueryWithOutput *>(parsed_query.get()))
221 {
222 if (query_with_output->isOutfileTruncate() && query_with_output->out_file)
223 {
224 const auto & tmp_file_node = query_with_output->out_file->as<DB::ASTLiteral &>();
225 String tmp_file = tmp_file_node.value.safeGet<std::string>();
226
227 try
228 {
229 fs::rename(tmp_file, out_file);
230 }
231 catch (const fs::filesystem_error & e)
232 {
233 /// Clean up temporary file
234 if (fs::exists(tmp_file))
235 fs::remove(tmp_file);
236
237 throw DB::Exception(DB::ErrorCodes::CANNOT_WRITE_TO_FILE,
238 "Cannot rename temporary file {} to {}: {}",
239 tmp_file, out_file, e.what());
240 }
241 }
242 }
243}
244
245}
246

Callers 1

processOrdinaryQueryMethod · 0.85

Calls 7

renameFunction · 0.85
isOutfileTruncateMethod · 0.80
ExceptionClass · 0.70
existsFunction · 0.50
removeFunction · 0.50
getMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected