|
5 | 5 | //! |
6 | 6 | //! The data structures and table-format logic live in |
7 | 7 | //! [`lance_table::system_index::frag_reuse`]; this module re-exports them and |
8 | | -//! the lance-table crate implements the [`Index`] and [`RowIdRemapper`] traits |
9 | | -//! for [`FragReuseIndex`] via lance-index-core. |
| 8 | +//! provides newtype wrappers that implement the [`Index`] and [`RowIdRemapper`] |
| 9 | +//! traits. |
| 10 | +
|
| 11 | +use std::any::Any; |
| 12 | +use std::sync::Arc; |
| 13 | + |
| 14 | +use arrow_array::RecordBatch; |
| 15 | +use async_trait::async_trait; |
| 16 | +use lance_core::deepsize::DeepSizeOf; |
| 17 | +use lance_core::Result; |
| 18 | +use lance_select::RowAddrTreeMap; |
| 19 | +use roaring::{RoaringBitmap, RoaringTreemap}; |
| 20 | +use serde::Serialize; |
10 | 21 |
|
11 | 22 | pub use lance_table::system_index::frag_reuse::*; |
| 23 | + |
| 24 | +use crate::scalar::RowIdRemapper; |
| 25 | +use crate::{Index, IndexType}; |
| 26 | + |
| 27 | +/// Newtype wrapping [`FragReuseIndex`] so that `lance-index` can implement |
| 28 | +/// the `Index` and `RowIdRemapper` traits (orphan rules prevent implementing |
| 29 | +/// them directly in `lance-table`). |
| 30 | +pub struct FragReuseIndexHandle(pub Arc<FragReuseIndex>); |
| 31 | + |
| 32 | +impl std::fmt::Debug for FragReuseIndexHandle { |
| 33 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 34 | + f.debug_tuple("FragReuseIndexHandle").field(&self.0).finish() |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +impl DeepSizeOf for FragReuseIndexHandle { |
| 39 | + fn deep_size_of_children(&self, context: &mut lance_core::deepsize::Context) -> usize { |
| 40 | + self.0.deep_size_of_children(context) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +#[derive(Serialize)] |
| 45 | +struct FragReuseStatistics { |
| 46 | + num_versions: usize, |
| 47 | +} |
| 48 | + |
| 49 | +#[async_trait] |
| 50 | +impl Index for FragReuseIndexHandle { |
| 51 | + fn as_any(&self) -> &dyn Any { |
| 52 | + self |
| 53 | + } |
| 54 | + |
| 55 | + fn as_index(self: Arc<Self>) -> Arc<dyn Index> { |
| 56 | + self |
| 57 | + } |
| 58 | + |
| 59 | + fn statistics(&self) -> Result<serde_json::Value> { |
| 60 | + let stats = FragReuseStatistics { |
| 61 | + num_versions: self.0.details.versions.len(), |
| 62 | + }; |
| 63 | + serde_json::to_value(stats).map_err(|e| { |
| 64 | + lance_core::Error::internal(format!( |
| 65 | + "failed to serialize fragment reuse index statistics: {}", |
| 66 | + e |
| 67 | + )) |
| 68 | + }) |
| 69 | + } |
| 70 | + |
| 71 | + async fn prewarm(&self) -> Result<()> { |
| 72 | + Ok(()) |
| 73 | + } |
| 74 | + |
| 75 | + fn index_type(&self) -> IndexType { |
| 76 | + IndexType::FragmentReuse |
| 77 | + } |
| 78 | + |
| 79 | + async fn calculate_included_frags(&self) -> Result<RoaringBitmap> { |
| 80 | + unimplemented!() |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +impl RowIdRemapper for FragReuseIndexHandle { |
| 85 | + fn remap_row_id(&self, row_id: u64) -> Option<u64> { |
| 86 | + self.0.remap_row_id(row_id) |
| 87 | + } |
| 88 | + |
| 89 | + fn remap_row_addrs_tree_map(&self, row_addrs: &RowAddrTreeMap) -> RowAddrTreeMap { |
| 90 | + self.0.remap_row_addrs_tree_map(row_addrs) |
| 91 | + } |
| 92 | + |
| 93 | + fn remap_row_ids_roaring_tree_map(&self, row_ids: &RoaringTreemap) -> RoaringTreemap { |
| 94 | + self.0.remap_row_ids_roaring_tree_map(row_ids) |
| 95 | + } |
| 96 | + |
| 97 | + fn remap_row_ids_record_batch( |
| 98 | + &self, |
| 99 | + batch: RecordBatch, |
| 100 | + row_id_idx: usize, |
| 101 | + ) -> Result<RecordBatch> { |
| 102 | + self.0.remap_row_ids_record_batch(batch, row_id_idx) |
| 103 | + } |
| 104 | +} |
0 commit comments