| 1 | #include "sqlite_benchmark.hpp" |
|---|---|
| 2 | |
| 3 | #include "sqlite_transfer.hpp" |
| 4 | |
| 5 | using namespace duckdb; |
| 6 | using namespace std; |
| 7 | |
| 8 | SQLiteBenchmark::SQLiteBenchmark(unique_ptr<DuckDBBenchmark> duckdb) |
| 9 | : Benchmark(true, "sqlite_"+ duckdb->name, "sqlite_"+ duckdb->group), duckdb_benchmark(move(duckdb)) { |
| 10 | } |
| 11 | |
| 12 | unique_ptr<BenchmarkState> SQLiteBenchmark::Initialize() { |
| 13 | auto sqlite_state = make_unique<SQLiteBenchmarkState>(); |
| 14 | // first load the data into DuckDB |
| 15 | auto duckdb_benchmark_state = duckdb_benchmark->Initialize(); |
| 16 | auto &duckdb_state = (DuckDBBenchmarkState &)*duckdb_benchmark_state; |
| 17 | if (sqlite3_open(":memory:", &sqlite_state->db) != SQLITE_OK) { |
| 18 | return nullptr; |
| 19 | } |
| 20 | // then transfer the data to SQLite |
| 21 | sqlite::TransferDatabase(duckdb_state.conn, sqlite_state->db); |
| 22 | // get the types of the query |
| 23 | auto duckdb_result = duckdb_state.conn.Query(duckdb_benchmark->GetQuery()); |
| 24 | if (!duckdb_result->success) { |
| 25 | return nullptr; |
| 26 | } |
| 27 | sqlite_state->types = duckdb_result->sql_types; |
| 28 | return move(sqlite_state); |
| 29 | } |
| 30 | |
| 31 | void SQLiteBenchmark::Run(BenchmarkState *state_) { |
| 32 | auto state = (SQLiteBenchmarkState *)state_; |
| 33 | auto query = duckdb_benchmark->GetQuery(); |
| 34 | state->result = sqlite::QueryDatabase(state->types, state->db, query, state->interrupt); |
| 35 | } |
| 36 | |
| 37 | void SQLiteBenchmark::Cleanup(BenchmarkState *state_) { |
| 38 | } |
| 39 | |
| 40 | string SQLiteBenchmark::Verify(BenchmarkState *state_) { |
| 41 | auto state = (SQLiteBenchmarkState *)state_; |
| 42 | if (!state->result) { |
| 43 | return "No result!"; |
| 44 | } |
| 45 | return duckdb_benchmark->VerifyResult(state->result.get()); |
| 46 | } |
| 47 | |
| 48 | string SQLiteBenchmark::GetLogOutput(BenchmarkState *state_) { |
| 49 | return ""; |
| 50 | } |
| 51 | |
| 52 | void SQLiteBenchmark::Interrupt(BenchmarkState *state_) { |
| 53 | auto state = (SQLiteBenchmarkState *)state_; |
| 54 | state->interrupt = 1; |
| 55 | } |
| 56 | |
| 57 | string SQLiteBenchmark::BenchmarkInfo() { |
| 58 | return duckdb_benchmark->BenchmarkInfo(); |
| 59 | } |
| 60 |