| 1 | #include "benchmark_runner.hpp" |
| 2 | #include "compare_result.hpp" |
| 3 | #include "dbgen.hpp" |
| 4 | #include "duckdb_benchmark_macro.hpp" |
| 5 | |
| 6 | using namespace duckdb; |
| 7 | using namespace std; |
| 8 | |
| 9 | #define SF 0.1 |
| 10 | |
| 11 | DUCKDB_BENCHMARK(ReadLineitemCSV, "[csv]" ) |
| 12 | int64_t count = 0; |
| 13 | void 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 | } |
| 26 | string GetQuery() override { |
| 27 | return "COPY lineitem FROM 'lineitem.csv' DELIMITER '|' HEADER" ; |
| 28 | } |
| 29 | void Cleanup(DuckDBBenchmarkState *state) override { |
| 30 | state->conn.Query("DROP TABLE lineitem" ); |
| 31 | tpch::dbgen(0, state->db); |
| 32 | } |
| 33 | string 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 | } |
| 44 | string BenchmarkInfo() override { |
| 45 | return "Read the lineitem table from SF 0.1 from CSV format" ; |
| 46 | } |
| 47 | FINISH_BENCHMARK(ReadLineitemCSV) |
| 48 | |
| 49 | DUCKDB_BENCHMARK(ReadLineitemCSVUnicode, "[csv]" ) |
| 50 | int64_t count = 0; |
| 51 | void 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 | } |
| 64 | string GetQuery() override { |
| 65 | return "COPY lineitem FROM 'lineitem_unicode.csv' DELIMITER '🦆' HEADER" ; |
| 66 | } |
| 67 | void Cleanup(DuckDBBenchmarkState *state) override { |
| 68 | state->conn.Query("DROP TABLE lineitem" ); |
| 69 | tpch::dbgen(0, state->db); |
| 70 | } |
| 71 | string 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 | } |
| 82 | string BenchmarkInfo() override { |
| 83 | return "Read the lineitem table from SF 0.1 from CSV format" ; |
| 84 | } |
| 85 | FINISH_BENCHMARK(ReadLineitemCSVUnicode) |
| 86 | |
| 87 | DUCKDB_BENCHMARK(WriteLineitemCSV, "[csv]" ) |
| 88 | void Load(DuckDBBenchmarkState *state) override { |
| 89 | // load the data into the tpch schema |
| 90 | tpch::dbgen(SF, state->db); |
| 91 | } |
| 92 | string GetQuery() override { |
| 93 | return "COPY lineitem TO 'lineitem.csv' DELIMITER '|' HEADER" ; |
| 94 | } |
| 95 | string VerifyResult(QueryResult *result) override { |
| 96 | if (!result->success) { |
| 97 | return result->error; |
| 98 | } |
| 99 | return string(); |
| 100 | } |
| 101 | string BenchmarkInfo() override { |
| 102 | return "Write the lineitem table from SF 0.1 to CSV format" ; |
| 103 | } |
| 104 | FINISH_BENCHMARK(WriteLineitemCSV) |
| 105 | |