-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jay Chia
committed
Nov 4, 2024
1 parent
8611aa7
commit e6d0350
Showing
11 changed files
with
193 additions
and
71 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from pyiceberg.catalog import Catalog as PyIcebergCatalog | ||
from pyiceberg.table import Table as PyIcebergTable | ||
|
||
from daft.dataframe import DataFrame | ||
|
||
from daft.catalog.python_catalog import PythonCatalog, PythonCatalogTable | ||
|
||
|
||
class PyIcebergCatalogAdaptor(PythonCatalog): | ||
def __init__(self, pyiceberg_catalog: PyIcebergCatalog): | ||
self._catalog = pyiceberg_catalog | ||
|
||
def list_tables(self, prefix: str) -> list[str]: | ||
return [".".join(tup) for tup in self._catalog.list_tables(prefix)] | ||
|
||
def get_table(self, name: str) -> PyIcebergTableAdaptor: | ||
return PyIcebergTableAdaptor(self._catalog.load_table(name)) | ||
|
||
|
||
class PyIcebergTableAdaptor(PythonCatalogTable): | ||
def __init__(self, pyiceberg_table: PyIcebergTable): | ||
self._table = pyiceberg_table | ||
|
||
def to_dataframe(self) -> DataFrame: | ||
import daft | ||
|
||
return daft.read_iceberg(self._table) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from __future__ import annotations | ||
|
||
from abc import abstractmethod | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from daft.dataframe import DataFrame | ||
|
||
|
||
class PythonCatalog: | ||
"""Wrapper class for various Python implementations of Data Catalogs""" | ||
|
||
@abstractmethod | ||
def list_tables(self, prefix: str) -> list[str]: ... | ||
|
||
@abstractmethod | ||
def get_table(self, name: str) -> PythonCatalogTable: ... | ||
|
||
|
||
class PythonCatalogTable: | ||
"""Wrapper class for various Python implementations of Data Catalog Tables""" | ||
|
||
@abstractmethod | ||
def to_dataframe(self) -> DataFrame: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from daft.dataframe import DataFrame | ||
from daft.unity_catalog import UnityCatalog, UnityCatalogTable | ||
|
||
from daft.catalog.python_catalog import PythonCatalog, PythonCatalogTable | ||
|
||
|
||
class UnityCatalogAdaptor(PythonCatalog): | ||
def __init__(self, unity_catalog: UnityCatalog): | ||
self._catalog = unity_catalog | ||
|
||
def list_tables(self, prefix: str) -> list[str]: | ||
num_namespaces = prefix.count(".") | ||
if prefix == "": | ||
return [ | ||
tbl | ||
for cat in self._catalog.list_catalogs() | ||
for schema in self._catalog.list_schemas(cat) | ||
for tbl in self._catalog.list_tables(schema) | ||
] | ||
elif num_namespaces == 0: | ||
catalog_name = prefix | ||
return [ | ||
tbl for schema in self._catalog.list_schemas(catalog_name) for tbl in self._catalog.list_tables(schema) | ||
] | ||
elif num_namespaces == 1: | ||
schema_name = prefix | ||
return [tbl for tbl in self._catalog.list_tables(schema_name)] | ||
else: | ||
raise ValueError( | ||
f"Unrecognized catalog name or schema name, expected a '.'-separated namespace but received: {prefix}" | ||
) | ||
|
||
def get_table(self, name: str) -> UnityTableAdaptor: | ||
return UnityTableAdaptor(self._catalog.load_table(name)) | ||
|
||
|
||
class UnityTableAdaptor(PythonCatalogTable): | ||
def __init__(self, unity_table: UnityCatalogTable): | ||
self._table = unity_table | ||
|
||
def to_dataframe(self) -> DataFrame: | ||
import daft | ||
|
||
return daft.read_deltalake(self._table) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
from daft.daft import LogicalPlanBuilder as PyLogicalPlanBuilder | ||
|
||
if TYPE_CHECKING: | ||
from daft.catalog.python_catalog import PythonCatalog | ||
|
||
def read_table(name: str) -> PyLogicalPlanBuilder: ... | ||
def register_table(name: str, plan_builder: PyLogicalPlanBuilder) -> str: ... | ||
def register_aws_glue() -> str: ... | ||
def register_python_catalog(catalog: PythonCatalog) -> str: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.