| 23 | } |
| 24 | |
| 25 | void InsertDatasetByRow::init() { |
| 26 | std::string datasetFullPath = TestHelper::appendLbugRootPath("dataset/" + datasetPath + "/"); |
| 27 | ; |
| 28 | std::string copyFile = datasetFullPath + TestHelper::COPY_FILE_NAME; |
| 29 | std::ifstream file(copyFile); |
| 30 | if (!file.is_open()) { |
| 31 | throw TestException(std::format("Error opening file: {}, errno: {}.", copyFile, errno)); |
| 32 | } |
| 33 | std::string line; |
| 34 | while (getline(file, line)) { |
| 35 | auto tokens = StringUtils::split(line, " "); |
| 36 | auto copyStatement = tokens[0]; |
| 37 | auto tableName = tokens[1]; |
| 38 | StringUtils::toLower(copyStatement); |
| 39 | if (copyStatement != "copy") { |
| 40 | throw TestException(std::format("Invalid COPY statement: {}", line)); |
| 41 | } |
| 42 | auto query = std::format("call show_tables() where name='{}' return type;", tableName); |
| 43 | auto result = validateQuery(connection, query); |
| 44 | auto tableType = result->getNext()->getValue(0)->toString(); |
| 45 | query = std::format("call table_info('{}') return name, type order by `property id`;", |
| 46 | tableName); |
| 47 | result = validateQuery(connection, query); |
| 48 | std::vector<std::pair<std::string, std::string>> properties; |
| 49 | while (result->hasNext()) { |
| 50 | auto tuple = result->getNext(); |
| 51 | properties.emplace_back(tuple->getValue(0)->toString(), tuple->getValue(1)->toString()); |
| 52 | } |
| 53 | size_t start = line.find('"', 0); |
| 54 | size_t end = line.find('"', start + 1); |
| 55 | if (start == std::string::npos || end == std::string::npos) { |
| 56 | throw TestException(std::format("Invalid file from copy {}.", line)); |
| 57 | } |
| 58 | std::string fileName = line.substr(start + 1, end - start - 1); |
| 59 | auto datasetFilePath = "\"" + datasetFullPath + fileName + "\""; |
| 60 | if (tableType == "NODE") { |
| 61 | tables.push_back(std::make_unique<NodeTableInfo>(std::move(tableName), |
| 62 | std::move(datasetFilePath), std::move(properties))); |
| 63 | } else if (tableType == "REL") { |
| 64 | query = std::format("call show_connection('{}') return *;", tableName); |
| 65 | result = validateQuery(connection, query); |
| 66 | auto tuple = result->getNext(); |
| 67 | RelConnection from; |
| 68 | RelConnection to; |
| 69 | from.name = tuple->getValue(0)->toString(); |
| 70 | from.property = tuple->getValue(2)->toString(); |
| 71 | to.name = tuple->getValue(1)->toString(); |
| 72 | to.property = tuple->getValue(3)->toString(); |
| 73 | query = std::format("call table_info('{}') where name='{}' return type;" |
| 74 | "call table_info('{}') where name='{}' return type;", |
| 75 | from.name, from.property, to.name, to.property); |
| 76 | result = validateQuery(connection, query); |
| 77 | from.type = result->getNext()->getValue(0)->toString(); |
| 78 | auto next = result->getNextQueryResult(); |
| 79 | to.type = next->getNext()->getValue(0)->toString(); |
| 80 | tables.push_back(std::make_unique<RelTableInfo>(std::move(tableName), |
| 81 | std::move(datasetFilePath), std::move(properties), std::move(from), std::move(to))); |
| 82 | } else { |