1
- use std:: { collections :: HashMap , sync:: Arc } ;
1
+ use std:: sync:: Arc ;
2
2
3
- use pyo3 :: ffi :: PyObject ;
3
+ use crate :: { bindings :: Bindings , error :: Result , Identifier , Table } ;
4
4
5
- use crate :: { error:: Result , Identifier , Table } ;
5
+ /// Catalog implementation reference.
6
+ pub type CatalogRef = Arc < dyn Catalog > ;
6
7
7
- /// Catalogs is a collection of referenceable catalogs (glorified map).
8
- ///
9
- /// Notes:
10
- /// - This is intentionally lightweight and everything is exact-case.
11
- /// - All APIs are non-fallible because callers determine what is an error.
12
- /// - It does not necessarily have map semantics.
13
- /// - Callers are responsible for case-normalization hence String, &str.
14
- /// - Intentionally using String and &str rather than Into and AsRef.
15
- #[ derive( Debug ) ]
16
- pub struct Catalogs ( HashMap < String , Arc < dyn Catalog > > ) ;
17
-
18
- impl Catalogs {
19
- /// Creates an empty catalogs collection
20
- pub fn empty ( ) -> Catalogs {
21
- Self ( HashMap :: new ( ) )
22
- }
23
-
24
- /// Attaches a catalog to this catalog collection.
25
- pub fn attach ( & mut self , name : String , catalog : Arc < dyn Catalog > ) {
26
- self . 0 . insert ( name, catalog) ;
27
- }
28
-
29
- /// Detaches a catalog from this catalog collection.
30
- pub fn detach ( & mut self , name : & str ) {
31
- self . 0 . remove ( name) ;
32
- }
33
-
34
- /// Returns true iff a catalog with the given name exists (exact-case).
35
- pub fn exists ( & self , name : & str ) -> bool {
36
- self . 0 . contains_key ( name)
37
- }
38
-
39
- /// Get the catalog by name.
40
- pub fn get ( & self , name : & str ) -> Option < Arc < dyn Catalog > > {
41
- self . 0 . get ( name) . map ( Arc :: clone)
42
- }
43
-
44
- /// Lists the catalogs
45
- pub fn list ( & self , pattern : Option < & str > ) -> Vec < String > {
46
- self . 0
47
- . keys ( )
48
- . map ( |k| k. as_str ( ) )
49
- . filter ( |k| pattern. is_none ( ) || k. contains ( pattern. unwrap_or ( "" ) ) )
50
- . map ( |k| k. to_string ( ) )
51
- . collect ( )
52
- }
53
-
54
- /// Returns true iff there are no catalogs in this collection.
55
- pub fn is_empty ( & self ) -> bool {
56
- self . 0 . is_empty ( )
57
- }
58
- }
8
+ /// CatalogProvider is a collection of referenceable catalogs.
9
+ pub type CatalogProvider = Bindings < CatalogRef > ;
59
10
60
11
/// A catalog provides object metadata such as namespaces, tables, and functions.
61
12
pub trait Catalog : Sync + Send + std:: fmt:: Debug {
@@ -65,9 +16,9 @@ pub trait Catalog: Sync + Send + std::fmt::Debug {
65
16
/// Returns the given table if it exists.
66
17
fn get_table ( & self , name : & Identifier ) -> Result < Option < Box < dyn Table > > > ;
67
18
68
- /// Leverage dynamic dispatch to return the inner object for a PyObjectImpl (use generics?).
19
+ /// Leverage dynamic dispatch to return the inner object for a PyCatalogImpl ( generics?)
69
20
#[ cfg( feature = "python" ) ]
70
21
fn to_py ( & self , _: pyo3:: Python < ' _ > ) -> pyo3:: PyObject {
71
- panic ! ( "missing to_py implementation; consider PyCatalog(self) as the blanket implementation" )
22
+ panic ! ( "missing to_py implementation, consider PyCatalog(self) as the blanket implementation" )
72
23
}
73
24
}
0 commit comments