be/src/format/table/iceberg/partition_spec.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <atomic> |
21 | | #include <memory> |
22 | | #include <string> |
23 | | #include <vector> |
24 | | |
25 | | namespace doris::iceberg { |
26 | | |
27 | | class StructLike; |
28 | | class Schema; |
29 | | |
30 | | class PartitionField { |
31 | | public: |
32 | | PartitionField(int sourceId, int fieldId, std::string name, std::string transform); |
33 | | |
34 | 0 | int source_id() const { return _source_id; } |
35 | | |
36 | 4 | int field_id() const { return _field_id; } |
37 | | |
38 | 0 | const std::string& name() const { return _name; } |
39 | | |
40 | 2 | const std::string& transform() const { return _transform; } |
41 | | |
42 | | private: |
43 | | int _source_id; |
44 | | int _field_id; |
45 | | std::string _name; |
46 | | std::string _transform; |
47 | | }; |
48 | | |
49 | | class PartitionSpec { |
50 | | public: |
51 | | class Builder { |
52 | | public: |
53 | | Builder(std::shared_ptr<Schema> schema); |
54 | | |
55 | 2 | ~Builder() = default; |
56 | | |
57 | | Builder& with_spec_id(int new_spec_id); |
58 | | |
59 | | Builder& add(int sourceId, int fieldId, std::string name, std::string transform); |
60 | | |
61 | | Builder& add(int sourceId, std::string name, std::string transform); |
62 | | |
63 | | std::unique_ptr<PartitionSpec> build(); |
64 | | |
65 | | private: |
66 | 2 | int next_field_id() { return ++_last_assigned_field_id; } |
67 | | |
68 | | private: |
69 | | std::shared_ptr<Schema> _schema; |
70 | | std::vector<PartitionField> _fields; |
71 | | int _spec_id; |
72 | | std::atomic<int> _last_assigned_field_id; |
73 | | }; |
74 | | |
75 | | PartitionSpec(std::shared_ptr<Schema> schema, int spec_id, std::vector<PartitionField> fields, |
76 | | int last_assigned_field_id); |
77 | | |
78 | 0 | const Schema& schema() const { return *_schema; } |
79 | | |
80 | 0 | int spec_id() const { return _spec_id; } |
81 | | |
82 | 6 | const std::vector<PartitionField>& fields() const { return _fields; } |
83 | | |
84 | 0 | int last_assigned_field_id() const { return _last_assigned_field_id; } |
85 | | |
86 | | private: |
87 | | // IDs for partition fields start at 1000 |
88 | | static constexpr int PARTITION_DATA_ID_START = 1000; |
89 | | std::shared_ptr<Schema> _schema; |
90 | | int _spec_id; |
91 | | std::vector<PartitionField> _fields; |
92 | | int _last_assigned_field_id; |
93 | | }; |
94 | | |
95 | | } // namespace doris::iceberg |