Skip to content

Commit 083f78e

Browse files
authored
feat(p3): add integration test (#436)
Signed-off-by: Alex Chi <[email protected]>
1 parent b325fa1 commit 083f78e

File tree

4 files changed

+391
-6
lines changed

4 files changed

+391
-6
lines changed

src/execution/mock_scan_executor.cpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ const char *mock_table_list[] = {"__mock_table_1",
3939
"__mock_agg_input_big",
4040
"__mock_table_schedule_2022",
4141
"__mock_table_123",
42+
"__mock_graph",
4243
nullptr};
4344

45+
static const int GRAPH_NODE_CNT = 10;
46+
4447
auto GetMockTableSchemaOf(const std::string &table) -> Schema {
4548
if (table == "__mock_table_1") {
4649
return Schema{std::vector{{Column{"colA", TypeId::INTEGER}, {Column{"colB", TypeId::INTEGER}}}}};
@@ -63,12 +66,15 @@ auto GetMockTableSchemaOf(const std::string &table) -> Schema {
6366
}
6467

6568
if (table == "__mock_agg_input_small" || table == "__mock_agg_input_big") {
66-
return Schema{std::vector{Column{"v1", TypeId::INTEGER},
67-
Column{"v2", TypeId::INTEGER},
68-
Column{"v3", TypeId::INTEGER},
69-
Column{"v4", TypeId::INTEGER},
70-
Column{"v5", TypeId::INTEGER},
71-
{Column{"v6", TypeId::VARCHAR, 128}}}};
69+
return Schema{std::vector{Column{"v1", TypeId::INTEGER}, Column{"v2", TypeId::INTEGER},
70+
Column{"v3", TypeId::INTEGER}, Column{"v4", TypeId::INTEGER},
71+
Column{"v5", TypeId::INTEGER}, Column{"v6", TypeId::VARCHAR, 128}}};
72+
}
73+
74+
if (table == "__mock_graph") {
75+
return Schema{std::vector{Column{"src", TypeId::INTEGER}, Column{"dst", TypeId::INTEGER},
76+
Column{"src_label", TypeId::VARCHAR, 8}, Column{"dst_label", TypeId::VARCHAR, 8},
77+
Column{"distance", TypeId::INTEGER}}};
7278
}
7379

7480
if (table == "__mock_table_123") {
@@ -107,6 +113,10 @@ auto GetSizeOf(const MockScanPlanNode *plan) -> size_t {
107113
return 10000;
108114
}
109115

116+
if (plan->GetTable() == "__mock_graph") {
117+
return GRAPH_NODE_CNT * GRAPH_NODE_CNT;
118+
}
119+
110120
if (plan->GetTable() == "__mock_table_123") {
111121
return 3;
112122
}
@@ -204,6 +214,24 @@ auto GetFunctionOf(const MockScanPlanNode *plan) -> std::function<Tuple(size_t)>
204214
};
205215
}
206216

217+
if (plan->GetTable() == "__mock_graph") {
218+
return [plan](size_t cursor) {
219+
std::vector<Value> values{};
220+
int src = cursor % GRAPH_NODE_CNT;
221+
int dst = cursor / GRAPH_NODE_CNT;
222+
values.push_back(ValueFactory::GetIntegerValue(src));
223+
values.push_back(ValueFactory::GetIntegerValue(dst));
224+
values.push_back(ValueFactory::GetVarcharValue(fmt::format("{:03}", src)));
225+
values.push_back(ValueFactory::GetVarcharValue(fmt::format("{:03}", dst)));
226+
if (src == dst) {
227+
values.push_back(ValueFactory::GetNullValueByType(TypeId::INTEGER));
228+
} else {
229+
values.push_back(ValueFactory::GetIntegerValue(1));
230+
}
231+
return Tuple{values, &plan->OutputSchema()};
232+
};
233+
}
234+
207235
// By default, return table of all 0.
208236
return [plan](size_t cursor) {
209237
std::vector<Value> values{};

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,34 @@ yliang412 Tuesday Tuesday 1
1515
kush789 Thursday Thursday 1
1616

1717
# The real test begins...
18+
19+
query rowsort
20+
select * from __mock_table_123 a, __mock_table_123 b, __mock_table_123 c;
21+
----
22+
1 1 1
23+
1 1 2
24+
1 1 3
25+
1 2 1
26+
1 2 2
27+
1 2 3
28+
1 3 1
29+
1 3 2
30+
1 3 3
31+
2 1 1
32+
2 1 2
33+
2 1 3
34+
2 2 1
35+
2 2 2
36+
2 2 3
37+
2 3 1
38+
2 3 2
39+
2 3 3
40+
3 1 1
41+
3 1 2
42+
3 1 3
43+
3 2 1
44+
3 2 2
45+
3 2 3
46+
3 3 1
47+
3 3 2
48+
3 3 3

test/sql/p3.15-integration-1.slt

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,193 @@
11
# 10 pts
2+
# This is something done by some TAs in some start-ups before. Once they got a wrong result
3+
# in a query, they split the query into parts so as to find which one goes wrong...
4+
#
5+
# This ultimate goal is to run an extra-complex query to compute the shortest path within x
6+
# steps from each of the vertex. We will start from the table scan.
7+
8+
statement ok
9+
CREATE TABLE graph(src int, dst int, src_label VARCHAR(8), dst_label VARCHAR(8), distance int);
10+
11+
statement ok
12+
INSERT INTO graph SELECT * FROM __mock_graph;
13+
14+
query rowsort
15+
select count(distance) from __mock_graph;
16+
----
17+
90
18+
19+
query rowsort
20+
-- sanity check
21+
select count(distance), sum(distance) from (
22+
-- find shortest path within 1 neighbor
23+
select src, dst, src_label, dst_label, min(distance) as distance from (
24+
-- with in all the paths
25+
select
26+
left_graph.src as src,
27+
right_graph.dst as dst,
28+
left_graph.src_label as src_label,
29+
right_graph.dst_label as dst_label,
30+
(left_graph.distance + right_graph.distance) as distance
31+
from
32+
graph left_graph inner join graph right_graph
33+
on left_graph.dst = right_graph.src
34+
) group by src, dst, src_label, dst_label
35+
);
36+
----
37+
100 200
38+
39+
statement ok
40+
select * from (
41+
select
42+
left_graph.src as src,
43+
right_graph.dst as dst,
44+
left_graph.src_label as src_label,
45+
right_graph.dst_label as dst_label,
46+
(left_graph.distance + right_graph.distance) as distance
47+
from (
48+
-- find shortest path within 1 neighbor
49+
select src, dst, src_label, dst_label, min(distance) as distance from (
50+
-- with in all the paths
51+
select
52+
left_graph.src as src,
53+
right_graph.dst as dst,
54+
left_graph.src_label as src_label,
55+
right_graph.dst_label as dst_label,
56+
(left_graph.distance + right_graph.distance) as distance
57+
from
58+
graph left_graph inner join graph right_graph
59+
on left_graph.dst = right_graph.src
60+
) group by src, dst, src_label, dst_label
61+
) left_graph inner join graph right_graph on left_graph.dst = right_graph.src
62+
) order by src, dst;
63+
64+
query rowsort
65+
-- sanity check
66+
select count(distance), sum(distance) from (
67+
-- find shortest path within 2 neighbors
68+
select src, dst, src_label, dst_label, min(distance) as distance from (
69+
-- with in all the paths
70+
select
71+
left_graph.src as src,
72+
right_graph.dst as dst,
73+
left_graph.src_label as src_label,
74+
right_graph.dst_label as dst_label,
75+
(left_graph.distance + right_graph.distance) as distance
76+
from (
77+
-- find shortest path within 1 neighbor
78+
select src, dst, src_label, dst_label, min(distance) as distance from (
79+
-- with in all the paths
80+
select
81+
left_graph.src as src,
82+
right_graph.dst as dst,
83+
left_graph.src_label as src_label,
84+
right_graph.dst_label as dst_label,
85+
(left_graph.distance + right_graph.distance) as distance
86+
from
87+
graph left_graph inner join graph right_graph
88+
on left_graph.dst = right_graph.src
89+
) group by src, dst, src_label, dst_label
90+
) left_graph inner join graph right_graph on left_graph.dst = right_graph.src
91+
) group by src, dst, src_label, dst_label
92+
);
93+
----
94+
100 300
95+
96+
query rowsort
97+
-- sanity check
98+
select count(distance), sum(distance) from (
99+
-- find shortest path within 3 neighbors
100+
select src, dst, src_label, dst_label, min(distance) as distance from (
101+
-- with in all the paths
102+
select
103+
left_graph.src as src,
104+
right_graph.dst as dst,
105+
left_graph.src_label as src_label,
106+
right_graph.dst_label as dst_label,
107+
(left_graph.distance + right_graph.distance) as distance
108+
from (
109+
-- find shortest path within 2 neighbors
110+
select src, dst, src_label, dst_label, min(distance) as distance from (
111+
-- with in all the paths
112+
select
113+
left_graph.src as src,
114+
right_graph.dst as dst,
115+
left_graph.src_label as src_label,
116+
right_graph.dst_label as dst_label,
117+
(left_graph.distance + right_graph.distance) as distance
118+
from (
119+
-- find shortest path within 1 neighbor
120+
select src, dst, src_label, dst_label, min(distance) as distance from (
121+
-- with in all the paths
122+
select
123+
left_graph.src as src,
124+
right_graph.dst as dst,
125+
left_graph.src_label as src_label,
126+
right_graph.dst_label as dst_label,
127+
(left_graph.distance + right_graph.distance) as distance
128+
from
129+
graph left_graph inner join graph right_graph
130+
on left_graph.dst = right_graph.src
131+
) group by src, dst, src_label, dst_label
132+
) left_graph inner join graph right_graph on left_graph.dst = right_graph.src
133+
) group by src, dst, src_label, dst_label
134+
) left_graph inner join graph right_graph on left_graph.dst = right_graph.src
135+
) group by src, dst, src_label, dst_label
136+
);
137+
----
138+
100 400
139+
140+
query
141+
select * from (
142+
select src, dst, src_label, dst_label, min(distance) as distance from (
143+
-- with in all the paths
144+
select
145+
left_graph.src as src,
146+
right_graph.dst as dst,
147+
left_graph.src_label as src_label,
148+
right_graph.dst_label as dst_label,
149+
(left_graph.distance + right_graph.distance) as distance
150+
from (
151+
-- find shortest path within 2 neighbors
152+
select src, dst, src_label, dst_label, min(distance) as distance from (
153+
-- with in all the paths
154+
select
155+
left_graph.src as src,
156+
right_graph.dst as dst,
157+
left_graph.src_label as src_label,
158+
right_graph.dst_label as dst_label,
159+
(left_graph.distance + right_graph.distance) as distance
160+
from (
161+
-- find shortest path within 1 neighbor
162+
select src, dst, src_label, dst_label, min(distance) as distance from (
163+
-- with in all the paths
164+
select
165+
left_graph.src as src,
166+
right_graph.dst as dst,
167+
left_graph.src_label as src_label,
168+
right_graph.dst_label as dst_label,
169+
(left_graph.distance + right_graph.distance) as distance
170+
from
171+
graph left_graph inner join graph right_graph
172+
on left_graph.dst = right_graph.src
173+
) group by src, dst, src_label, dst_label
174+
) left_graph inner join graph right_graph on left_graph.dst = right_graph.src
175+
) group by src, dst, src_label, dst_label
176+
) left_graph inner join graph right_graph on left_graph.dst = right_graph.src
177+
) group by src, dst, src_label, dst_label
178+
) where src = 0 order by dst limit 10;
179+
----
180+
0 0 000 000 4
181+
0 1 000 001 4
182+
0 2 000 002 4
183+
0 3 000 003 4
184+
0 4 000 004 4
185+
0 5 000 005 4
186+
0 6 000 006 4
187+
0 7 000 007 4
188+
0 8 000 008 4
189+
0 9 000 009 4
190+
191+
# In the future, we will construct some custom graphs with different link weight.
192+
# But for now, that's the end of the test!
193+
# TODO: recursive CTE 🤤

0 commit comments

Comments
 (0)