dora_message/
metadata.rs

1use std::collections::BTreeMap;
2
3use arrow_schema::DataType;
4use serde::{Deserialize, Serialize};
5
6/// Additional data that is sent as part of output messages.
7///
8/// Includes a timestamp, type information, and additional user-provided parameters.
9#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10pub struct Metadata {
11    metadata_version: u16,
12    timestamp: uhlc::Timestamp,
13    pub type_info: ArrowTypeInfo,
14    pub parameters: MetadataParameters,
15}
16
17impl Metadata {
18    pub fn new(timestamp: uhlc::Timestamp, type_info: ArrowTypeInfo) -> Self {
19        Self::from_parameters(timestamp, type_info, Default::default())
20    }
21
22    pub fn from_parameters(
23        timestamp: uhlc::Timestamp,
24        type_info: ArrowTypeInfo,
25        parameters: MetadataParameters,
26    ) -> Self {
27        Self {
28            metadata_version: 0,
29            timestamp,
30            parameters,
31            type_info,
32        }
33    }
34
35    pub fn timestamp(&self) -> uhlc::Timestamp {
36        self.timestamp
37    }
38
39    pub fn open_telemetry_context(&self) -> String {
40        if let Some(Parameter::String(otel)) = self.parameters.get("open_telemetry_context") {
41            otel.to_string()
42        } else {
43            "".to_string()
44        }
45    }
46}
47
48/// Additional metadata that can be sent as part of output messages.
49pub type MetadataParameters = BTreeMap<String, Parameter>;
50
51#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
52pub struct ArrowTypeInfo {
53    pub data_type: DataType,
54    pub len: usize,
55    pub null_count: usize,
56    pub validity: Option<Vec<u8>>,
57    pub offset: usize,
58    pub buffer_offsets: Vec<BufferOffset>,
59    pub child_data: Vec<ArrowTypeInfo>,
60}
61
62/// A metadata parameter that can be sent as part of output messages.
63#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
64pub enum Parameter {
65    Bool(bool),
66    Integer(i64),
67    String(String),
68    ListInt(Vec<i64>),
69    Float(f64),
70    ListFloat(Vec<f64>),
71    ListString(Vec<String>),
72}
73
74#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
75pub struct BufferOffset {
76    pub offset: usize,
77    pub len: usize,
78}