MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / init

Method init

test/test_runner/multi_copy_split.cpp:61–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61void SplitMultiCopyRandom::init() {
62 genSeedIfNecessary();
63
64 const std::string tmpDir = TestHelper::getTempDir("multi_copy");
65 auto totalFilePath = TestHelper::joinPath(tmpDir, tableName + ".csv");
66 auto loadQuery = std::format("COPY (LOAD FROM {} RETURN *) TO '{}';", source, totalFilePath);
67 spdlog::info("QUERY: {}", loadQuery);
68 validateQuery(connection, loadQuery);
69
70 auto lineEnds = getLineEnds(totalFilePath);
71
72 auto lineIdx = 0u;
73 std::vector<std::string> lengths;
74 std::ifstream file(totalFilePath);
75 for (auto& endLine : lineEnds) {
76 lengths.push_back(std::to_string(endLine - lineIdx));
77 auto currFilePath =
78 TestHelper::joinPath(tmpDir, tableName + std::to_string(lengths.size()) + ".csv");
79 std::ofstream outfile(currFilePath);
80 if (!outfile.is_open()) {
81 throw TestException(
82 std::format("Error opening file: {}, errno: {}.", currFilePath, errno));
83 }
84 splitFilePaths.push_back(currFilePath);
85 std::string line;
86 for (; lineIdx < endLine; lineIdx++) {
87 if (!getline(file, line)) {
88 throw TestException(
89 std::format("Expected line number mismatch: {} to {}.", lineIdx, endLine));
90 }
91 outfile << line << "\n";
92 }
93 }
94 spdlog::info("RANDOM MULTI COPY: split {} lines into {} chunks of {} lines",
95 lineEnds[lineEnds.size() - 1], numSplit, StringUtils::join(lengths, ", "));
96}
97
98void SplitMultiCopyRandom::run() {
99 for (auto file : splitFilePaths) {

Callers

nothing calls this directly

Calls 5

TestExceptionClass · 0.85
joinFunction · 0.85
validateQueryFunction · 0.70
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected