Skip to content

Commit

Permalink
Trim tags in SpliMetadata debug (#4034)
Browse files Browse the repository at this point in the history
* Trim tags in SpliMetadata debug
closes #4002

* clippy
  • Loading branch information
saroh authored Oct 27, 2023
1 parent b12561a commit 6cf5c9f
Showing 1 changed file with 90 additions and 1 deletion.
91 changes: 90 additions & 1 deletion quickwit/quickwit-metastore/src/split_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Split {
/// Carries immutable split metadata.
/// This struct can deserialize older format automatically
/// but can only serialize to the last version.
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Default, Eq, PartialEq, Serialize, Deserialize)]
#[serde(into = "VersionedSplitMetadata")]
#[serde(try_from = "VersionedSplitMetadata")]
pub struct SplitMetadata {
Expand Down Expand Up @@ -133,6 +133,51 @@ pub struct SplitMetadata {
/// this split.
pub num_merge_ops: usize,
}
impl fmt::Debug for SplitMetadata {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut debug_struct = f.debug_struct("SplitMetadata");
debug_struct.field("split_id", &self.split_id);
debug_struct.field("index_uid", &self.index_uid);
debug_struct.field("partition_id", &self.partition_id);
debug_struct.field("source_id", &self.source_id);
debug_struct.field("node_id", &self.node_id);
debug_struct.field("num_docs", &self.num_docs);
debug_struct.field(
"uncompressed_docs_size_in_bytes",
&self.uncompressed_docs_size_in_bytes,
);
debug_struct.field("time_range", &self.time_range);
debug_struct.field("create_timestamp", &self.create_timestamp);
debug_struct.field("maturity", &self.maturity);
if !self.tags.is_empty() {
let mut tags_iter = self.tags.iter();
let mut tags_str = String::new();
tags_str.push('{');
for _ in 0..4 {
if let Some(tag) = tags_iter.next() {
tags_str.push('"');
tags_str.push_str(tag);
tags_str.push_str("\", ");
} else {
break;
}
}
if tags_iter.next().is_some() {
let remaining_count = self.tags.len() - 4;
tags_str.push_str(&format!("and {} more", remaining_count));
} else {
tags_str.pop();
tags_str.pop();
}
tags_str.push('}');
debug_struct.field("tags", &tags_str);
}
debug_struct.field("footer_offsets", &self.footer_offsets);
debug_struct.field("delete_opstamp", &self.delete_opstamp);
debug_struct.field("num_merge_ops", &self.num_merge_ops);
debug_struct.finish()
}
}

impl SplitMetadata {
/// Creates a new instance of split metadata.
Expand Down Expand Up @@ -324,6 +369,8 @@ pub fn utc_now_timestamp() -> i64 {

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_split_maturity_serialization() {
{
Expand All @@ -346,4 +393,46 @@ mod tests {
assert_eq!(deserialized, split_maturity);
}
}

#[test]
fn test_split_metadata_debug() {
let split_metadata = SplitMetadata {
split_id: "split-1".to_string(),
index_uid: IndexUid::from_parts(
"00000000-0000-0000-0000-000000000000",
ulid::Ulid::nil(),
),
partition_id: 0,
source_id: "source-1".to_string(),
node_id: "node-1".to_string(),
num_docs: 100,
uncompressed_docs_size_in_bytes: 1024,
time_range: Some(0..=100),
create_timestamp: 1629867600,
maturity: SplitMaturity::Mature,
tags: {
let mut tags = BTreeSet::new();
tags.insert("🐱".to_string());
tags.insert("🙀".to_string());
tags.insert("😻".to_string());
tags.insert("😼".to_string());
tags.insert("😿".to_string());
tags
},
footer_offsets: 0..1024,
delete_opstamp: 0,
num_merge_ops: 0,
};

let expected_output = "SplitMetadata { split_id: \"split-1\", index_uid: \
IndexUid(\"00000000-0000-0000-0000-000000000000:\
00000000000000000000000000\"), partition_id: 0, source_id: \
\"source-1\", node_id: \"node-1\", num_docs: 100, \
uncompressed_docs_size_in_bytes: 1024, time_range: Some(0..=100), \
create_timestamp: 1629867600, maturity: Mature, tags: \
\"{\\\"🐱\\\", \\\"😻\\\", \\\"😼\\\", \\\"😿\\\", and 1 more}\", \
footer_offsets: 0..1024, delete_opstamp: 0, num_merge_ops: 0 }";

assert_eq!(format!("{:?}", split_metadata), expected_output);
}
}

0 comments on commit 6cf5c9f

Please sign in to comment.