laminar_connectors/reference/
mod.rs1#[cfg(any(test, feature = "testing"))]
4use std::collections::VecDeque;
5
6use arrow_array::RecordBatch;
7
8use crate::error::ConnectorError;
9
10#[async_trait::async_trait]
12pub trait ReferenceTableSource: Send {
13 async fn resolve_schema(
19 &mut self,
20 config: &crate::config::ConnectorConfig,
21 explicit: Option<arrow_schema::SchemaRef>,
22 ) -> Result<crate::schema::resolution::SchemaBinding, ConnectorError> {
23 let schema = explicit.ok_or_else(|| ConnectorError::FeatureUnsupported(
24 "reference-table connector requires explicit fields; no metadata resolver is implemented".into()))?;
25 crate::schema::resolution::logical_binding(
26 config,
27 crate::schema::resolution::SchemaDirection::Source,
28 crate::schema::resolution::SchemaOrigin::Explicit,
29 &schema,
30 )
31 }
32
33 async fn poll_snapshot(&mut self) -> Result<Option<RecordBatch>, ConnectorError>;
35
36 async fn close(&mut self) -> Result<(), ConnectorError>;
38}
39
40#[cfg(any(test, feature = "testing"))]
42pub struct MockReferenceTableSource {
43 snapshot_batches: VecDeque<RecordBatch>,
44 pub closed: bool,
46}
47
48#[cfg(any(test, feature = "testing"))]
49impl MockReferenceTableSource {
50 #[must_use]
52 pub fn new(snapshot_batches: Vec<RecordBatch>) -> Self {
53 Self {
54 snapshot_batches: VecDeque::from(snapshot_batches),
55 closed: false,
56 }
57 }
58
59 #[must_use]
61 pub fn empty() -> Self {
62 Self::new(Vec::new())
63 }
64}
65
66#[cfg(any(test, feature = "testing"))]
67#[async_trait::async_trait]
68impl ReferenceTableSource for MockReferenceTableSource {
69 async fn poll_snapshot(&mut self) -> Result<Option<RecordBatch>, ConnectorError> {
70 if self.closed {
71 return Err(ConnectorError::InvalidState {
72 expected: "open reference snapshot source".into(),
73 actual: "closed".into(),
74 });
75 }
76 Ok(self.snapshot_batches.pop_front())
77 }
78
79 async fn close(&mut self) -> Result<(), ConnectorError> {
80 self.closed = true;
81 Ok(())
82 }
83}
84
85#[cfg(test)]
86mod tests;