Skip to content

Commit 470d238

Browse files
committed
Adds back register_python_catalog and rebase on main
1 parent 15e6af9 commit 470d238

File tree

9 files changed

+50
-24
lines changed

9 files changed

+50
-24
lines changed

Cargo.lock

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ common-tracing = {path = "src/common/tracing", default-features = false}
1212
common-version = {path = "src/common/version", default-features = false}
1313
daft-algebra = {path = "src/daft-algebra", default-features = false}
1414
daft-catalog = {path = "src/daft-catalog", default-features = false}
15+
daft-catalog-python-catalog = {path = "src/daft-catalog/python-catalog", optional = true}
1516
daft-compression = {path = "src/daft-compression", default-features = false}
1617
daft-connect = {path = "src/daft-connect", optional = true}
1718
daft-context = {path = "src/daft-context", default-features = false}
@@ -56,6 +57,7 @@ python = [
5657
"common-file-formats/python",
5758
"common-scan-info/python",
5859
"common-system-info/python",
60+
"daft-catalog-python-catalog/python",
5961
"daft-catalog/python",
6062
"daft-context/python",
6163
"daft-core/python",

daft/catalog/__iceberg.py

-10
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ def _from_obj(obj: object) -> IcebergCatalog:
3434
return c
3535
raise ValueError(f"Unsupported iceberg catalog type: {type(obj)}")
3636

37-
@property
38-
def inner(self) -> InnerCatalog:
39-
"""Returns the inner iceberg catalog."""
40-
return self._inner
41-
4237
###
4338
# get_*
4439
###
@@ -72,11 +67,6 @@ def _from_obj(obj: object) -> IcebergTable | None:
7267
return t
7368
raise ValueError(f"Unsupported iceberg table type: {type(obj)}")
7469

75-
@property
76-
def inner(self) -> InnerTable:
77-
"""Returns the inner iceberg table."""
78-
return self._inner
79-
8070
@staticmethod
8171
def _try_from(obj: object) -> IcebergTable | None:
8272
"""Returns an IcebergTable if the given object can be adapted so."""

daft/catalog/__init__.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from abc import ABC, abstractmethod
4444
from collections.abc import Sequence
4545
from daft.daft import PyTableSource, catalog as native_catalog
46-
from daft.daft import PyIdentifier, PyTable
46+
from daft.daft import PyIdentifier
4747
from daft.logical.builder import LogicalPlanBuilder
4848

4949
from daft.dataframe import DataFrame
@@ -185,10 +185,6 @@ def _from_obj(obj: object) -> Catalog:
185185
f"Unsupported catalog type: {type(obj)}; please ensure all required extra dependencies are installed."
186186
)
187187

188-
@property
189-
def inner(self) -> object | None:
190-
"""Returns the inner catalog object if this is an adapter."""
191-
192188
###
193189
# list_*
194190
###
@@ -314,7 +310,6 @@ def from_unity(obj: object) -> Table:
314310
except ImportError:
315311
raise ImportError("Unity support not installed: pip install -U 'getdaft[unity]'")
316312

317-
318313
@staticmethod
319314
def _from_obj(obj: object) -> Table:
320315
"""Returns a Daft Table from a supported object type or raises an error."""

daft/catalog/__unity.py

-5
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ def _from_obj(obj: object) -> UnityTable | None:
8282
return t
8383
raise ValueError(f"Unsupported unity table type: {type(obj)}")
8484

85-
@property
86-
def inner(self) -> InnerTable:
87-
"""Returns the inner unity table."""
88-
return self._inner
89-
9085
@staticmethod
9186
def _try_from(obj: object) -> UnityTable | None:
9287
"""Returns an UnityTable if the given object can be adapted so."""

src/daft-catalog/Cargo.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ sqlparser = {workspace = true}
88
snafu.workspace = true
99

1010
[features]
11-
python = ["dep:pyo3", "common-error/python", "daft-logical-plan/python", "daft-core/python"]
11+
python = [
12+
"dep:pyo3",
13+
"common-error/python",
14+
"daft-core/python",
15+
"daft-logical-plan/python"
16+
]
1217

1318
[package]
1419
name = "daft-catalog"

src/daft-sql/src/planner.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@ impl<'a> SQLPlanner<'a> {
168168
Ref::map(self.context.borrow(), |i| &i.bound_ctes)
169169
}
170170

171+
/// Lookup a table by identifier in the current session
172+
fn get_table(&self, ident: &Identifier) -> Option<LogicalPlanBuilder> {
173+
self.session()
174+
.get_table(ident)
175+
.map(|table| {
176+
table
177+
.get_logical_plan()
178+
.expect("could not create a logical plan from the table")
179+
.into()
180+
})
181+
.ok()
182+
}
183+
171184
/// Borrow the planning session
172185
fn session(&self) -> Ref<'_, Rc<Session>> {
173186
Ref::map(self.context.borrow(), |i| &i.session)
@@ -887,13 +900,14 @@ impl<'a> SQLPlanner<'a> {
887900
let ident = normalize(name);
888901
let table = if ident.has_namespace() {
889902
// qualified search of sesison metadata
890-
self.session().get_table(&ident).ok()
903+
self.get_table(&ident)
891904
} else {
892905
// search bindings then session metadata
893906
self.bound_ctes()
894907
.get(&ident.name)
895908
.cloned()
896-
.or_else(|| self.session().get_table(&ident).ok())
909+
.or_else(|| self.bound_ctes().get(&ident.name).cloned())
910+
.or_else(|| self.get_table(&ident))
897911
};
898912
table.ok_or_else(|| PlannerError::table_not_found(ident.to_string()))
899913
}

src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ pub mod pylib {
124124
daft_session::register_modules(m)?;
125125
daft_sql::register_modules(m)?;
126126

127+
// Register `py_register_python_catalog` to daft.catalog
128+
let catalog_attr = m.getattr("catalog")?;
129+
let catalog_module = catalog_attr.downcast()?;
130+
daft_catalog_python_catalog::python::register_modules(catalog_module)?;
131+
127132
// Register testing module
128133
let testing_module = PyModule::new(m.py(), "testing")?;
129134
m.add_submodule(&testing_module)?;

tests/catalog/test_catalog.py

+9
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@ def test_try_from_unity():
2323
# assert doesn't throw!
2424
assert Catalog._from_obj(unity_catalog) is not None
2525
assert Catalog.from_unity(unity_catalog) is not None
26+
27+
28+
def test_register_python_catalog():
29+
import daft.unity_catalog
30+
31+
# sanity check for backwards compatibility
32+
cat1 = daft.unity_catalog.UnityCatalog("", "")
33+
daft.catalog.register_python_catalog(cat1, "test")
34+
daft.catalog.unregister_catalog("test")

0 commit comments

Comments
 (0)