fluss/client/write/
write_format.rs1use crate::error::Error::IllegalArgument;
19use crate::error::Result;
20use crate::metadata::KvFormat;
21use std::fmt::Display;
22
23#[derive(Copy, Clone)]
24pub enum WriteFormat {
25 ArrowLog,
26 CompactedLog,
27 CompactedKv,
28}
29
30impl WriteFormat {
31 pub const fn is_log(&self) -> bool {
32 matches!(self, Self::ArrowLog | Self::CompactedLog)
33 }
34
35 pub fn is_kv(&self) -> bool {
36 !self.is_log()
37 }
38
39 pub fn to_kv_format(&self) -> Result<KvFormat> {
40 match self {
41 WriteFormat::CompactedKv => Ok(KvFormat::COMPACTED),
42 other => Err(IllegalArgument {
43 message: format!("WriteFormat `{other}` is not a KvFormat"),
44 }),
45 }
46 }
47
48 pub fn from_kv_format(kv_format: &KvFormat) -> Result<Self> {
49 match kv_format {
50 KvFormat::COMPACTED => Ok(WriteFormat::CompactedKv),
51 other => Err(IllegalArgument {
52 message: format!("Unknown KvFormat: `{other}`"),
53 }),
54 }
55 }
56}
57
58impl Display for WriteFormat {
59 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60 match self {
61 WriteFormat::ArrowLog => f.write_str("ArrowLog"),
62 WriteFormat::CompactedLog => f.write_str("CompactedLog"),
63 WriteFormat::CompactedKv => f.write_str("CompactedKv"),
64 }
65 }
66}