Skip to content

Commit 1997bae

Browse files
authored
feat(p3): add submission command (#438)
* feat(p3): add submission command Signed-off-by: Alex Chi <[email protected]> * minor fix Signed-off-by: Alex Chi <[email protected]> * throw on some join types Signed-off-by: Alex Chi <[email protected]> * fix help Signed-off-by: Alex Chi <[email protected]>
1 parent 5976d77 commit 1997bae

File tree

8 files changed

+86
-21
lines changed

8 files changed

+86
-21
lines changed

CMakeLists.txt

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ project(BusTub
1010
LANGUAGES C CXX
1111
)
1212

13-
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
14-
message(STATUS "Setting build type to `Debug` as none was specified.")
15-
set(CMAKE_BUILD_TYPE "Debug")
16-
endif()
13+
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
14+
message(STATUS "Setting build type to `Debug` as none was specified.")
15+
set(CMAKE_BUILD_TYPE "Debug")
16+
endif ()
1717

1818

19-
if(EMSCRIPTEN)
19+
if (EMSCRIPTEN)
2020
add_compile_options(-fexceptions)
2121
add_link_options(-fexceptions)
22-
endif()
22+
endif ()
2323

2424
# People keep running CMake in the wrong folder, completely nuking their project or creating weird bugs.
2525
# This checks if you're running CMake from a folder that already has CMakeLists.txt.
@@ -135,11 +135,11 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
135135
set(BUSTUB_SRC_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/include)
136136
set(BUSTUB_TEST_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/test/include)
137137
set(BUSTUB_THIRD_PARTY_INCLUDE_DIR
138-
${PROJECT_SOURCE_DIR}/third_party
139-
${PROJECT_SOURCE_DIR}/third_party/fmt/include
140-
${PROJECT_SOURCE_DIR}/third_party/libpg_query/include
141-
${PROJECT_SOURCE_DIR}/third_party/argparse/include
142-
)
138+
${PROJECT_SOURCE_DIR}/third_party
139+
${PROJECT_SOURCE_DIR}/third_party/fmt/include
140+
${PROJECT_SOURCE_DIR}/third_party/libpg_query/include
141+
${PROJECT_SOURCE_DIR}/third_party/argparse/include
142+
)
143143

