2020from __future__ import annotations
2121
2222from abc import ABC , abstractmethod
23- from typing import TYPE_CHECKING , Any , Protocol
23+ from typing import TYPE_CHECKING , Protocol
2424
2525import datafusion ._internal as df_internal
2626
2727if TYPE_CHECKING :
2828 import pyarrow as pa
2929
30- from datafusion import DataFrame
31- from datafusion .context import TableProviderExportable
32-
3330try :
3431 from warnings import deprecated # Python 3.13+
3532except ImportError :
@@ -85,11 +82,7 @@ def database(self, name: str = "public") -> Schema:
8582 """Returns the database with the given ``name`` from this catalog."""
8683 return self .schema (name )
8784
88- def register_schema (
89- self ,
90- name : str ,
91- schema : Schema | SchemaProvider | SchemaProviderExportable ,
92- ) -> Schema | None :
85+ def register_schema (self , name , schema ) -> Schema | None :
9386 """Register a schema with this catalog."""
9487 if isinstance (schema , Schema ):
9588 return self .catalog .register_schema (name , schema ._raw_schema )
@@ -129,12 +122,10 @@ def table(self, name: str) -> Table:
129122 """Return the table with the given ``name`` from this schema."""
130123 return Table (self ._raw_schema .table (name ))
131124
132- def register_table (
133- self ,
134- name : str ,
135- table : Table | TableProviderExportable | DataFrame | pa .dataset .Dataset ,
136- ) -> None :
137- """Register a table in this schema."""
125+ def register_table (self , name , table ) -> None :
126+ """Register a table provider in this schema."""
127+ if isinstance (table , Table ):
128+ return self ._raw_schema .register_table (name , table .table )
138129 return self ._raw_schema .register_table (name , table )
139130
140131 def deregister_table (self , name : str ) -> None :
@@ -148,45 +139,30 @@ class Database(Schema):
148139
149140
150141class Table :
151- """A DataFusion table.
152-
153- Internally we currently support the following types of tables:
154-
155- - Tables created using built-in DataFusion methods, such as
156- reading from CSV or Parquet
157- - pyarrow datasets
158- - DataFusion DataFrames, which will be converted into a view
159- - Externally provided tables implemented with the FFI PyCapsule
160- interface (advanced)
161- """
142+ """DataFusion table."""
162143
163- __slots__ = ("_inner" ,)
164-
165- def __init__ (
166- self , table : Table | TableProviderExportable | DataFrame | pa .dataset .Dataset
167- ) -> None :
168- """Constructor."""
169- self ._inner = df_internal .catalog .RawTable (table )
144+ def __init__ (self , table : df_internal .catalog .RawTable ) -> None :
145+ """This constructor is not typically called by the end user."""
146+ self .table = table
170147
171148 def __repr__ (self ) -> str :
172149 """Print a string representation of the table."""
173- return repr ( self ._inner )
150+ return self .table . __repr__ ( )
174151
175152 @staticmethod
176- @deprecated ("Use Table() constructor instead." )
177153 def from_dataset (dataset : pa .dataset .Dataset ) -> Table :
178- """Turn a :mod:` pyarrow.dataset` `` Dataset`` into a :class:` Table` ."""
179- return Table (dataset )
154+ """Turn a pyarrow Dataset into a Table."""
155+ return Table (df_internal . catalog . RawTable . from_dataset ( dataset ) )
180156
181157 @property
182158 def schema (self ) -> pa .Schema :
183159 """Returns the schema associated with this table."""
184- return self ._inner .schema
160+ return self .table .schema
185161
186162 @property
187163 def kind (self ) -> str :
188164 """Returns the kind of table."""
189- return self ._inner .kind
165+ return self .table .kind
190166
191167
192168class CatalogProvider (ABC ):
@@ -243,16 +219,14 @@ def table(self, name: str) -> Table | None:
243219 """Retrieve a specific table from this schema."""
244220 ...
245221
246- def register_table ( # noqa: B027
247- self , name : str , table : Table | TableProviderExportable | Any
248- ) -> None :
249- """Add a table to this schema.
222+ def register_table (self , name : str , table : Table ) -> None : # noqa: B027
223+ """Add a table from this schema.
250224
251225 This method is optional. If your schema provides a fixed list of tables, you do
252226 not need to implement this method.
253227 """
254228
255- def deregister_table (self , name : str , cascade : bool ) -> None : # noqa: B027
229+ def deregister_table (self , name , cascade : bool ) -> None : # noqa: B027
256230 """Remove a table from this schema.
257231
258232 This method is optional. If your schema provides a fixed list of tables, you do
0 commit comments