20
20
from __future__ import annotations
21
21
22
22
from abc import ABC , abstractmethod
23
- from typing import TYPE_CHECKING , Any , Protocol
23
+ from typing import TYPE_CHECKING , Protocol
24
24
25
25
import datafusion ._internal as df_internal
26
26
27
27
if TYPE_CHECKING :
28
28
import pyarrow as pa
29
29
30
- from datafusion import DataFrame
31
- from datafusion .context import TableProviderExportable
32
-
33
30
try :
34
31
from warnings import deprecated # Python 3.13+
35
32
except ImportError :
@@ -85,11 +82,7 @@ def database(self, name: str = "public") -> Schema:
85
82
"""Returns the database with the given ``name`` from this catalog."""
86
83
return self .schema (name )
87
84
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 :
93
86
"""Register a schema with this catalog."""
94
87
if isinstance (schema , Schema ):
95
88
return self .catalog .register_schema (name , schema ._raw_schema )
@@ -129,12 +122,10 @@ def table(self, name: str) -> Table:
129
122
"""Return the table with the given ``name`` from this schema."""
130
123
return Table (self ._raw_schema .table (name ))
131
124
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 )
138
129
return self ._raw_schema .register_table (name , table )
139
130
140
131
def deregister_table (self , name : str ) -> None :
@@ -148,45 +139,30 @@ class Database(Schema):
148
139
149
140
150
141
class 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."""
162
143
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
170
147
171
148
def __repr__ (self ) -> str :
172
149
"""Print a string representation of the table."""
173
- return repr ( self ._inner )
150
+ return self .table . __repr__ ( )
174
151
175
152
@staticmethod
176
- @deprecated ("Use Table() constructor instead." )
177
153
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 ) )
180
156
181
157
@property
182
158
def schema (self ) -> pa .Schema :
183
159
"""Returns the schema associated with this table."""
184
- return self ._inner .schema
160
+ return self .table .schema
185
161
186
162
@property
187
163
def kind (self ) -> str :
188
164
"""Returns the kind of table."""
189
- return self ._inner .kind
165
+ return self .table .kind
190
166
191
167
192
168
class CatalogProvider (ABC ):
@@ -243,16 +219,14 @@ def table(self, name: str) -> Table | None:
243
219
"""Retrieve a specific table from this schema."""
244
220
...
245
221
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.
250
224
251
225
This method is optional. If your schema provides a fixed list of tables, you do
252
226
not need to implement this method.
253
227
"""
254
228
255
- def deregister_table (self , name : str , cascade : bool ) -> None : # noqa: B027
229
+ def deregister_table (self , name , cascade : bool ) -> None : # noqa: B027
256
230
"""Remove a table from this schema.
257
231
258
232
This method is optional. If your schema provides a fixed list of tables, you do
0 commit comments