1 | #include "catch.hpp" |
2 | #include "duckdb/common/file_system.hpp" |
3 | #include "test_helpers.hpp" |
4 | #include "duckdb/storage/storage_info.hpp" |
5 | |
6 | #include <fstream> |
7 | |
8 | using namespace duckdb; |
9 | using namespace std; |
10 | |
11 | TEST_CASE("Test repeated load and checkpoint of storage" , "[storage][.]" ) { |
12 | unique_ptr<MaterializedQueryResult> result; |
13 | auto storage_database = TestCreatePath("repeated_load" ); |
14 | auto csv_file = TestCreatePath("rload.csv" ); |
15 | auto config = GetTestConfig(); |
16 | |
17 | vector<string> model{"M11" , "F22" , "U33" }; |
18 | vector<string> shop{"www.goodshop.com" , "www.badshop.com" }; |
19 | vector<string> name{"Electronics Something One" , "Electronics Something Two" , |
20 | "Electronics Something Three" , "Electronics Something Four" , |
21 | "Electronics Something Five" , "Electronics Something Six" , |
22 | "Electronics Something Seven" , "Electronics Something Eight" , |
23 | "Electronics Something Nine" , "Electronics Something Ten" }; |
24 | vector<string> brand{"AAAAA" , "BBBBB" , "CCCC" , "DDDDDD" , "PPPP" }; |
25 | vector<string> color{"violet" , "indigo" , "blue" , "green" , "yellow" , "orange" , "red" }; |
26 | idx_t row_count = 1000; |
27 | |
28 | DeleteDatabase(storage_database); |
29 | for (idx_t counter = 0; counter < 100; counter++) { |
30 | DuckDB db(storage_database); |
31 | Connection con(db); |
32 | |
33 | if (counter > 0) { |
34 | result = con.Query("SELECT COUNT(*) FROM pdata" ); |
35 | REQUIRE(CHECK_COLUMN(result, 0, {Value::BIGINT(counter * row_count)})); |
36 | } |
37 | // generate the csv file |
38 | ofstream csv_writer(csv_file); |
39 | for (idx_t i = 0; i < row_count; i++) { |
40 | idx_t z = i + counter; |
41 | idx_t record_id = i + (row_count * counter); |
42 | csv_writer << record_id << "|" ; |
43 | csv_writer << i % 99 << "|" ; |
44 | csv_writer << shop[z % 2] << "|" ; |
45 | csv_writer << "electronics" |
46 | << "|" ; |
47 | csv_writer << name[z % 10] << "|" ; |
48 | csv_writer << brand[z % 5] << "|" ; |
49 | csv_writer << color[z % 7] << "|" ; |
50 | csv_writer << model[z % 3] << "|" ; |
51 | csv_writer << "\n" ; |
52 | } |
53 | csv_writer.close(); |
54 | // create and load the table |
55 | REQUIRE_NO_FAIL( |
56 | con.Query("CREATE TABLE IF NOT EXISTS pdata (record_id BIGINT PRIMARY KEY , price DOUBLE, shop VARCHAR, " |
57 | "category VARCHAR, name VARCHAR, brand VARCHAR, color VARCHAR, model VARCHAR);" )); |
58 | REQUIRE_NO_FAIL(con.Query("COPY pdata(record_id,price,shop,category,name,brand,color,model) FROM '" + csv_file + |
59 | "' ( DELIMITER '|' );" )); |
60 | result = con.Query("SELECT MIN(record_id), MIN(price), MIN(shop), MIN(category), MIN(name), MIN(brand), " |
61 | "MIN(color), MIN(model) FROM pdata" ); |
62 | REQUIRE(CHECK_COLUMN(result, 0, {0})); |
63 | REQUIRE(CHECK_COLUMN(result, 1, {0})); |
64 | REQUIRE(CHECK_COLUMN(result, 2, {"www.badshop.com" })); |
65 | REQUIRE(CHECK_COLUMN(result, 3, {"electronics" })); |
66 | REQUIRE(CHECK_COLUMN(result, 4, {"Electronics Something Eight" })); |
67 | REQUIRE(CHECK_COLUMN(result, 5, {"AAAAA" })); |
68 | REQUIRE(CHECK_COLUMN(result, 6, {"blue" })); |
69 | REQUIRE(CHECK_COLUMN(result, 7, {"F22" })); |
70 | |
71 | result = con.Query("SELECT COUNT(*) FROM pdata" ); |
72 | REQUIRE(CHECK_COLUMN(result, 0, {Value::BIGINT((counter + 1) * row_count)})); |
73 | } |
74 | } |
75 | |