Skip to content

Commit

Permalink
Convert demo db tests to e2e tests (#1574)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfdavid committed May 28, 2023
1 parent 65263f5 commit fbee1f6
Show file tree
Hide file tree
Showing 16 changed files with 501 additions and 161 deletions.
9 changes: 9 additions & 0 deletions src/common/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,14 @@ std::vector<std::string> StringUtils::splitBySpace(const std::string& input) {
return result;
}

void StringUtils::replaceAll(
std::string& str, const std::string& search, const std::string& replacement) {
size_t pos = 0;
while ((pos = str.find(search, pos)) != std::string::npos) {
str.replace(pos, search.length(), replacement);
pos += replacement.length();
}
}

} // namespace common
} // namespace kuzu
3 changes: 3 additions & 0 deletions src/include/common/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class StringUtils {
std::regex whiteSpacePattern{"\\s"};
str = std::regex_replace(str, whiteSpacePattern, "");
}

static void replaceAll(
std::string& str, const std::string& search, const std::string& replacement);
};

} // namespace common
Expand Down
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ add_subdirectory(binder)
add_subdirectory(c_api)
add_subdirectory(common)
add_subdirectory(copy)
add_subdirectory(demo_db)
add_subdirectory(main)
add_subdirectory(optimizer)
add_subdirectory(parser)
Expand Down
1 change: 0 additions & 1 deletion test/demo_db/CMakeLists.txt

This file was deleted.

128 changes: 0 additions & 128 deletions test/demo_db/demo_db_test.cpp

This file was deleted.

