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

Method executeImpl

programs/disks/CommandWrite.cpp:37–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35
36
37 void executeImpl(const CommandLineOptions & options, DisksClient & client) override
38 {
39 auto disk = client.getCurrentDiskWithPath();
40
41 std::optional<String> path_from = getValueFromCommandLineOptionsWithOptional<String>(options, "path-from");
42
43 String path_to = disk.getRelativeFromRoot(getValueFromCommandLineOptionsThrow<String>(options, "path-to"));
44 std::optional<String> write_mode_param = getValueFromCommandLineOptionsWithOptional<String>(options, "mode");
45 WriteMode write_mode = WriteMode::Rewrite;
46 if (write_mode_param.has_value())
47 {
48 if (*write_mode_param == "rewrite")
49 write_mode = WriteMode::Rewrite;
50 else if (*write_mode_param == "append")
51 write_mode = WriteMode::Append;
52 else
53 throw Exception(
54 ErrorCodes::BAD_ARGUMENTS, "invalid `mode`, expected `rewrite` or `append`, actual '{}'", *write_mode_param);
55 }
56
57 auto in = [&]() -> std::unique_ptr<ReadBufferFromFileBase>
58 {
59 if (!path_from.has_value())
60 return std::make_unique<ReadBufferFromFileDescriptor>(STDIN_FILENO);
61
62 String relative_path_from = disk.getRelativeFromRoot(path_from.value());
63 auto res = disk.getDisk()->readFileIfExists(relative_path_from, getReadSettings());
64 if (res)
65 return res;
66 /// For backward compatibility.
67 return std::make_unique<ReadBufferFromEmptyFile>();
68 }();
69
70 LOG_INFO(
71 log,
72 "Writing file from '{}' to '{}' with mode '{}' at disk '{}'",
73 path_from.value_or("stdin"),
74 path_to,
75 write_mode,
76 disk.getDisk()->getName());
77 auto out = disk.getDisk()->writeFile(path_to, DBMS_DEFAULT_BUFFER_SIZE, write_mode);
78 copyData(*in, *out);
79 out->finalize();
80 }
81};
82
83CommandPtr makeCommandWrite()

Callers

nothing calls this directly

Calls 10

getReadSettingsFunction · 0.85
copyDataFunction · 0.85
getRelativeFromRootMethod · 0.80
ExceptionClass · 0.50
valueMethod · 0.45
readFileIfExistsMethod · 0.45
getDiskMethod · 0.45
getNameMethod · 0.45
writeFileMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected