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

Method createTableInfo

test/test_runner/csv_converter.cpp:35–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35void CSVConverter::createTableInfo(std::string schemaFile) {
36 std::ifstream file(schemaFile);
37 if (!file.is_open()) {
38 throw TestException(std::format("Error opening file: {}, errno: {}.", schemaFile, errno));
39 }
40 // This implementation stays as a temporary solution to create copy statements for rel tables
41 // We'll switch to use table_info once that function can provide everything needed
42 // table_info is mentioned in this issue https://github.com/kuzudb/kuzu/issues/2991
43 std::string line;
44 while (getline(file, line)) {
45 auto tokens = StringUtils::split(line, " ");
46
47 std::transform(tokens[0].begin(), tokens[0].end(), tokens[0].begin(),
48 [](unsigned char c) { return std::tolower(c); });
49 std::transform(tokens[2].begin(), tokens[2].end(), tokens[2].begin(),
50 [](unsigned char c) { return std::tolower(c); });
51 if (tokens[0] != "create" || tokens[2] != "table") {
52 throw TestException(std::format("Invalid CREATE statement: {}", line));
53 }
54
55 auto tableType = tokens[1];
56 std::transform(tableType.begin(), tableType.end(), tableType.begin(),
57 [](unsigned char c) { return std::tolower(c); });
58 auto tableName = tokens[3];
59
60 std::shared_ptr<TableInfo> table;
61 if (tableType == "node") {
62 auto nodeTable = std::make_shared<NodeTableInfo>();
63 size_t primaryKeyPos = line.find("PRIMARY KEY");
64 if (primaryKeyPos != std::string::npos) {
65 size_t openParenPos = line.find("(", primaryKeyPos);
66 size_t closeParenPos = line.find(")", primaryKeyPos);
67 if (openParenPos != std::string::npos && closeParenPos != std::string::npos &&
68 openParenPos < closeParenPos) {
69 nodeTable->primaryKey =
70 line.substr(openParenPos + 1, closeParenPos - openParenPos - 1);
71 table = nodeTable;
72 } else {
73 throw TestException(
74 std::format("PRIMARY KEY is not defined in node table: {}", line));
75 }
76 } else {
77 throw TestException(
78 std::format("PRIMARY KEY is not defined in node table: {}", line));
79 }
80 } else {
81 auto relTable = std::make_shared<RelTableInfo>();
82 size_t startPos = line.find("FROM");
83 if (startPos != std::string::npos) {
84 size_t endPos = line.find_first_of(",)", startPos);
85 if (endPos != std::string::npos) {
86 auto tmp = StringUtils::splitBySpace(line.substr(startPos, endPos - startPos));
87 relTable->fromTable =
88 std::dynamic_pointer_cast<NodeTableInfo>(tableNameMap[tmp[1]]);
89 relTable->toTable =
90 std::dynamic_pointer_cast<NodeTableInfo>(tableNameMap[tmp[3]]);
91 table = relTable;
92 } else {

Callers

nothing calls this directly

Calls 5

TestExceptionClass · 0.85
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected