1#include "benchmark_runner.hpp"
2#include "compare_result.hpp"
3#include "dbgen.hpp"
4#include "duckdb_benchmark_macro.hpp"
5
6using namespace duckdb;
7using namespace std;
8
9#define SF 0.1
10
11DUCKDB_BENCHMARK(ReadLineitemCSV, "[csv]")
12int64_t count = 0;
13void Load(DuckDBBenchmarkState *state) override {
14 // load the data into the tpch schema
15 state->conn.Query("CREATE SCHEMA tpch");
16 tpch::dbgen(SF, state->db, "tpch");
17 // create the CSV file
18 auto result = state->conn.Query("COPY tpch.lineitem TO 'lineitem.csv' DELIMITER '|' HEADER");
19 assert(result->success);
20 count = result->collection.chunks[0]->GetValue(0, 0).GetValue<int64_t>();
21 // delete the database
22 state->conn.Query("DROP SCHEMA tpch CASCADE");
23 // create the empty schema to load into
24 tpch::dbgen(0, state->db);
25}
26string GetQuery() override {
27 return "COPY lineitem FROM 'lineitem.csv' DELIMITER '|' HEADER";
28}
29void Cleanup(DuckDBBenchmarkState *state) override {
30 state->conn.Query("DROP TABLE lineitem");
31 tpch::dbgen(0, state->db);
32}
33string VerifyResult(QueryResult *result) override {
34 if (!result->success) {
35 return result->error;
36 }
37 auto &materialized = (MaterializedQueryResult &)*result;
38 auto expected_count = materialized.collection.chunks[0]->GetValue(0, 0).GetValue<int64_t>();
39 if (expected_count != count) {
40 return StringUtil::Format("Count mismatch, expected %lld elements but got %lld", count, expected_count);
41 }
42 return string();
43}
44string BenchmarkInfo() override {
45 return "Read the lineitem table from SF 0.1 from CSV format";
46}
47FINISH_BENCHMARK(ReadLineitemCSV)
48
49DUCKDB_BENCHMARK(ReadLineitemCSVUnicode, "[csv]")
50int64_t count = 0;
51void Load(DuckDBBenchmarkState *state) override {
52 // load the data into the tpch schema
53 state->conn.Query("CREATE SCHEMA tpch");
54 tpch::dbgen(SF, state->db, "tpch");
55 // create the CSV file
56 auto result = state->conn.Query("COPY tpch.lineitem TO 'lineitem_unicode.csv' DELIMITER '🦆' HEADER");
57 assert(result->success);
58 count = result->collection.chunks[0]->GetValue(0, 0).GetValue<int64_t>();
59 // delete the database
60 state->conn.Query("DROP SCHEMA tpch CASCADE");
61 // create the empty schema to load into
62 tpch::dbgen(0, state->db);
63}
64string GetQuery() override {
65 return "COPY lineitem FROM 'lineitem_unicode.csv' DELIMITER '🦆' HEADER";
66}
67void Cleanup(DuckDBBenchmarkState *state) override {
68 state->conn.Query("DROP TABLE lineitem");
69 tpch::dbgen(0, state->db);
70}
71string VerifyResult(QueryResult *result) override {
72 if (!result->success) {
73 return result->error;
74 }
75 auto &materialized = (MaterializedQueryResult &)*result;
76 auto expected_count = materialized.collection.chunks[0]->GetValue(0, 0).GetValue<int64_t>();
77 if (expected_count != count) {
78 return StringUtil::Format("Count mismatch, expected %lld elements but got %lld", count, expected_count);
79 }
80 return string();
81}
82string BenchmarkInfo() override {
83 return "Read the lineitem table from SF 0.1 from CSV format";
84}
85FINISH_BENCHMARK(ReadLineitemCSVUnicode)
86
87DUCKDB_BENCHMARK(WriteLineitemCSV, "[csv]")
88void Load(DuckDBBenchmarkState *state) override {
89 // load the data into the tpch schema
90 tpch::dbgen(SF, state->db);
91}
92string GetQuery() override {
93 return "COPY lineitem TO 'lineitem.csv' DELIMITER '|' HEADER";
94}
95string VerifyResult(QueryResult *result) override {
96 if (!result->success) {
97 return result->error;
98 }
99 return string();
100}
101string BenchmarkInfo() override {
102 return "Write the lineitem table from SF 0.1 to CSV format";
103}
104FINISH_BENCHMARK(WriteLineitemCSV)
105