46 static Result<std::shared_ptr<UpdatePartitionSpec>> Make(
47 std::shared_ptr<TransactionContext> ctx);
69 std::string_view part_name =
"");
101 Kind
kind() const final {
return Kind::kUpdatePartitionSpec; }
111 std::shared_ptr<PartitionSpec> spec;
114 Result<ApplyResult> Apply();
120 using TransformKey = std::pair<int32_t, std::string>;
123 struct TransformKeyHash {
124 size_t operator()(
const TransformKey& key)
const {
125 return 31 * std::hash<int32_t>{}(key.first) + std::hash<std::string>{}(key.second);
130 int32_t AssignFieldId();
142 PartitionField RecycleOrCreatePartitionField(int32_t source_id,
143 std::shared_ptr<Transform> transform,
144 std::string_view name);
147 UpdatePartitionSpec& AddFieldInternal(std::string_view name, int32_t source_id,
148 const std::shared_ptr<Transform>& transform);
151 Result<std::string> GeneratePartitionName(
152 int32_t source_id,
const std::shared_ptr<Transform>& transform)
const;
155 static bool IsTimeTransform(
const std::shared_ptr<Transform>& transform);
158 static bool IsVoidTransform(
const PartitionField& field);
161 void CheckForRedundantAddedPartitions(
const PartitionField& field);
164 UpdatePartitionSpec& RewriteDeleteAndAddField(
const PartitionField& existing,
165 std::string_view name);
168 UpdatePartitionSpec& RemoveFieldByTransform(
const TransformKey& key,
169 std::string_view term_str);
172 static std::unordered_map<std::string, const PartitionField*, StringHash, StringEqual>
173 IndexSpecByName(
const PartitionSpec& spec);
176 static std::unordered_map<TransformKey, const PartitionField*, TransformKeyHash>
177 IndexSpecByTransform(
const PartitionSpec& spec);
180 void BuildHistoricalFieldsIndex();
183 int32_t format_version_;
184 std::shared_ptr<PartitionSpec> spec_;
185 std::shared_ptr<Schema> schema_;
186 bool case_sensitive_{
true};
187 bool set_as_default_{
true};
188 int32_t last_assigned_partition_id_;
191 std::unordered_map<std::string, const PartitionField*, StringHash, StringEqual>
193 std::unordered_map<TransformKey, const PartitionField*, TransformKeyHash>
198 std::unordered_map<TransformKey, PartitionField, TransformKeyHash> historical_fields_;
201 std::vector<PartitionField> adds_;
202 std::unordered_set<std::string, StringHash, StringEqual> added_field_names_;
203 std::unordered_map<int32_t, std::string> added_time_fields_;
204 std::unordered_map<TransformKey, std::string, TransformKeyHash>
205 transform_to_added_field_;
206 std::unordered_set<int32_t> deletes_;
207 std::unordered_map<std::string, std::string, StringHash, StringEqual> renames_;