|
18 | 18 | //! This module contains transaction api.
|
19 | 19 |
|
20 | 20 | mod append;
|
| 21 | +mod rewrite_manifest; |
| 22 | +pub use rewrite_manifest::{ |
| 23 | + CREATED_MANIFESTS_COUNT, KEPT_MANIFESTS_COUNT, PROCESSED_ENTRY_COUNT, REPLACED_MANIFESTS_COUNT, |
| 24 | +}; |
21 | 25 | mod snapshot;
|
22 | 26 | mod sort_order;
|
23 | 27 |
|
24 | 28 | use std::cmp::Ordering;
|
25 | 29 | use std::collections::HashMap;
|
| 30 | +use std::hash::Hash; |
26 | 31 | use std::mem::discriminant;
|
27 | 32 | use std::sync::Arc;
|
28 | 33 |
|
| 34 | +use rewrite_manifest::{ClusterFunc, PredicateFunc, RewriteManifsetAction}; |
29 | 35 | use uuid::Uuid;
|
30 | 36 |
|
31 | 37 | use crate::error::Result;
|
@@ -166,6 +172,42 @@ impl<'a> Transaction<'a> {
|
166 | 172 | )
|
167 | 173 | }
|
168 | 174 |
|
| 175 | + /// Rewrite manifest file. |
| 176 | + pub fn rewrite_manifest<T: Hash + Eq>( |
| 177 | + self, |
| 178 | + cluster_by_func: Option<ClusterFunc<T>>, |
| 179 | + manifest_predicate: Option<PredicateFunc>, |
| 180 | + snapshot_id: Option<i64>, |
| 181 | + commit_uuid: Option<Uuid>, |
| 182 | + key_metadata: Vec<u8>, |
| 183 | + ) -> Result<RewriteManifsetAction<'a, T>> { |
| 184 | + let snapshot_id = if let Some(snapshot_id) = snapshot_id { |
| 185 | + if self |
| 186 | + .current_table |
| 187 | + .metadata() |
| 188 | + .snapshots() |
| 189 | + .any(|s| s.snapshot_id() == snapshot_id) |
| 190 | + { |
| 191 | + return Err(Error::new( |
| 192 | + ErrorKind::DataInvalid, |
| 193 | + format!("Snapshot id {} already exists", snapshot_id), |
| 194 | + )); |
| 195 | + } |
| 196 | + snapshot_id |
| 197 | + } else { |
| 198 | + self.generate_unique_snapshot_id() |
| 199 | + }; |
| 200 | + RewriteManifsetAction::new( |
| 201 | + self, |
| 202 | + cluster_by_func, |
| 203 | + manifest_predicate, |
| 204 | + snapshot_id, |
| 205 | + commit_uuid.unwrap_or_else(Uuid::now_v7), |
| 206 | + key_metadata, |
| 207 | + HashMap::new(), |
| 208 | + ) |
| 209 | + } |
| 210 | + |
169 | 211 | /// Creates replace sort order action.
|
170 | 212 | pub fn replace_sort_order(self) -> ReplaceSortOrderAction<'a> {
|
171 | 213 | ReplaceSortOrderAction {
|
|
0 commit comments