1#include "sqlite_benchmark.hpp"
2
3#include "sqlite_transfer.hpp"
4
5using namespace duckdb;
6using namespace std;
7
8SQLiteBenchmark::SQLiteBenchmark(unique_ptr<DuckDBBenchmark> duckdb)
9 : Benchmark(true, "sqlite_" + duckdb->name, "sqlite_" + duckdb->group), duckdb_benchmark(move(duckdb)) {
10}
11
12unique_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
31void 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
37void SQLiteBenchmark::Cleanup(BenchmarkState *state_) {
38}
39
40string 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
48string SQLiteBenchmark::GetLogOutput(BenchmarkState *state_) {
49 return "";
50}
51
52void SQLiteBenchmark::Interrupt(BenchmarkState *state_) {
53 auto state = (SQLiteBenchmarkState *)state_;
54 state->interrupt = 1;
55}
56
57string SQLiteBenchmark::BenchmarkInfo() {
58 return duckdb_benchmark->BenchmarkInfo();
59}
60