Skip to main content

feldera_adapterlib/
connector_metadata.rs

1use std::{collections::BTreeMap, sync::Arc};
2
3use feldera_sqllib::{SqlString, Variant};
4
5/// Connector metadata attached to each input record.
6///
7/// Both the transport connector and the parser can add metadata attributes
8/// such as Kafka topic name or Avro schema id. These attributes are passed
9/// to the deserializer along with the actual record, which can use them
10/// to populate some of the table columns.
11#[derive(Default, Clone, Debug, PartialEq, Eq)]
12pub struct ConnectorMetadata(BTreeMap<Variant, Variant>);
13
14impl ConnectorMetadata {
15    pub fn new() -> Self {
16        Self(BTreeMap::new())
17    }
18
19    pub fn insert(&mut self, name: &str, value: Variant) {
20        self.0.insert(Variant::String(SqlString::from(name)), value);
21    }
22}
23
24impl From<BTreeMap<Variant, Variant>> for ConnectorMetadata {
25    fn from(metadata: BTreeMap<Variant, Variant>) -> Self {
26        Self(metadata)
27    }
28}
29
30impl From<ConnectorMetadata> for Variant {
31    fn from(metadata: ConnectorMetadata) -> Self {
32        Variant::Map(Arc::new(metadata.0))
33    }
34}