1919
2020from __future__ import annotations
2121
22+ from abc import ABC , abstractmethod
2223from typing import TYPE_CHECKING
2324
2425import datafusion ._internal as df_internal
@@ -121,6 +122,8 @@ def table(self, name: str) -> Table:
121122
122123 def register_table (self , name , table ) -> None :
123124 """Register a table provider in this schema."""
125+ if isinstance (table , Table ):
126+ return self ._raw_schema .register_table (name , table .table )
124127 return self ._raw_schema .register_table (name , table )
125128
126129 def deregister_table (self , name : str ) -> None :
@@ -144,6 +147,11 @@ def __repr__(self) -> str:
144147 """Print a string representation of the table."""
145148 return self .table .__repr__ ()
146149
150+ @staticmethod
151+ def from_dataset (dataset : pa .dataset .Dataset ) -> Table :
152+ """Turn a pyarrow Dataset into a Table."""
153+ return Table (df_internal .catalog .RawTable .from_dataset (dataset ))
154+
147155 @property
148156 def schema (self ) -> pa .Schema :
149157 """Returns the schema associated with this table."""
@@ -153,3 +161,71 @@ def schema(self) -> pa.Schema:
153161 def kind (self ) -> str :
154162 """Returns the kind of table."""
155163 return self .table .kind
164+
165+
166+ class CatalogProvider (ABC ):
167+ @abstractmethod
168+ def schema_names (self ) -> set [str ]:
169+ """Set of the names of all schemas in this catalog."""
170+ ...
171+
172+ @abstractmethod
173+ def schema (self , name : str ) -> Schema | None :
174+ """Retrieve a specific schema from this catalog."""
175+ ...
176+
177+ def register_schema (self , name : str , schema : Schema ) -> None : # noqa: B027
178+ """Add a schema to this catalog.
179+
180+ This method is optional. If your catalog provides a fixed list of schemas, you
181+ do not need to implement this method.
182+ """
183+
184+ def deregister_schema (self , name : str , cascade : bool ) -> None : # noqa: B027
185+ """Remove a schema from this catalog.
186+
187+ This method is optional. If your catalog provides a fixed list of schemas, you
188+ do not need to implement this method.
189+
190+ Args:
191+ name: The name of the schema to remove.
192+ cascade: If true, deregister the tables within the schema.
193+ """
194+
195+
196+ class SchemaProvider (ABC ):
197+ def owner_name (self ) -> str | None :
198+ """Returns the owner of the schema.
199+
200+ This is an optional method. The default return is None.
201+ """
202+ return None
203+
204+ @abstractmethod
205+ def table_names (self ) -> set [str ]:
206+ """Set of the names of all tables in this schema."""
207+ ...
208+
209+ @abstractmethod
210+ def table (self , name : str ) -> Table | None :
211+ """Retrieve a specific table from this schema."""
212+ ...
213+
214+ def register_table (self , name : str , table : Table ) -> None : # noqa: B027
215+ """Add a table from this schema.
216+
217+ This method is optional. If your schema provides a fixed list of tables, you do
218+ not need to implement this method.
219+ """
220+
221+ def deregister_table (self , name , cascade : bool ) -> None : # noqa: B027
222+ """Remove a table from this schema.
223+
224+ This method is optional. If your schema provides a fixed list of tables, you do
225+ not need to implement this method.
226+ """
227+
228+ @abstractmethod
229+ def table_exist (self , name : str ) -> bool :
230+ """Returns true if the table exists in this schema."""
231+ ...
0 commit comments