1 | #include "duckdb/planner/operator/logical_column_data_get.hpp" |
2 | |
3 | #include "duckdb/common/field_writer.hpp" |
4 | #include "duckdb/common/types/data_chunk.hpp" |
5 | #include "duckdb/main/config.hpp" |
6 | |
7 | namespace duckdb { |
8 | |
9 | LogicalColumnDataGet::LogicalColumnDataGet(idx_t table_index, vector<LogicalType> types, |
10 | unique_ptr<ColumnDataCollection> collection) |
11 | : LogicalOperator(LogicalOperatorType::LOGICAL_CHUNK_GET), table_index(table_index), |
12 | collection(std::move(collection)) { |
13 | D_ASSERT(types.size() > 0); |
14 | chunk_types = std::move(types); |
15 | } |
16 | |
17 | vector<ColumnBinding> LogicalColumnDataGet::GetColumnBindings() { |
18 | return GenerateColumnBindings(table_idx: table_index, column_count: chunk_types.size()); |
19 | } |
20 | |
21 | void LogicalColumnDataGet::Serialize(FieldWriter &writer) const { |
22 | writer.WriteField(element: table_index); |
23 | writer.WriteRegularSerializableList(elements: chunk_types); |
24 | writer.WriteField(element: collection->ChunkCount()); |
25 | for (auto &chunk : collection->Chunks()) { |
26 | chunk.Serialize(serializer&: writer.GetSerializer()); |
27 | } |
28 | } |
29 | |
30 | unique_ptr<LogicalOperator> LogicalColumnDataGet::Deserialize(LogicalDeserializationState &state, FieldReader &reader) { |
31 | auto table_index = reader.ReadRequired<idx_t>(); |
32 | auto chunk_types = reader.ReadRequiredSerializableList<LogicalType, LogicalType>(); |
33 | auto chunk_count = reader.ReadRequired<idx_t>(); |
34 | auto collection = make_uniq<ColumnDataCollection>(args&: state.gstate.context, args&: chunk_types); |
35 | for (idx_t i = 0; i < chunk_count; i++) { |
36 | DataChunk chunk; |
37 | chunk.Deserialize(source&: reader.GetSource()); |
38 | collection->Append(new_chunk&: chunk); |
39 | } |
40 | return make_uniq<LogicalColumnDataGet>(args&: table_index, args: std::move(chunk_types), args: std::move(collection)); |
41 | } |
42 | |
43 | vector<idx_t> LogicalColumnDataGet::GetTableIndex() const { |
44 | return vector<idx_t> {table_index}; |
45 | } |
46 | |
47 | string LogicalColumnDataGet::GetName() const { |
48 | #ifdef DEBUG |
49 | if (DBConfigOptions::debug_print_bindings) { |
50 | return LogicalOperator::GetName() + StringUtil::Format(" #%llu" , table_index); |
51 | } |
52 | #endif |
53 | return LogicalOperator::GetName(); |
54 | } |
55 | |
56 | } // namespace duckdb |
57 | |