Skip to content

Commit 746c07d

Browse files
authored
feat(p3): finalize tests (#446)
Signed-off-by: Alex Chi <[email protected]>
1 parent 91a6ae6 commit 746c07d

File tree

8 files changed

+231
-167
lines changed

8 files changed

+231
-167
lines changed

CMakeLists.txt

Lines changed: 129 additions & 125 deletions
Large diffs are not rendered by default.

test/CMakeLists.txt

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,35 @@ add_custom_target(check-public-ci-tests COMMAND ${CMAKE_CTEST_COMMAND} --verbose
1818
# #########################################
1919
# "make XYZ_test"
2020
# #########################################
21-
foreach(bustub_test_source ${BUSTUB_TEST_SOURCES})
22-
# Create a human readable name.
23-
get_filename_component(bustub_test_filename ${bustub_test_source} NAME)
24-
string(REPLACE ".cpp" "" bustub_test_name ${bustub_test_filename})
21+
foreach (bustub_test_source ${BUSTUB_TEST_SOURCES})
22+
# Create a human readable name.
23+
get_filename_component(bustub_test_filename ${bustub_test_source} NAME)
24+
string(REPLACE ".cpp" "" bustub_test_name ${bustub_test_filename})
2525

26-
# Add the test target separately and as part of "make check-tests".
27-
add_executable(${bustub_test_name} EXCLUDE_FROM_ALL ${bustub_test_source})
28-
add_dependencies(build-tests ${bustub_test_name})
29-
add_dependencies(check-tests ${bustub_test_name})
26+
# Add the test target separately and as part of "make check-tests".
27+
add_executable(${bustub_test_name} EXCLUDE_FROM_ALL ${bustub_test_source})
28+
add_dependencies(build-tests ${bustub_test_name})
29+
add_dependencies(check-tests ${bustub_test_name})
3030

31-
gtest_discover_tests(${bustub_test_name}
32-
EXTRA_ARGS
33-
--gtest_color=auto
34-
--gtest_output=xml:${CMAKE_BINARY_DIR}/test/${bustub_test_name}.xml
35-
--gtest_catch_exceptions=0
36-
DISCOVERY_TIMEOUT 120
37-
PROPERTIES
38-
TIMEOUT 60
39-
)
31+
gtest_discover_tests(${bustub_test_name}
32+
EXTRA_ARGS
33+
--gtest_color=auto
34+
--gtest_output=xml:${CMAKE_BINARY_DIR}/test/${bustub_test_name}.xml
35+
--gtest_catch_exceptions=0
36+
DISCOVERY_TIMEOUT 120
37+
PROPERTIES
38+
TIMEOUT 120
39+
)
4040

41-
target_link_libraries(${bustub_test_name} bustub gtest gmock_main)
41+
target_link_libraries(${bustub_test_name} bustub gtest gmock_main)
4242

43-
# Set test target properties and dependencies.
44-
set_target_properties(${bustub_test_name}
45-
PROPERTIES
46-
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/test"
47-
COMMAND ${bustub_test_name}
48-
)
49-
endforeach()
43+
# Set test target properties and dependencies.
44+
set_target_properties(${bustub_test_name}
45+
PROPERTIES
46+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/test"
47+
COMMAND ${bustub_test_name}
48+
)
49+
endforeach ()
5050

5151
set(BUSTUB_SLT_SOURCES
5252
"${PROJECT_SOURCE_DIR}/test/sql/p3.01-seqscan.slt"
@@ -68,22 +68,22 @@ set(BUSTUB_SLT_SOURCES
6868
"${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q1.slt"
6969
"${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q2.slt"
7070
"${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q3.slt"
71-
)
71+
)
7272

7373
add_custom_target(test-p3 ${CMAKE_CTEST_COMMAND} -R SQLLogicTest)
7474

7575
# #########################################
7676
# "make XYZ_test"
7777
# #########################################
78-
foreach(bustub_test_source ${BUSTUB_SLT_SOURCES})
79-
# Create a human readable name.
80-
get_filename_component(bustub_test_filename ${bustub_test_source} NAME)
81-
string(REPLACE ".slt" "" bustub_filename_wo_suffix "${bustub_test_filename}")
82-
string(REPLACE ".slt" "" bustub_test_name "SQLLogicTest.${bustub_filename_wo_suffix}")
83-
add_test(NAME ${bustub_test_name} COMMAND "${CMAKE_BINARY_DIR}/bin/bustub-sqllogictest" ${bustub_test_source} --verbose -d)
84-
add_custom_target(${bustub_filename_wo_suffix}_test COMMAND "${CMAKE_BINARY_DIR}/bin/bustub-sqllogictest" "${bustub_test_source}" --verbose -d)
85-
add_dependencies(${bustub_filename_wo_suffix}_test sqllogictest)
86-
endforeach()
78+
foreach (bustub_test_source ${BUSTUB_SLT_SOURCES})
79+
# Create a human readable name.
80+
get_filename_component(bustub_test_filename ${bustub_test_source} NAME)
81+
string(REPLACE ".slt" "" bustub_filename_wo_suffix "${bustub_test_filename}")
82+
string(REPLACE ".slt" "" bustub_test_name "SQLLogicTest.${bustub_filename_wo_suffix}")
83+
add_test(NAME ${bustub_test_name} COMMAND "${CMAKE_BINARY_DIR}/bin/bustub-sqllogictest" ${bustub_test_source} --verbose -d)
84+
add_custom_target(${bustub_filename_wo_suffix}_test COMMAND "${CMAKE_BINARY_DIR}/bin/bustub-sqllogictest" "${bustub_test_source}" --verbose -d)
85+
add_dependencies(${bustub_filename_wo_suffix}_test sqllogictest)
86+
endforeach ()
8787

8888
add_dependencies(test-p3 sqllogictest)
8989

test/sql/p3.07-group-agg-1.slt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ statement ok
2525
-- v6: some magic string
2626
create table t1(v1 int, v2 int, v3 int, v4 int, v5 int, v6 varchar(128));
2727

28+
query
29+
select v5, min(v1), sum(v2), count(*) from t1 group by v5; -- no groups, no output
30+
----
31+
2832
query
2933
insert into t1 select * from __mock_agg_input_small;
3034
----

test/sql/p3.09-simple-join.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ select * from temp_3 t3 inner join temp_2 t2 on t3.colB = t2.colA;
391391

392392
query rowsort
393393
select * from
394-
temp_2 t2 inner join
394+
(select * from temp_2 where colB < 10) t2 inner join
395395
(select distinct(temp_2.colA) from temp_1 inner join temp_2 on temp_1.colC = temp_2.colA) t3
396396
on t2.colB < t3.colA;
397397
----

test/sql/p3.10-multi-way-join.slt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,39 @@ select L.colC as colC, L.t1B, L.t2B, R.t3B, R.t4B from
334334
0 132 917 917 221
335335
0 132 917 8 8
336336
0 132 917 8 221
337+
338+
statement ok
339+
create table t2(v1 int); insert into t2 values (1), (1), (2);
340+
341+
statement ok
342+
create table t3(v1 int); insert into t3 values (1), (2), (3);
343+
344+
statement ok
345+
create table t4(v1 int); insert into t4 values (2), (3), (3);
346+
347+
query rowsort
348+
select * from t3 left join t2 on t2.v1 = t3.v1;
349+
----
350+
1 1
351+
1 1
352+
2 2
353+
3 integer_null
354+
355+
query rowsort
356+
select * from (t3 left join t2 on t2.v1 = t3.v1) left join t4 on t3.v1 = t4.v1;
357+
----
358+
1 1 integer_null
359+
1 1 integer_null
360+
2 2 2
361+
3 integer_null 3
362+
3 integer_null 3
363+
364+
statement ok
365+
create table t5(v1 int);
366+
367+
query rowsort
368+
select * from ((t3 left join t5 on t3.v1 < t5.v1) left join t5 as t52 on t3.v1 < t52.v1) left join t5 as t53 on t3.v1 < t53.v1;
369+
----
370+
1 integer_null integer_null integer_null
371+
2 integer_null integer_null integer_null
372+
3 integer_null integer_null integer_null

test/sql/p3.14-topn.slt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,10 @@ select * from
350350
84 711 4 9 92192 84 4626
351351
69 603 9 8 20385 69 755
352352
33 701 3 8 24527 33 991
353+
354+
query rowsort +explain +ensure:topn*2
355+
select * from (select * from test_simple_seq_2 order by col1 desc limit 5) order by col1 asc limit 3;
356+
----
357+
5 15
358+
6 16
359+
7 17

test/sql/p3.16-integration-2.slt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ SELECT * FROM result;
4444
8 8 008 008 0 0
4545
9 9 009 009 0 0
4646

47-
query rowsort
47+
query rowsort +explain:o
4848
-- 1st neighbor
4949
INSERT INTO tmp SELECT * FROM (
5050
SELECT
@@ -63,7 +63,7 @@ INSERT INTO tmp SELECT * FROM (
6363
statement ok
6464
INSERT INTO result SELECT * FROM tmp; DELETE FROM tmp; SELECT count(*) FROM result;
6565

66-
query rowsort
66+
query rowsort +explain:o
6767
-- 2nd neighbor
6868
INSERT INTO tmp SELECT * FROM (
6969
SELECT
@@ -82,7 +82,7 @@ INSERT INTO tmp SELECT * FROM (
8282
statement ok
8383
INSERT INTO result SELECT * FROM tmp; DELETE FROM tmp; SELECT count(*) FROM result;
8484

85-
query rowsort
85+
query rowsort +explain:o
8686
-- 3rd neighbor
8787
INSERT INTO tmp SELECT * FROM (
8888
SELECT
@@ -101,7 +101,7 @@ INSERT INTO tmp SELECT * FROM (
101101
statement ok
102102
INSERT INTO result SELECT * FROM tmp; DELETE FROM tmp; SELECT count(*) FROM result;
103103

104-
query rowsort
104+
query rowsort +explain:o
105105
-- 4th neighbor
106106
INSERT INTO tmp SELECT * FROM (
107107
SELECT
@@ -120,7 +120,7 @@ INSERT INTO tmp SELECT * FROM (
120120
statement ok
121121
INSERT INTO result SELECT * FROM tmp; DELETE FROM tmp; SELECT count(*) FROM result;
122122

123-
query rowsort
123+
query rowsort +explain:o
124124
SELECT src, src_label, dst, dst_label, count(*), min(distance), max(distance), min(steps), max(steps) FROM result WHERE src = 1 GROUP BY src, src_label, dst, dst_label ORDER BY dst;
125125
----
126126
1 001 0 000 1000 1 4 1 4

tools/sqllogictest/sqllogictest.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ auto ProcessExtraOptions(const std::string &sql, bustub::BustubInstance &instanc
7777
fmt::print("TopN not found\n");
7878
return false;
7979
}
80+
} else if (opt == "ensure:topn*2") {
81+
if (bustub::StringUtil::Split(result.str(), "TopN").size() != 3) {
82+
fmt::print("TopN should appear exactly twice\n");
83+
return false;
84+
}
8085
} else if (opt == "ensure:index_join") {
8186
if (!bustub::StringUtil::Contains(result.str(), "NestedIndexJoin")) {
8287
fmt::print("NestedIndexJoin not found\n");
@@ -116,6 +121,14 @@ auto ProcessExtraOptions(const std::string &sql, bustub::BustubInstance &instanc
116121
}
117122
fmt::print("\n");
118123
fmt::print(">>>END\n");
124+
} else if (bustub::StringUtil::StartsWith(opt, "explain")) {
125+
auto writer = bustub::SimpleStreamWriter(std::cout);
126+
auto x = bustub::StringUtil::Split(opt, "explain:");
127+
if (!x.empty() && !x[0].empty()) {
128+
instance.ExecuteSql(fmt::format("explain ({}) {}", x[0], sql), writer);
129+
} else {
130+
instance.ExecuteSql("explain " + sql, writer);
131+
}
119132
} else {
120133
throw bustub::NotImplementedException(fmt::format("unsupported extra option: {}", opt));
121134
}
@@ -195,7 +208,7 @@ auto main(int argc, char **argv) -> int { // NOLINT
195208
}
196209

197210
std::stringstream result;
198-
auto writer = bustub::SimpleStreamWriter(result);
211+
auto writer = bustub::SimpleStreamWriter(result, true);
199212
bustub->ExecuteSql(statement.sql_, writer);
200213
if (verbose) {
201214
fmt::print("----\n{}\n", result.str());

0 commit comments

Comments
 (0)