Skip to content

Commit 2f2890b

Browse files
authored
feat: Add a private ctor in TableHeap to avoid nullptr table when running binder tests (#582)
* feat: Add a private ctor in TableHeap to avoid nullptr table when running binder tests * fix: Ensure format consistency
1 parent 9553f1c commit 2f2890b

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

src/include/catalog/catalog.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ class Catalog {
132132
// Construct the table heap
133133
std::unique_ptr<TableHeap> table = nullptr;
134134

135-
// TODO(Wan,chi): This should be refactored into a private ctor for the binder tests, we shouldn't allow nullptr.
136135
// When create_table_heap == false, it means that we're running binder tests (where no txn will be provided) or
137136
// we are running shell without buffer pool. We don't need to create TableHeap in this case.
138137
if (create_table_heap) {
139138
table = std::make_unique<TableHeap>(bpm_);
139+
} else {
140+
// Otherwise, create an empty heap only for binder tests
141+
table = TableHeap::CreateEmptyHeap(create_table_heap);
140142
}
141143

142144
// Fetch the table OID for the new table

src/include/planner/planner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class PlannerContext {
6262

6363
/**
6464
* In the second phase of aggregation planning, we plan agg calls from `aggregations_`, and generate
65-
* an aggregation plan node. The expressions in thie vector should be used over the output from the
65+
* an aggregation plan node. The expressions in the vector should be used over the output from the
6666
* aggregation plan node.
6767
*/
6868
std::vector<AbstractExpressionRef> expr_in_agg_;

src/include/storage/table/table_heap.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#pragma once
1414

15+
#include <memory>
1516
#include <mutex> // NOLINT
1617
#include <optional>
1718
#include <utility>
@@ -92,7 +93,17 @@ class TableHeap {
9293
*/
9394
void UpdateTupleInPlaceUnsafe(const TupleMeta &meta, const Tuple &tuple, RID rid);
9495

96+
/** For binder tests */
97+
static auto CreateEmptyHeap(bool create_table_heap = false) -> std::unique_ptr<TableHeap> {
98+
// The input parameter should be false in order to generate a empty heap
99+
assert(!create_table_heap);
100+
return std::unique_ptr<TableHeap>(new TableHeap(create_table_heap));
101+
}
102+
95103
private:
104+
/** Used for binder tests */
105+
explicit TableHeap(bool create_table_heap = false);
106+
96107
BufferPoolManager *bpm_;
97108
page_id_t first_page_id_{INVALID_PAGE_ID};
98109

src/storage/table/table_heap.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ TableHeap::TableHeap(BufferPoolManager *bpm) : bpm_(bpm) {
3636
first_page->Init();
3737
}
3838

39+
TableHeap::TableHeap(bool create_table_heap) : bpm_(nullptr) {}
40+
3941
auto TableHeap::InsertTuple(const TupleMeta &meta, const Tuple &tuple, LockManager *lock_mgr, Transaction *txn,
4042
table_oid_t oid) -> std::optional<RID> {
4143
std::unique_lock<std::mutex> guard(latch_);

0 commit comments

Comments
 (0)