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