From d844ebb05011de9d647e702c1f50ed5912409b1f Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Tue, 31 Oct 2023 12:12:36 +0000 Subject: [PATCH] Make dry-run output json --- sqlsmith.cc | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/sqlsmith.cc b/sqlsmith.cc index 775e781..c8d3abf 100644 --- a/sqlsmith.cc +++ b/sqlsmith.cc @@ -14,6 +14,7 @@ using boost::regex_match; #include #include +#include #include "random.hh" #include "grammar.hh" @@ -36,6 +37,10 @@ using boost::regex_match; #include "postgres.hh" +#include + +using json = nlohmann::json; + using namespace std; using namespace std::chrono; @@ -181,17 +186,24 @@ int main(int argc, char *argv[]) max_joins = stol(options["max-joins"]); if (options.count("dry-run")) { + assert(options.count("max-queries")); + long max_queries = stol(options["max-queries"]); + json data; + data["version"] = "1.0"; + data["seed"] = options.count("seed") ? stoi(options["seed"]) : getpid(); + data["max-queries"] = max_queries; + data["queries"] = json::array(); while (1) { shared_ptr gen = options.count("explain-only") ? explain_factory(&scope, max_joins) : statement_factory(&scope, max_joins); - gen->out(cout); - for (auto l : loggers) - l->generated(*gen); - cout << ";" << endl; + stringstream s; + gen->out(s); + data["queries"].push_back(s.str()); queries_generated++; - if (options.count("max-queries") - && (queries_generated >= stol(options["max-queries"]))) - return 0; + if (queries_generated >= max_queries) { + std::cout << data.dump() << std::endl; + return 0; + } } }