use crate::types::{RowKey, ScanRow, TombstoneType, Value};
#[derive(Debug, Clone, PartialEq)]
pub struct CompactionRow {
pub key: RowKey,
pub row_timestamp: i64,
pub row_data: CompactionRowData,
}
impl CompactionRow {
pub fn from_legacy_value(key: RowKey, row: ScanRow, row_timestamp: i64) -> Self {
let row_data = match row {
ScanRow::Row(entries) => {
let simple = entries
.into_iter()
.map(|(k, v)| {
let timestamp = match &v {
Value::Tombstone(info) => info.deletion_time,
_ => row_timestamp,
};
SimpleCell {
column: k.to_string(),
value: v,
timestamp,
ttl: None,
local_deletion_time: None,
}
})
.collect();
CompactionRowData::Live {
simple,
complex: Vec::new(),
row_deletion: None,
}
}
ScanRow::Marker(Value::Tombstone(info))
if info.tombstone_type == TombstoneType::RowTombstone =>
{
CompactionRowData::Tombstone {
deletion_time: info.deletion_time,
local_deletion_time: 0,
clustering: Vec::new(),
}
}
ScanRow::RawRow(bytes) => CompactionRowData::Live {
simple: vec![SimpleCell {
column: "value".to_string(),
value: Value::Blob(bytes.into()),
timestamp: row_timestamp,
ttl: None,
local_deletion_time: None,
}],
complex: Vec::new(),
row_deletion: None,
},
ScanRow::Marker(other) => CompactionRowData::Live {
simple: vec![SimpleCell {
column: "value".to_string(),
value: other,
timestamp: row_timestamp,
ttl: None,
local_deletion_time: None,
}],
complex: Vec::new(),
row_deletion: None,
},
};
CompactionRow {
key,
row_timestamp,
row_data,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum CompactionBound {
Inclusive(Vec<(String, Value)>),
Exclusive(Vec<(String, Value)>),
Bottom,
Top,
}
#[derive(Debug, Clone, PartialEq)]
pub enum CompactionRowData {
RangeMarker {
start: CompactionBound,
end: CompactionBound,
deletion_time: i64,
local_deletion_time: i32,
},
PartitionDelete {
deletion_time: i64,
local_deletion_time: i32,
},
Tombstone {
deletion_time: i64,
local_deletion_time: i32,
clustering: Vec<(String, Value)>,
},
Live {
simple: Vec<SimpleCell>,
complex: Vec<ComplexColumn>,
row_deletion: Option<(i64, i32)>,
},
}
#[derive(Debug, Clone, PartialEq)]
pub struct SimpleCell {
pub column: String,
pub value: Value,
pub timestamp: i64,
pub ttl: Option<u32>,
pub local_deletion_time: Option<i32>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ComplexColumn {
pub column: String,
pub complex_deletion: Option<(i64, i32)>,
pub elements: Vec<ComplexElement>,
pub collapsed_value: Value,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ComplexElement {
pub cell_path: Vec<u8>,
pub value: Option<Value>,
pub decoded_key: Option<Value>,
pub timestamp: i64,
pub ttl: Option<u32>,
pub local_deletion_time: Option<i32>,
pub is_deleted: bool,
pub has_empty_value: bool,
}