Skip to content
Snippets Groups Projects
Commit 5c43973f authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon:
Browse files

fix: better BatchDml display in pico.raft_log()

parent 9ff808c8
No related branches found
No related tags found
1 merge request!927Gmoshkin/join using batch dml
......@@ -86,43 +86,19 @@ impl std::fmt::Display for Op {
return match self {
Self::Nop => f.write_str("Nop"),
Self::BatchDml { ops } => {
for op in ops {
match op {
Dml::Insert { table, tuple, .. } => {
writeln!(f, "Insert({table}, {})", DisplayAsJson(tuple))?;
}
Dml::Replace { table, tuple, .. } => {
writeln!(f, "Replace({table}, {})", DisplayAsJson(tuple))?;
}
Dml::Update {
table, key, ops, ..
} => {
let key = DisplayAsJson(key);
let ops = DisplayAsJson(&**ops);
writeln!(f, "Update({table}, {key}, {ops})")?;
}
Dml::Delete { table, key, .. } => {
writeln!(f, "Delete({table}, {})", DisplayAsJson(key))?;
}
}
write!(f, "BatchDml(")?;
let mut ops = ops.iter();
if let Some(first) = ops.next() {
write!(f, "{}", DisplayDml(first))?;
}
for next in ops {
write!(f, ", {}", DisplayDml(next))?;
}
write!(f, ")")?;
Ok(())
}
Self::Dml(Dml::Insert { table, tuple, .. }) => {
write!(f, "Insert({table}, {})", DisplayAsJson(tuple))
}
Self::Dml(Dml::Replace { table, tuple, .. }) => {
write!(f, "Replace({table}, {})", DisplayAsJson(tuple))
}
Self::Dml(Dml::Update {
table, key, ops, ..
}) => {
let key = DisplayAsJson(key);
let ops = DisplayAsJson(&**ops);
write!(f, "Update({table}, {key}, {ops})")
}
Self::Dml(Dml::Delete { table, key, .. }) => {
write!(f, "Delete({table}, {})", DisplayAsJson(key))
Self::Dml(dml) => {
write!(f, "{}", DisplayDml(dml))
}
Self::DdlPrepare {
schema_version,
......@@ -272,6 +248,30 @@ impl std::fmt::Display for Op {
}
};
struct DisplayDml<'a>(&'a Dml);
impl std::fmt::Display for DisplayDml<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self.0 {
Dml::Insert { table, tuple, .. } => {
write!(f, "Insert({table}, {})", DisplayAsJson(tuple))
}
Dml::Replace { table, tuple, .. } => {
write!(f, "Replace({table}, {})", DisplayAsJson(tuple))
}
Dml::Update {
table, key, ops, ..
} => {
let key = DisplayAsJson(key);
let ops = DisplayAsJson(&**ops);
write!(f, "Update({table}, {key}, {ops})")
}
Dml::Delete { table, key, .. } => {
write!(f, "Delete({table}, {})", DisplayAsJson(key))
}
}
}
}
struct DisplayAsJson<T>(pub T);
impl std::fmt::Display for DisplayAsJson<&TupleBuffer> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment