1 | #include "duckdb/storage/checkpoint/table_data_reader.hpp" |
2 | #include "duckdb/storage/checkpoint/table_data_writer.hpp" |
3 | #include "duckdb/storage/meta_block_reader.hpp" |
4 | |
5 | #include "duckdb/common/vector_operations/vector_operations.hpp" |
6 | #include "duckdb/common/types/null_value.hpp" |
7 | |
8 | #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp" |
9 | |
10 | #include "duckdb/planner/parsed_data/bound_create_table_info.hpp" |
11 | |
12 | #include "duckdb/main/database.hpp" |
13 | #include "duckdb/main/client_context.hpp" |
14 | |
15 | using namespace duckdb; |
16 | using namespace std; |
17 | |
18 | TableDataReader::TableDataReader(CheckpointManager &manager, MetaBlockReader &reader, BoundCreateTableInfo &info) |
19 | : manager(manager), reader(reader), info(info) { |
20 | info.data = unique_ptr<vector<unique_ptr<PersistentSegment>>[]>( |
21 | new vector<unique_ptr<PersistentSegment>>[info.Base().columns.size()]); |
22 | } |
23 | |
24 | void TableDataReader::ReadTableData() { |
25 | auto &columns = info.Base().columns; |
26 | assert(columns.size() > 0); |
27 | |
28 | // load the data pointers for the table |
29 | idx_t table_count = 0; |
30 | for (idx_t col = 0; col < columns.size(); col++) { |
31 | auto &column = columns[col]; |
32 | idx_t column_count = 0; |
33 | idx_t data_pointer_count = reader.Read<idx_t>(); |
34 | for (idx_t data_ptr = 0; data_ptr < data_pointer_count; data_ptr++) { |
35 | // read the data pointer |
36 | DataPointer data_pointer; |
37 | data_pointer.min = reader.Read<double>(); |
38 | data_pointer.max = reader.Read<double>(); |
39 | data_pointer.row_start = reader.Read<idx_t>(); |
40 | data_pointer.tuple_count = reader.Read<idx_t>(); |
41 | data_pointer.block_id = reader.Read<block_id_t>(); |
42 | data_pointer.offset = reader.Read<uint32_t>(); |
43 | reader.ReadData(data_pointer.min_stats, 8); |
44 | reader.ReadData(data_pointer.max_stats, 8); |
45 | |
46 | column_count += data_pointer.tuple_count; |
47 | // create a persistent segment |
48 | auto segment = make_unique<PersistentSegment>( |
49 | manager.buffer_manager, data_pointer.block_id, data_pointer.offset, GetInternalType(column.type), |
50 | data_pointer.row_start, data_pointer.tuple_count, data_pointer.min_stats, data_pointer.max_stats); |
51 | info.data[col].push_back(move(segment)); |
52 | } |
53 | if (col == 0) { |
54 | table_count = column_count; |
55 | } else { |
56 | if (table_count != column_count) { |
57 | throw Exception("Column length mismatch in table load!" ); |
58 | } |
59 | } |
60 | } |
61 | } |
62 | |