Skip to content

Commit 88d123e

Browse files
authored
feat(p3): add more test cases (#432)
* feat(p3): add more test cases Signed-off-by: Alex Chi <[email protected]> * add new custom rule Signed-off-by: Alex Chi <[email protected]>
1 parent ab7ba98 commit 88d123e

22 files changed

+169
-1
lines changed

src/execution/mock_scan_executor.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const char *mock_table_list[] = {"__mock_table_1",
3838
"__mock_agg_input_small",
3939
"__mock_agg_input_big",
4040
"__mock_table_schedule_2022",
41+
"__mock_table_123",
4142
nullptr};
4243

4344
auto GetMockTableSchemaOf(const std::string &table) -> Schema {
@@ -70,6 +71,10 @@ auto GetMockTableSchemaOf(const std::string &table) -> Schema {
7071
{Column{"v6", TypeId::VARCHAR, 128}}}};
7172
}
7273

74+
if (table == "__mock_table_123") {
75+
return Schema{std::vector{Column{"number", TypeId::INTEGER}}};
76+
}
77+
7378
throw bustub::Exception(fmt::format("mock table {} not found", table));
7479
}
7580

@@ -102,6 +107,10 @@ auto GetSizeOf(const MockScanPlanNode *plan) -> size_t {
102107
return 10000;
103108
}
104109

110+
if (plan->GetTable() == "__mock_table_123") {
111+
return 3;
112+
}
113+
105114
return 100;
106115
}
107116

@@ -187,6 +196,14 @@ auto GetFunctionOf(const MockScanPlanNode *plan) -> std::function<Tuple(size_t)>
187196
};
188197
}
189198

199+
if (plan->GetTable() == "__mock_table_123") {
200+
return [plan](size_t cursor) {
201+
std::vector<Value> values{};
202+
values.push_back(ValueFactory::GetIntegerValue(cursor + 1));
203+
return Tuple{values, &plan->OutputSchema()};
204+
};
205+
}
206+
190207
// By default, return table of all 0.
191208
return [plan](size_t cursor) {
192209
std::vector<Value> values{};

src/optimizer/optimizer_custom_rules.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ auto Optimizer::OptimizeCustom(const AbstractPlanNodeRef &plan) -> AbstractPlanN
1010
p = OptimizeNLJAsIndexJoin(p);
1111
// p = OptimizeNLJAsHashJoin(p); // Enable this rule after you have implemented hash join.
1212
p = OptimizeOrderByAsIndexScan(p);
13+
p = OptimizeSortLimitAsTopN(p);
1314
return p;
1415
}
1516

test/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ set(BUSTUB_SLT_SOURCES
5858
"${PROJECT_SOURCE_DIR}/test/sql/p3.07-group-agg-1.slt"
5959
"${PROJECT_SOURCE_DIR}/test/sql/p3.08-group-agg-2.slt"
6060
"${PROJECT_SOURCE_DIR}/test/sql/p3.09-simple-join.slt"
61+
"${PROJECT_SOURCE_DIR}/test/sql/p3.10-multi-way-join.slt"
62+
"${PROJECT_SOURCE_DIR}/test/sql/p3.11-repeat-execute.slt"
63+
"${PROJECT_SOURCE_DIR}/test/sql/p3.12-nested-index-join.slt"
64+
"${PROJECT_SOURCE_DIR}/test/sql/p3.13-sort-limit.slt"
65+
"${PROJECT_SOURCE_DIR}/test/sql/p3.14-topn.slt"
66+
"${PROJECT_SOURCE_DIR}/test/sql/p3.15-integration-1.slt"
67+
"${PROJECT_SOURCE_DIR}/test/sql/p3.16-integration-2.slt"
68+
"${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q1.slt"
69+
"${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q2.slt"
70+
"${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q3.slt"
6171
)
6272

6373
add_custom_target(test-p3 ${CMAKE_CTEST_COMMAND} -R SQLLogicTest)
@@ -71,7 +81,7 @@ foreach(bustub_test_source ${BUSTUB_SLT_SOURCES})
7181
string(REPLACE ".slt" "" bustub_filename_wo_suffix "${bustub_test_filename}")
7282
string(REPLACE ".slt" "" bustub_test_name "SQLLogicTest.${bustub_filename_wo_suffix}")
7383
add_test(NAME ${bustub_test_name} COMMAND "${CMAKE_BINARY_DIR}/bin/bustub-sqllogictest" ${bustub_test_source} --verbose -d)
74-
add_custom_target(${bustub_filename_wo_suffix}_test COMMAND ${CMAKE_CTEST_COMMAND} -R ${bustub_test_name} --verbose)
84+
add_custom_target(${bustub_filename_wo_suffix}_test COMMAND "${CMAKE_BINARY_DIR}/bin/bustub-sqllogictest" "${bustub_test_source}" --verbose -d)
7585
add_dependencies(${bustub_filename_wo_suffix}_test sqllogictest)
7686
endforeach()
7787

test/sql/p3.01-seqscan.slt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# 5 pts
2+
13
query
24
select * from test_simple_seq_1;
35
----

test/sql/p3.02-insert.slt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# 5 pts
2+
13
# Create a table
24
statement ok
35
create table t1(v1 int, v2 varchar(128), v3 int);

test/sql/p3.03-delete.slt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# 5 pts
2+
13
# Create a table
24
statement ok
35
create table t1(v1 int, v2 varchar(128), v3 int);

test/sql/p3.04-index-scan.slt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# 10 pts
2+
13
# Ensure all order-bys in this file are transformed into index scan
24
statement ok
35
set force_optimizer_starter_rule=yes

test/sql/p3.05-empty-table.slt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# 5 pts
2+
13
# Create a table
24
statement ok
35
create table t1(v1 int);

test/sql/p3.06-simple-agg.slt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# 5 pts
2+
13
# How many TAs are there in 2022 Fall?
24
query
35
select count(*) from __mock_table_tas_2022;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# 5 pts
2+
13
# How many TAs are there for OH on each weekday?
24
# "rowsort" means that the order of result doesn't matter.
35

0 commit comments

Comments
 (0)