144144
include_directories(${BUSTUB_SRC_INCLUDE_DIR} ${BUSTUB_TEST_INCLUDE_DIR} ${BUSTUB_THIRD_PARTY_INCLUDE_DIR})
145145
include_directories(BEFORE src) # This is needed for gtest.
@@ -286,7 +286,7 @@ set(P2_FILES
286286
"src/include/storage/index/b_plus_tree.h"
287287
"src/storage/index/b_plus_tree.cpp"
288288
${P1_FILES}
289-
)
289+
)
290290
add_custom_target(check-clang-tidy-p2
291291
${BUSTUB_BUILD_SUPPORT_DIR}/run_clang_tidy.py # run LLVM's clang-tidy script
292292
-clang-tidy-binary ${CLANG_TIDY_BIN} # using our clang-tidy binary
@@ -299,4 +299,46 @@ add_custom_target(submit-p2
299299
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
300300
)
301301

302+
set(P3_FILES
303+
"src/include/execution/executors/aggregation_executor.h"
304+
"src/include/execution/executors/delete_executor.h"
305+
"src/include/execution/executors/filter_executor.h"
306+
"src/include/execution/executors/hash_join_executor.h"
307+
"src/include/execution/executors/index_scan_executor.h"
308+
"src/include/execution/executors/insert_executor.h"
309+
"src/include/execution/executors/limit_executor.h"
310+
"src/include/execution/executors/nested_index_join_executor.h"
311+
"src/include/execution/executors/nested_loop_join_executor.h"
312+
"src/include/execution/executors/seq_scan_executor.h"
313+
"src/include/execution/executors/sort_executor.h"
314+
"src/include/execution/executors/topn_executor.h"
315+
"src/execution/aggregation_executor.cpp"
316+
"src/execution/delete_executor.cpp"
317+
"src/execution/filter_executor.cpp"
318+
"src/execution/hash_join_executor.cpp"
319+
"src/execution/index_scan_executor.cpp"
320+
"src/execution/insert_executor.cpp"
321+
"src/execution/limit_executor.cpp"
322+
"src/execution/nested_index_join_executor.cpp"
323+
"src/execution/nested_loop_join_executor.cpp"
324+
"src/execution/seq_scan_executor.cpp"
325+
"src/execution/sort_executor.cpp"
326+
"src/execution/topn_executor.cpp"
327+
"src/include/optimizer/optimizer.h"
328+
"src/optimizer/optimizer_custom_rules.cpp"
329+
${P2_FILES}
330+
)
331+
332+
add_custom_target(check-clang-tidy-p3
333+
${BUSTUB_BUILD_SUPPORT_DIR}/run_clang_tidy.py # run LLVM's clang-tidy script
334+
-clang-tidy-binary ${CLANG_TIDY_BIN} # using our clang-tidy binary
335+
-p ${CMAKE_BINARY_DIR} # using cmake's generated compile commands
336+
${P3_FILES}
337+
)
338+
add_custom_target(submit-p3
339+
zip project3-submission.zip
340+
${P3_FILES}
341+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
342+
)
343+
302344
add_dependencies(check-clang-tidy gtest bustub) # needs gtest headers, compile_commands.json

src/common/bustub_instance.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ void BustubInstance::WriteOneCell(const std::string &cell, ResultWriter &writer)
125125
void BustubInstance::CmdDisplayHelp(ResultWriter &writer) {
126126
std::string help = R"(Welcome to the BusTub shell!
127127
128-
\\dt: show all tables
129-
\\di: show all indices
130-
\\help: show this message again
128+
\dt: show all tables
129+
\di: show all indices
130+
\help: show this message again
131131
132132
BusTub shell currently only supports a small set of Postgres queries. We'll set
133133
up a doc describing the current status later. It will silently ignore some parts

src/execution/filter_executor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ void FilterExecutor::Init() {
1515

1616
auto FilterExecutor::Next(Tuple *tuple, RID *rid) -> bool {
1717
auto filter_expr = plan_->GetPredicate();
18-
auto true_value = ValueFactory::GetBooleanValue(true);
1918

2019
while (true) {
2120
// Get the next tuple
@@ -26,7 +25,7 @@ auto FilterExecutor::Next(Tuple *tuple, RID *rid) -> bool {
2625
}
2726

2827
auto value = filter_expr->Evaluate(tuple, child_executor_->GetOutputSchema());
29-
if (value.CompareEquals(true_value) == CmpBool::CmpTrue) {
28+
if (!value.IsNull() && value.GetAs<bool>()) {
3029
return true;
3130
}
3231
}

src/execution/hash_join_executor.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@
1212

1313
#include "execution/executors/hash_join_executor.h"
1414

15+
// Note for 2022 Fall: You don't need to implement HashJoinExecutor to pass all tests. You ONLY need to implement it
16+
// if you want to get faster in leaderboard tests.
17+
1518
namespace bustub {
1619

1720
HashJoinExecutor::HashJoinExecutor(ExecutorContext *exec_ctx, const HashJoinPlanNode *plan,
1821
std::unique_ptr<AbstractExecutor> &&left_child,
1922
std::unique_ptr<AbstractExecutor> &&right_child)
20-
: AbstractExecutor(exec_ctx) {}
23+
: AbstractExecutor(exec_ctx) {
24+
if (!(plan->GetJoinType() == JoinType::LEFT || plan->GetJoinType() == JoinType::INNER)) {
25+
// Note for 2022 Fall: You ONLY need to implement left join and inner join.
26+
throw bustub::NotImplementedException(fmt::format("join type {} not supported", plan->GetJoinType()));
27+
}
28+
}
2129

2230
void HashJoinExecutor::Init() { throw NotImplementedException("HashJoinExecutor is not implemented"); }
2331

src/execution/nested_index_join_executor.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ namespace bustub {
1616

1717
NestIndexJoinExecutor::NestIndexJoinExecutor(ExecutorContext *exec_ctx, const NestedIndexJoinPlanNode *plan,
1818
std::unique_ptr<AbstractExecutor> &&child_executor)
19-
: AbstractExecutor(exec_ctx) {}
19+
: AbstractExecutor(exec_ctx) {
20+
if (!(plan->GetJoinType() == JoinType::LEFT || plan->GetJoinType() == JoinType::INNER)) {
21+
// Note for 2022 Fall: You ONLY need to implement left join and inner join.
22+
throw bustub::NotImplementedException(fmt::format("join type {} not supported", plan->GetJoinType()));
23+
}
24+
}
2025

2126
void NestIndexJoinExecutor::Init() { throw NotImplementedException("NestIndexJoinExecutor is not implemented"); }
2227

src/execution/nested_loop_join_executor.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "execution/executors/nested_loop_join_executor.h"
14+
#include "binder/table_ref/bound_join_ref.h"
15+
#include "common/exception.h"
1416

1517
namespace bustub {
1618

1719
NestedLoopJoinExecutor::NestedLoopJoinExecutor(ExecutorContext *exec_ctx, const NestedLoopJoinPlanNode *plan,
1820
std::unique_ptr<AbstractExecutor> &&left_executor,
1921
std::unique_ptr<AbstractExecutor> &&right_executor)
20-
: AbstractExecutor(exec_ctx) {}
22+
: AbstractExecutor(exec_ctx) {
23+
if (!(plan->GetJoinType() == JoinType::LEFT || plan->GetJoinType() == JoinType::INNER)) {
24+
// Note for 2022 Fall: You ONLY need to implement left join and inner join.
25+
throw bustub::NotImplementedException(fmt::format("join type {} not supported", plan->GetJoinType()));
26+
}
27+
}
2128

2229
void NestedLoopJoinExecutor::Init() { throw NotImplementedException("NestedLoopJoinExecutor is not implemented"); }
2330

src/optimizer/optimizer_custom_rules.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include "execution/plans/abstract_plan.h"
22
#include "optimizer/optimizer.h"
33

4+
// Note for 2022 Fall: You can add all optimizer rule implementations and apply the rules as you want in this file. Note
5+
// that for some test cases, we force using starter rules, so that the configuration here won't take effects. Starter
6+
// rule can be forcibly enabled by `set force_optimizer_starter_rule=yes`.
7+
48
namespace bustub {
59

610
auto Optimizer::OptimizeCustom(const AbstractPlanNodeRef &plan) -> AbstractPlanNodeRef {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 10 pts
2-
# Run in RELEASE MODE
2+
# Run in RELEASE MODE, set at least 60s timeout.
33

44
# This test is like how a data engineer works towards their goal. They query some data,
55
# store it (materialize it), and query some more data again, until they reach their goal.

0 commit comments

Comments
 (0)