MCPcopy Create free account
hub / github.com/duckdb/duckdb / ProcessFile

Method ProcessFile

benchmark/interpreted_benchmark.cpp:170–465  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168}
169
170void InterpretedBenchmark::ProcessFile(const string &path) {
171 BenchmarkFileReader reader(path, replacement_mapping);
172 string line;
173 while (reader.ReadLine(line)) {
174 // skip blank lines and comments
175 if (line.empty() || line[0] == '#') {
176 continue;
177 }
178 // look for a command in this line
179 auto splits = StringUtil::Split(StringUtil::Lower(line), ' ');
180 if (splits[0] == "load" || splits[0] == "run" || splits[0] == "init" || splits[0] == "cleanup" ||
181 splits[0] == "reload") {
182 if (queries.find(splits[0]) != queries.end()) {
183 throw std::runtime_error("Multiple calls to " + splits[0] + " in the same benchmark file");
184 }
185
186 // load command: keep reading until we find a blank line or EOF
187 string query;
188 while (reader.ReadLine(line)) {
189 if (line.empty()) {
190 break;
191 } else {
192 query += line + " ";
193 }
194 }
195 if (splits.size() > 1 && !splits[1].empty()) {
196 // read entire file into query
197 std::ifstream file(splits[1], std::ios::ate);
198 std::streamsize size = file.tellg();
199 file.seekg(0, std::ios::beg);
200 if (size < 0) {
201 throw std::runtime_error("Failed to read " + splits[0] + " from file " + splits[1]);
202 }
203
204 auto buffer = make_unsafe_uniq_array<char>(size);
205 if (!file.read(buffer.get(), size)) {
206 throw std::runtime_error("Failed to read " + splits[0] + " from file " + splits[1]);
207 }
208 query = string(buffer.get(), size);
209 }
210 StringUtil::Trim(query);
211 if (query.empty()) {
212 throw std::runtime_error("Encountered an empty " + splits[0] + " node!");
213 }
214 queries[splits[0]] = query;
215 } else if (splits[0] == "require") {
216 if (splits.size() < 2 || splits.size() > 3) {
217 throw std::runtime_error(reader.FormatException("require requires a single parameter"));
218 }
219 if (splits.size() == 3) {
220 if (splits[2] != "load_only") {
221 throw std::runtime_error(
222 reader.FormatException("require only supports load_only as a second parameter"));
223 }
224 AddExtension(splits[1], true);
225 } else {
226 AddExtension(splits[1], false);
227 }

Callers

nothing calls this directly

Calls 15

ThrowResultModeErrorFunction · 0.85
ProcessReplacementsFunction · 0.85
ContainsFunction · 0.85
ProcessFileFunction · 0.85
ReadLineMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
readMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected