uni_plugin/traits/
catalog.rs1use std::sync::Arc;
4
5use arrow_schema::SchemaRef;
6use datafusion::execution::SendableRecordBatchStream;
7use datafusion::logical_expr::Expr;
8use datafusion::physical_plan::Statistics;
9use smol_str::SmolStr;
10
11use crate::errors::FnError;
12use crate::qname::QName;
13
14pub trait CatalogProvider: Send + Sync {
16 fn name(&self) -> &str;
18
19 fn list_labels(&self) -> Result<Vec<CatalogLabel>, FnError>;
25
26 fn list_edge_types(&self) -> Result<Vec<CatalogEdgeType>, FnError>;
32
33 fn resolve_label(&self, label: &str) -> Option<Arc<dyn CatalogTable>>;
35
36 fn resolve_edge_type(&self, edge: &str) -> Option<Arc<dyn CatalogTable>>;
38}
39
40#[derive(Clone, Debug)]
42pub struct CatalogLabel {
43 pub name: SmolStr,
45 pub doc: String,
47}
48
49#[derive(Clone, Debug)]
51pub struct CatalogEdgeType {
52 pub name: SmolStr,
54 pub doc: String,
56}
57
58pub trait CatalogTable: Send + Sync {
61 fn schema(&self) -> SchemaRef;
63
64 fn scan(
70 &self,
71 projection: Option<&[usize]>,
72 filters: &[Expr],
73 limit: Option<usize>,
74 ) -> Result<SendableRecordBatchStream, FnError>;
75
76 fn statistics(&self) -> Option<Statistics> {
78 None
79 }
80}
81
82#[derive(Debug)]
84#[non_exhaustive]
85pub enum ReplacementRequest<'a> {
86 Label(&'a str),
88 Procedure(&'a QName),
90 Function(&'a QName),
92}
93
94#[non_exhaustive]
96pub enum Replacement {
97 CatalogTable(Arc<dyn CatalogTable>),
99 Procedure(QName),
101 Function(QName),
103}
104
105impl std::fmt::Debug for Replacement {
106 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
107 match self {
108 Self::CatalogTable(_) => f
109 .debug_tuple("CatalogTable")
110 .field(&"<dyn CatalogTable>")
111 .finish(),
112 Self::Procedure(q) => f.debug_tuple("Procedure").field(q).finish(),
113 Self::Function(q) => f.debug_tuple("Function").field(q).finish(),
114 }
115 }
116}
117
118pub trait ReplacementScanProvider: Send + Sync {
121 fn replace(&self, request: &ReplacementRequest<'_>) -> Option<Replacement>;
123}