8
8
9
9
**Catalog**
10
10
11
- Daft recognizes a default catalog which it will attempt to use when no specific catalog name is provided.
12
-
13
11
```python
14
- # This will hit the default catalog
15
- daft.read_table("my_db.my_namespace.my_table")
12
+ # without any qualifiers, the default catalog and namespace are used.
13
+ daft.read_table("my_table")
14
+
15
+ # with a qualified identifier (uses default catalog)
16
+ daft.read_table("my_namespace.my_table")
17
+
18
+ # with a fully qualified identifier
19
+ daft.read_table("my_catalog.my_namespace.my_table")
16
20
```
17
21
18
22
**Named Tables**
24
28
```python
25
29
df = daft.from_pydict({"foo": [1, 2, 3]})
26
30
27
- # TODO deprecated catalog APIs #3819
28
- daft.catalog.register_table(
29
- "my_table",
30
- df,
31
- )
31
+ # Attach the DataFrame for use across other APIs.
32
+ daft.attach_table(df, "my_table")
32
33
33
34
# Your table is now accessible from Daft-SQL, or Daft's `read_table`
34
35
df1 = daft.read_table("my_table")
42
43
43
44
from abc import ABC , abstractmethod
44
45
from collections .abc import Sequence
45
- from daft .daft import catalog as native_catalog
46
46
from daft .daft import PyIdentifier , PyTable
47
- from daft .logical .builder import LogicalPlanBuilder
48
-
49
47
from daft .dataframe import DataFrame
50
48
51
49
from typing import TYPE_CHECKING
65
63
"unregister_catalog" ,
66
64
]
67
65
66
+
68
67
# TODO deprecated catalog APIs #3819
69
- unregister_catalog = native_catalog .unregister_catalog
68
+ def unregister_catalog (catalog_name : str | None ) -> bool :
69
+ """Unregisters a catalog from the Daft catalog system.
70
+
71
+ DEPRECATED: This is deprecated and will be removed in daft >= 0.5.0; please use `daft.detach_catalog`.
72
+
73
+ This function removes a previously registered catalog from the Daft catalog system.
74
+
75
+ Args:
76
+ catalog_name (Optional[str]): The name of the catalog to unregister. If None, the default catalog will be unregistered.
77
+
78
+ Returns:
79
+ bool: True if a catalog was successfully unregistered, False otherwise.
80
+
81
+ Example:
82
+ >>> import daft
83
+ >>> daft.unregister_catalog("my_catalog")
84
+ True
85
+ """
86
+ from daft .session import detach_catalog
87
+
88
+ warnings .warn (
89
+ "This is deprecated and will be removed in daft >= 0.5.0; please use `daft.detach_catalog`." ,
90
+ category = DeprecationWarning ,
91
+ )
92
+ try :
93
+ alias = catalog_name if catalog_name else "default"
94
+ detach_catalog (alias )
95
+ return True
96
+ except Exception :
97
+ return False
70
98
71
99
72
100
# TODO deprecated catalog APIs #3819
73
101
def read_table (name : str ) -> DataFrame :
74
102
"""Finds a table with the specified name and reads it as a DataFrame.
75
103
104
+ DEPRECATED: This is deprecated and will be removed in daft >= 0.5.0; please use `daft.read_table`.
105
+
76
106
The provided name can be any of the following, and Daft will return them with the following order of priority:
77
107
78
108
1. Name of a registered dataframe/SQL view (manually registered using `daft.register_table`): `"my_registered_table"`
@@ -85,14 +115,21 @@ def read_table(name: str) -> DataFrame:
85
115
Returns:
86
116
A DataFrame containing the data from the specified table.
87
117
"""
88
- native_logical_plan_builder = native_catalog .read_table (name )
89
- return DataFrame (LogicalPlanBuilder (native_logical_plan_builder ))
118
+ from daft .session import read_table
119
+
120
+ warnings .warn (
121
+ "This is deprecated and will be removed in daft >= 0.5.0; please use `daft.read_table`." ,
122
+ category = DeprecationWarning ,
123
+ )
124
+ return read_table (name )
90
125
91
126
92
127
# TODO deprecated catalog APIs #3819
93
128
def register_table (name : str , dataframe : DataFrame ) -> str :
94
129
"""Register a DataFrame as a named table.
95
130
131
+ DEPRECATED: This is deprecated and will be removed in daft >= 0.5.0; please use `daft.attach_table`.
132
+
96
133
This function registers a DataFrame as a named table, making it accessible
97
134
via Daft-SQL or Daft's `read_table` function.
98
135
@@ -108,13 +145,22 @@ def register_table(name: str, dataframe: DataFrame) -> str:
108
145
>>> daft.catalog.register_table("my_table", df)
109
146
>>> daft.read_table("my_table")
110
147
"""
111
- return native_catalog .register_table (name , dataframe ._builder ._builder )
148
+ from daft .session import attach_table
149
+
150
+ warnings .warn (
151
+ "This is deprecated and will be removed in daft >= 0.5.0; please use `daft.attach_table`." ,
152
+ category = DeprecationWarning ,
153
+ )
154
+ _ = attach_table (dataframe , name )
155
+ return name
112
156
113
157
114
158
# TODO deprecated catalog APIs #3819
115
159
def register_python_catalog (catalog : object , name : str | None = None ) -> str :
116
160
"""Registers a Python catalog with Daft.
117
161
162
+ DEPRECATED: This is deprecated and will be removed in daft >= 0.5.0; please use `daft.attach_catalog`.
163
+
118
164
Currently supports:
119
165
120
166
* [PyIceberg Catalogs](https://py.iceberg.apache.org/api/)
@@ -136,7 +182,16 @@ def register_python_catalog(catalog: object, name: str | None = None) -> str:
136
182
>>> daft.catalog.register_python_catalog(catalog, "my_daft_catalog")
137
183
138
184
"""
139
- return native_catalog .register_python_catalog (Catalog ._from_obj (catalog ), name )
185
+ from daft .session import attach_catalog
186
+
187
+ warnings .warn (
188
+ "This is deprecated and will be removed in daft >= 0.5.0; please use `daft.attach_catalog`." ,
189
+ category = DeprecationWarning ,
190
+ )
191
+ if name is None :
192
+ raise ValueError ("implicit catalog aliases are not supported" )
193
+ _ = attach_catalog (catalog , name )
194
+ return name
140
195
141
196
142
197
class Catalog (ABC ):
0 commit comments