Skip to content

Commit 5976d77

Browse files
authored
feat(sqllogictest): support check index scan / topn (#437)
Signed-off-by: Alex Chi <[email protected]>
1 parent 083f78e commit 5976d77

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

tools/sqllogictest/sqllogictest.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,38 @@ auto ResultCompare(const std::string &produced_result, const std::string &expect
5858
return cmp_result;
5959
}
6060

61+
auto ProcessExtraOptions(const std::string &sql, bustub::BustubInstance &instance,
62+
const std::vector<std::string> &extra_options, bool verbose) -> bool {
63+
for (const auto &opt : extra_options) {
64+
if (bustub::StringUtil::StartsWith(opt, "ensure:")) {
65+
std::stringstream result;
66+
auto writer = bustub::SimpleStreamWriter(result);
67+
instance.ExecuteSql("explain " + sql, writer);
68+
69+
if (opt == "ensure:index_scan") {
70+
if (!bustub::StringUtil::Contains(result.str(), "IndexScan")) {
71+
fmt::print("IndexScan not found\n");
72+
return false;
73+
}
74+
} else if (opt == "ensure:topn") {
75+
if (!bustub::StringUtil::Contains(result.str(), "TopN")) {
76+
fmt::print("TopN not found\n");
77+
return false;
78+
}
79+
} else {
80+
throw bustub::NotImplementedException(fmt::format("unsupported extra option: {}", opt));
81+
}
82+
} else {
83+
throw bustub::NotImplementedException(fmt::format("unsupported extra option: {}", opt));
84+
}
85+
86+
if (verbose) {
87+
fmt::print("[PASS] extra check: {}\n", opt);
88+
}
89+
}
90+
return true;
91+
}
92+
6193
auto main(int argc, char **argv) -> int { // NOLINT
6294
argparse::ArgumentParser program("bustub-sqllogictest");
6395
program.add_argument("file").help("the sqllogictest file to run");
@@ -116,10 +148,15 @@ auto main(int argc, char **argv) -> int { // NOLINT
116148
if (verbose) {
117149
fmt::print("{}\n", statement.sql_);
118150
if (!statement.extra_options_.empty()) {
119-
fmt::print("{}\n", statement.extra_options_);
151+
fmt::print("Extra checks: {}\n", statement.extra_options_);
120152
}
121153
}
122154
try {
155+
if (!ProcessExtraOptions(statement.sql_, *bustub, statement.extra_options_, verbose)) {
156+
fmt::print("failed to process extra options\n");
157+
return 1;
158+
}
159+
123160
std::stringstream result;
124161
auto writer = bustub::SimpleStreamWriter(result);
125162
bustub->ExecuteSql(statement.sql_, writer);
@@ -146,10 +183,15 @@ auto main(int argc, char **argv) -> int { // NOLINT
146183
if (verbose) {
147184
fmt::print("{}\n", query.sql_);
148185
if (!query.extra_options_.empty()) {
149-
fmt::print("{}\n", query.extra_options_);
186+
fmt::print("Extra checks: {}\n", query.extra_options_);
150187
}
151188
}
152189
try {
190+
if (!ProcessExtraOptions(query.sql_, *bustub, query.extra_options_, verbose)) {
191+
fmt::print("failed to process extra options\n");
192+
return 1;
193+
}
194+
153195
std::stringstream result;
154196
auto writer = bustub::SimpleStreamWriter(result, true, " ");
155197
bustub->ExecuteSql(query.sql_, writer);

0 commit comments

Comments
 (0)