1#include "catch.hpp"
2#include "duckdb/common/file_system.hpp"
3#include "dbgen.hpp"
4#include "test_helpers.hpp"
5
6using namespace duckdb;
7using namespace std;
8
9TEST_CASE("Test storing TPC-H", "[storage][.]") {
10 unique_ptr<QueryResult> result;
11 double sf = 0.1;
12 auto storage_database = TestCreatePath("storage_tpch");
13 auto config = GetTestConfig();
14
15 // make sure the database does not exist
16 DeleteDatabase(storage_database);
17 {
18 // create a database and insert TPC-H tables
19 DuckDB db(storage_database, config.get());
20 // generate the TPC-H data for SF 0.1
21 tpch::dbgen(sf, db);
22 }
23 // reload the database from disk
24 {
25 DuckDB db(storage_database, config.get());
26 Connection con(db);
27 // check if all the counts are correct
28 result = con.Query("SELECT COUNT(*) FROM orders");
29 REQUIRE(CHECK_COLUMN(result, 0, {150000}));
30 result = con.Query("SELECT COUNT(*) FROM lineitem");
31 REQUIRE(CHECK_COLUMN(result, 0, {600572}));
32 result = con.Query("SELECT COUNT(*) FROM part");
33 REQUIRE(CHECK_COLUMN(result, 0, {20000}));
34 result = con.Query("SELECT COUNT(*) FROM partsupp");
35 REQUIRE(CHECK_COLUMN(result, 0, {80000}));
36 result = con.Query("SELECT COUNT(*) FROM supplier");
37 REQUIRE(CHECK_COLUMN(result, 0, {1000}));
38 result = con.Query("SELECT COUNT(*) FROM customer");
39 REQUIRE(CHECK_COLUMN(result, 0, {15000}));
40 result = con.Query("SELECT COUNT(*) FROM nation");
41 REQUIRE(CHECK_COLUMN(result, 0, {25}));
42 result = con.Query("SELECT COUNT(*) FROM region");
43 REQUIRE(CHECK_COLUMN(result, 0, {5}));
44 }
45 // reload the database from disk again
46 {
47 DuckDB db(storage_database, config.get());
48 Connection con(db);
49 // check if all the counts are correct
50 result = con.Query("SELECT COUNT(*) FROM orders");
51 REQUIRE(CHECK_COLUMN(result, 0, {150000}));
52 result = con.Query("SELECT COUNT(*) FROM lineitem");
53 REQUIRE(CHECK_COLUMN(result, 0, {600572}));
54 result = con.Query("SELECT COUNT(*) FROM part");
55 REQUIRE(CHECK_COLUMN(result, 0, {20000}));
56 result = con.Query("SELECT COUNT(*) FROM partsupp");
57 REQUIRE(CHECK_COLUMN(result, 0, {80000}));
58 result = con.Query("SELECT COUNT(*) FROM supplier");
59 REQUIRE(CHECK_COLUMN(result, 0, {1000}));
60 result = con.Query("SELECT COUNT(*) FROM customer");
61 REQUIRE(CHECK_COLUMN(result, 0, {15000}));
62 result = con.Query("SELECT COUNT(*) FROM nation");
63 REQUIRE(CHECK_COLUMN(result, 0, {25}));
64 result = con.Query("SELECT COUNT(*) FROM region");
65 REQUIRE(CHECK_COLUMN(result, 0, {5}));
66 }
67 // reload the database from disk again
68 {
69 DuckDB db(storage_database, config.get());
70 Connection con(db);
71 // check if all the counts are correct
72 result = con.Query("SELECT COUNT(*) FROM orders");
73 REQUIRE(CHECK_COLUMN(result, 0, {150000}));
74 result = con.Query("SELECT COUNT(*) FROM lineitem");
75 REQUIRE(CHECK_COLUMN(result, 0, {600572}));
76 result = con.Query("SELECT COUNT(*) FROM part");
77 REQUIRE(CHECK_COLUMN(result, 0, {20000}));
78 result = con.Query("SELECT COUNT(*) FROM partsupp");
79 REQUIRE(CHECK_COLUMN(result, 0, {80000}));
80 result = con.Query("SELECT COUNT(*) FROM supplier");
81 REQUIRE(CHECK_COLUMN(result, 0, {1000}));
82 result = con.Query("SELECT COUNT(*) FROM customer");
83 REQUIRE(CHECK_COLUMN(result, 0, {15000}));
84 result = con.Query("SELECT COUNT(*) FROM nation");
85 REQUIRE(CHECK_COLUMN(result, 0, {25}));
86 result = con.Query("SELECT COUNT(*) FROM region");
87 REQUIRE(CHECK_COLUMN(result, 0, {5}));
88 }
89 DeleteDatabase(storage_database);
90}
91