Skip to content

Commit

Permalink
update project-3.yaml; add leaderboard for q1 window (#641)
Browse files Browse the repository at this point in the history
* update project-3.yaml; add leaderboard for q1 window; fix window function refsol

Signed-off-by: AveryQi115 <[email protected]>

* change leaderboard q3.1

Signed-off-by: AveryQi115 <[email protected]>

* update leaderboard q3.1

Signed-off-by: AveryQi115 <[email protected]>

---------

Signed-off-by: AveryQi115 <[email protected]>
  • Loading branch information
AveryQi115 authored Oct 30, 2023
1 parent 004761a commit cd34aec
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/execution/mock_scan_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const char *mock_table_list[] = {"__mock_table_1", "__mock_table_2", "__mock_tab
// For leaderboard Q2
"__mock_t4_1m", "__mock_t5_1m", "__mock_t6_1m",
// For leaderboard Q3
"__mock_t7", "__mock_t8", nullptr};
"__mock_t7", "__mock_t8", "__mock_t9", nullptr};

static const int GRAPH_NODE_CNT = 10;

Expand Down Expand Up @@ -124,6 +124,10 @@ auto GetMockTableSchemaOf(const std::string &table) -> Schema {
return Schema{std::vector{Column{"v4", TypeId::INTEGER}}};
}

if (table == "__mock_t9") {
return Schema{std::vector{Column{"x", TypeId::INTEGER}, Column{"y", TypeId::INTEGER}}};
}

throw bustub::Exception(fmt::format("mock table {} not found", table));
}

Expand Down Expand Up @@ -194,6 +198,10 @@ auto GetSizeOf(const MockScanPlanNode *plan) -> size_t {
return 10;
}

if (table == "__mock_t9") {
return 1000000;
}

return 0;
}

Expand Down Expand Up @@ -410,6 +418,15 @@ auto GetFunctionOf(const MockScanPlanNode *plan) -> std::function<Tuple(size_t)>
};
}

if (table == "__mock_t9") {
return [plan](size_t cursor) {
std::vector<Value> values{};
values.push_back(ValueFactory::GetIntegerValue(cursor / 10000));
values.push_back(ValueFactory::GetIntegerValue(cursor / 2 + ((cursor / 10000) % 2) * ((cursor / 2) % 2)));
return Tuple{values, &plan->OutputSchema()};
};
}

// By default, return table of all 0.
return [plan](size_t cursor) {
std::vector<Value> values{};
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ set(BUSTUB_SLT_SOURCES
"${PROJECT_SOURCE_DIR}/test/sql/p3.18-integration-1.slt"
"${PROJECT_SOURCE_DIR}/test/sql/p3.19-integration-2.slt"
"${PROJECT_SOURCE_DIR}/test/sql/p3.20-window-function.slt"
"${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q1.slt"
"${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q1-window.slt"
"${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q2.slt"
"${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q3.slt"
)
Expand Down
24 changes: 24 additions & 0 deletions test/sql/p3.leaderboard-q1-window.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
statement ok
explain (o) select x, y from (
select x, y, rank() over (partition by x order by y) as rank
from __mock_t9
) where rank <= 3;

query nosort +timing:x10:.q1
select * from (
select x, y from (
select x, y, rank() over (partition by x order by y) as rank
from __mock_t9
) where rank <= 3
) order by y limit 10;
----
0 0
0 0
0 1
0 1
1 5000
1 5000
1 5002
1 5002
1 5002
1 5002

0 comments on commit cd34aec

Please sign in to comment.