@@ -58,6 +58,38 @@ auto ResultCompare(const std::string &produced_result, const std::string &expect
58
58
return cmp_result;
59
59
}
60
60
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
+
61
93
auto main (int argc, char **argv) -> int { // NOLINT
62
94
argparse::ArgumentParser program (" bustub-sqllogictest" );
63
95
program.add_argument (" file" ).help (" the sqllogictest file to run" );
@@ -116,10 +148,15 @@ auto main(int argc, char **argv) -> int { // NOLINT
116
148
if (verbose) {
117
149
fmt::print (" {}\n " , statement.sql_ );
118
150
if (!statement.extra_options_ .empty ()) {
119
- fmt::print (" {}\n " , statement.extra_options_ );
151
+ fmt::print (" Extra checks: {}\n " , statement.extra_options_ );
120
152
}
121
153
}
122
154
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
+
123
160
std::stringstream result;
124
161
auto writer = bustub::SimpleStreamWriter (result);
125
162
bustub->ExecuteSql (statement.sql_ , writer);
@@ -146,10 +183,15 @@ auto main(int argc, char **argv) -> int { // NOLINT
146
183
if (verbose) {
147
184
fmt::print (" {}\n " , query.sql_ );
148
185
if (!query.extra_options_ .empty ()) {
149
- fmt::print (" {}\n " , query.extra_options_ );
186
+ fmt::print (" Extra checks: {}\n " , query.extra_options_ );
150
187
}
151
188
}
152
189
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
+
153
195
std::stringstream result;
154
196
auto writer = bustub::SimpleStreamWriter (result, true , " " );
155
197
bustub->ExecuteSql (query.sql_ , writer);
0 commit comments