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 | | #include "common/compile_check_begin.h" |
27 | | |
28 | | class StructLike; |
29 | | class Schema; |
30 | | |
31 | | class PartitionField { |
32 | | public: |
33 | | PartitionField(int sourceId, int fieldId, std::string name, std::string transform); |
34 | | |
35 | 0 | int source_id() const { return _source_id; } |
36 | | |
37 | 4 | int field_id() const { return _field_id; } |
38 | | |
39 | 0 | const std::string& name() const { return _name; } |
40 | | |
41 | 0 | const std::string& transform() const { return _transform; } |
42 | | |
43 | | private: |
44 | | int _source_id; |
45 | | int _field_id; |
46 | | std::string _name; |
47 | | std::string _transform; |
48 | | }; |
49 | | |
50 | | class PartitionSpec { |
51 | | public: |
52 | | class Builder { |
53 | | public: |
54 | | Builder(std::shared_ptr<Schema> schema); |
55 | | |
56 | 2 | ~Builder() = default; |
57 | | |
58 | | Builder& with_spec_id(int new_spec_id); |
59 | | |
60 | | Builder& add(int sourceId, int fieldId, std::string name, std::string transform); |
61 | | |
62 | | Builder& add(int sourceId, std::string name, std::string transform); |
63 | | |
64 | | std::unique_ptr<PartitionSpec> build(); |
65 | | |
66 | | private: |
67 | 2 | int next_field_id() { return ++_last_assigned_field_id; } |
68 | | |
69 | | private: |
70 | | std::shared_ptr<Schema> _schema; |
71 | | std::vector<PartitionField> _fields; |
72 | | int _spec_id; |
73 | | std::atomic<int> _last_assigned_field_id; |
74 | | }; |
75 | | |
76 | | PartitionSpec(std::shared_ptr<Schema> schema, int spec_id, std::vector<PartitionField> fields, |
77 | | int last_assigned_field_id); |
78 | | |
79 | 0 | const Schema& schema() const { return *_schema; } |
80 | | |
81 | 0 | int spec_id() const { return _spec_id; } |
82 | | |
83 | 6 | const std::vector<PartitionField>& fields() const { return _fields; } |
84 | | |
85 | 0 | int last_assigned_field_id() const { return _last_assigned_field_id; } |
86 | | |
87 | | private: |
88 | | // IDs for partition fields start at 1000 |
89 | | static constexpr int PARTITION_DATA_ID_START = 1000; |
90 | | std::shared_ptr<Schema> _schema; |
91 | | int _spec_id; |
92 | | std::vector<PartitionField> _fields; |
93 | | int _last_assigned_field_id; |
94 | | }; |
95 | | |
96 | | #include "common/compile_check_end.h" |
97 | | } // namespace doris::iceberg |