4 changes: 4 additions & 0 deletions test/include/test_runner/test_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const std::unordered_map<std::string, TokenType> tokenMap = {{"-GROUP", TokenTyp
{"]", TokenType::END_OF_STATEMENT_BLOCK}, {"----", TokenType::RESULT},
{"--", TokenType::SEPARATOR}, {"#", TokenType::EMPTY}};

const std::unordered_map<std::string, std::string> variableMap = {
{"${KUZU_ROOT_DIRECTORY}", KUZU_ROOT_DIRECTORY}};

class LogicToken {
public:
TokenType type;
Expand All @@ -65,6 +68,7 @@ class TestParser {
void extractExpectedResult(TestStatement* currentStatement);
void extractStatementBlock();
void addStatementBlock(const std::string& blockName, const std::string& testGroupName);
void replaceVariables(std::string& str);
inline bool endOfFile() { return fileStream.eof(); }
inline bool nextLine() { return static_cast<bool>(getline(fileStream, line)); }
inline void checkMinimumParams(int minimumParams) {
Expand Down
4 changes: 4 additions & 0 deletions test/include/test_runner/test_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ class TestRunner {
static bool testStatement(TestStatement* statement, main::Connection& conn);
static bool checkLogicalPlans(std::unique_ptr<main::PreparedStatement>& preparedStatement,
TestStatement* statement, main::Connection& conn);
static bool checkLogicalPlan(std::unique_ptr<main::PreparedStatement>& preparedStatement,
TestStatement* statement, main::Connection& conn, uint32_t planIdx);
static std::vector<std::string> convertResultToString(
main::QueryResult& queryResult, bool checkOutputOrder = false);
static bool checkPlanResult(std::unique_ptr<main::QueryResult>& result,
TestStatement* statement, const std::string& planStr, uint32_t planIndex);
};

} // namespace testing
Expand Down
9 changes: 6 additions & 3 deletions test/test_files/demo_db/demo_db.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# skip the new framework of executing until we convert this test
# the test will still run through the current implementation
-SKIP
-GROUP DemoDBTest
-DATASET demo-db/csv

--

-CASE DemoDBTest

-NAME Limit1
-QUERY MATCH (u:User) RETURN u.name ORDER BY u.age DESC LIMIT 3;
Expand Down
51 changes: 51 additions & 0 deletions test/test_files/demo_db/demo_db_create.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-GROUP DemoDBCreateTest
-DATASET demo-db/csv

--

-CASE CreateNodeTest1
-STATEMENT CREATE (u:User {name: 'Alice', age: 35})
---- ok
-QUERY MATCH (a:User) WHERE a.name = 'Alice' RETURN a.name, a.age
---- 1
Alice|35

-CASE CreateNodeTest2
-STATEMENT CREATE (u:User {name: 'Dimitri'})
---- ok
-QUERY MATCH (a:User) WHERE a.name = 'Dimitri' RETURN a.name, a.age
---- 1
Dimitri|

-CASE CreateRelTest1
-STATEMENT CREATE (u:User {name: 'Alice'})
---- ok
-STATEMENT MATCH (a:User) WHERE a.name = 'Adam' WITH a MATCH (b:User) WHERE b.name = 'Alice' WITH a, b CREATE (a)-[e:Follows {since:1990}]->(b)
---- ok
-CHECK_ORDER
-QUERY MATCH (a:User)-[:Follows]->(b:User) WHERE a.name = 'Adam' RETURN b.name ORDER BY b.name
---- 3
Alice
Karissa
Zhang

-CASE CreateRelTest2
-STATEMENT MATCH (a:User), (b:User) WHERE a.name='Zhang' AND b.name='Karissa' CREATE (a)-[:Follows {since:2022}]->(b)
---- ok
-CHECK_ORDER
-QUERY MATCH (a:User)-[:Follows]->(b:User) WHERE a.name = 'Zhang' RETURN b.name ORDER BY b.name
---- 2
Karissa
Noura

-CASE CreateAvgNullTest
-STATEMENT MATCH (a:User) WHERE a.name = 'Adam' CREATE (a)-[:Follows]->(b:User {name:'Alice'})
---- ok
-CHECK_ORDER
-QUERY MATCH (a:User) WITH a, avg(a.age) AS b, SUM(a.age) AS c, COUNT(a.age) AS d, COUNT(*) AS e RETURN a, b, c,d, e ORDER BY c DESC
---- 5
(label:User, 0:4, {name:Alice, age:})|||0|1
(label:User, 0:2, {name:Zhang, age:50})|50.000000|50|1|1
(label:User, 0:1, {name:Karissa, age:40})|40.000000|40|1|1
(label:User, 0:0, {name:Adam, age:30})|30.000000|30|1|1
(label:User, 0:3, {name:Noura, age:25})|25.000000|25|1|1
23 changes: 23 additions & 0 deletions test/test_files/demo_db/demo_db_delete.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-GROUP DemoDBDeleteTest
-DATASET demo-db/csv

--

-CASE DeleteNodeTest
-STATEMENT CREATE (u:User {name: 'Alice', age: 35})
---- ok
-QUERY MATCH (u:User) RETURN COUNT(*)
---- 1
5
-STATEMENT MATCH (u:User) WHERE u.name = 'Alice' DELETE u
---- ok
-QUERY MATCH (u:User) RETURN COUNT(*)
---- 1
4

-CASE DeleteRelTest
-STATEMENT MATCH (u:User)-[f:Follows]->(u1:User) WHERE u.name = 'Adam' AND u1.name = 'Karissa' DELETE f
---- ok
-QUERY MATCH (u:User)-[f:Follows]->(u1:User) WHERE u.name='Adam' RETURN u1.name
---- 1
Zhang
12 changes: 9 additions & 3 deletions test/test_files/demo_db/demo_db_order.test
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# skip the new framework of executing until we convert this test
# the test will still run through the current implementation
-SKIP
-GROUP DemoDBTest
-DATASET demo-db/csv

--

-CASE DemoDBOrderedTest

-NAME OrderBy1
-CHECK_ORDER
-QUERY MATCH (u:User) RETURN u.name, u.age ORDER BY u.age;
---- 4
Noura|25
Expand All @@ -11,12 +15,14 @@ Karissa|40
Zhang|50

-NAME OrderBy2
-CHECK_ORDER
-QUERY MATCH (u:User)-[:LivesIn]->(c:City) WHERE c.name = "Waterloo" RETURN u.name, u.age ORDER BY u.age DESC;
---- 2
Karissa|40
Adam|30

-NAME OrderBy3
-CHECK_ORDER
-QUERY MATCH (a:User)-[:Follows]->(b:User) RETURN b.age, a.name ORDER BY b.age DESC, a.name DESC;
---- 4
50|Karissa
Expand Down
31 changes: 31 additions & 0 deletions test/test_files/demo_db/demo_db_order_parquet.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-GROUP DemoDBTest
-DATASET demo-db/parquet

--

-CASE DemoDBOrderedTestFromParquet

-NAME OrderBy1
-CHECK_ORDER
-QUERY MATCH (u:User) RETURN u.name, u.age ORDER BY u.age;
---- 4
Noura|25
Adam|30
Karissa|40
Zhang|50

-NAME OrderBy2
-CHECK_ORDER
-QUERY MATCH (u:User)-[:LivesIn]->(c:City) WHERE c.name = "Waterloo" RETURN u.name, u.age ORDER BY u.age DESC;
---- 2
Karissa|40
Adam|30

-NAME OrderBy3
-CHECK_ORDER
-QUERY MATCH (a:User)-[:Follows]->(b:User) RETURN b.age, a.name ORDER BY b.age DESC, a.name DESC;
---- 4
50|Karissa
50|Adam
40|Adam
25|Zhang
Loading

0 comments on commit fbee1f6

Please sign in to comment.