| 59 | } |
| 60 | |
| 61 | void 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 | |
| 98 | void SplitMultiCopyRandom::run() { |
| 99 | for (auto file : splitFilePaths) { |
nothing calls this directly
no test coverage detected