risingwave_connector/source/nexmark/
split.rsuse risingwave_common::types::JsonbVal;
use serde::{Deserialize, Serialize};
use crate::error::ConnectorResult;
use crate::source::{SplitId, SplitMetaData};
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Hash)]
pub struct NexmarkSplit {
pub(crate) split_index: i32,
pub(crate) split_num: i32,
pub(crate) start_offset: Option<u64>,
}
impl SplitMetaData for NexmarkSplit {
fn id(&self) -> SplitId {
format!("{}-{}", self.split_num, self.split_index).into()
}
fn restore_from_json(value: JsonbVal) -> ConnectorResult<Self> {
serde_json::from_value(value.take()).map_err(Into::into)
}
fn encode_to_json(&self) -> JsonbVal {
serde_json::to_value(self.clone()).unwrap().into()
}
fn update_offset(&mut self, last_seen_offset: String) -> ConnectorResult<()> {
self.start_offset = Some(last_seen_offset.as_str().parse::<u64>().unwrap());
Ok(())
}
}
impl NexmarkSplit {
pub fn new(split_index: i32, split_num: i32, start_offset: Option<u64>) -> NexmarkSplit {
NexmarkSplit {
split_index,
split_num,
start_offset,
}
}
}