Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't check duckdb and ray import if not used #33

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pypaimon/api/table_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

import pandas as pd
import pyarrow as pa
import ray

from abc import ABC, abstractmethod
from duckdb.duckdb import DuckDBPyConnection
from pypaimon.api import Split
from typing import List, Optional
from typing import List, Optional, TYPE_CHECKING

if TYPE_CHECKING:
import ray
from duckdb.duckdb import DuckDBPyConnection


class TableRead(ABC):
Expand All @@ -46,9 +48,9 @@ def to_duckdb(
self,
splits: List[Split],
table_name: str,
connection: Optional[DuckDBPyConnection] = None) -> DuckDBPyConnection:
connection: Optional["DuckDBPyConnection"] = None) -> "DuckDBPyConnection":
"""Convert splits into an in-memory DuckDB table which can be queried."""

@abstractmethod
def to_ray(self, splits: List[Split]) -> ray.data.dataset.Dataset:
def to_ray(self, splits: List[Split]) -> "ray.data.dataset.Dataset":
"""Convert splits into a Ray dataset format."""
17 changes: 11 additions & 6 deletions pypaimon/py4j/java_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@

# pypaimon.api implementation based on Java code & py4j lib

import duckdb
import pandas as pd
import pyarrow as pa
import ray

from duckdb.duckdb import DuckDBPyConnection
from pypaimon.py4j.java_gateway import get_gateway
from pypaimon.py4j.util import java_utils, constants
from pypaimon.api import \
(catalog, table, read_builder, table_scan, split,
table_read, write_builder, table_write, commit_message,
table_commit, Schema, predicate)
from typing import List, Iterator, Optional, Any
from typing import List, Iterator, Optional, Any, TYPE_CHECKING

if TYPE_CHECKING:
import ray
from duckdb.duckdb import DuckDBPyConnection


class Catalog(catalog.Catalog):
Expand Down Expand Up @@ -171,12 +172,16 @@ def to_duckdb(
self,
splits: List[Split],
table_name: str,
connection: Optional[DuckDBPyConnection] = None) -> DuckDBPyConnection:
connection: Optional["DuckDBPyConnection"] = None) -> "DuckDBPyConnection":
import duckdb

con = connection or duckdb.connect(database=":memory:")
con.register(table_name, self.to_arrow(splits))
return con

def to_ray(self, splits: List[Split]) -> ray.data.dataset.Dataset:
def to_ray(self, splits: List[Split]) -> "ray.data.dataset.Dataset":
import ray

return ray.data.from_arrow(self.to_arrow(splits))

def _init(self):
Expand Down
Loading