-
Notifications
You must be signed in to change notification settings - Fork 3k
Python: Add conversion from iceberg table scan to ray dataset #7148
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
Changes from all commits
25214a6
a0838c6
04c47cd
fa4ca76
b813a85
c3adbd8
dfb2c7f
54b00c6
7f9dfa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,7 @@ | |
| if TYPE_CHECKING: | ||
| import pandas as pd | ||
| import pyarrow as pa | ||
| import ray | ||
| from duckdb import DuckDBPyConnection | ||
|
|
||
|
|
||
|
|
@@ -415,3 +416,8 @@ def to_duckdb(self, table_name: str, connection: Optional[DuckDBPyConnection] = | |
| con.register(table_name, self.to_arrow()) | ||
|
|
||
| return con | ||
|
|
||
| def to_ray(self) -> ray.data.dataset.Dataset: | ||
| import ray | ||
|
|
||
| return ray.data.from_arrow(self.to_arrow()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just for my understanding, would
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for mentioning this. not_nan = table_test_null_nan.scan(row_filter=NotNaN("col_numeric"), selected_fields=("idx",)).to_arrow()The huge table size will be an issue for limited_result = table_test_limit.scan(selected_fields=("idx",), limit=20).to_arrow()In the future, I think there could be more discussions on converting large iceberg table to ray dataset. Please let me know if you have more questions/concerns on this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the same experience today for connections like duckdb?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so, since currently all the connections are based on An out-of-memory error occurs when converting a large table to duckdb on an EC2 instance with insufficient memory.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. I guess we need to address this issue across connections then. Thanks for the explanation!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arrow also allows There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like Ray also leverages PyArrow dataset to read a variety of format (Parquet, CSV, etc) (API list). And internally Ray uses PyArrow to read data in batches and in parallel with many tasks. This PR is a good starting point. We can further collaborate to add a |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,8 @@ pandas = { version = ">=1.4.4,<=1.5.3", optional = true } | |
|
|
||
| duckdb = { version = ">=0.6.0,<=0.7.1", optional = true } | ||
|
|
||
| ray = { version = ">=2.0.0,<=2.3.0", optional = true } | ||
|
|
||
| python-snappy = { version = "0.6.1", optional = true } | ||
|
|
||
| thrift = { version = "0.16.0", optional = true } | ||
|
|
@@ -100,6 +102,7 @@ build-backend = "poetry.core.masonry.api" | |
| pyarrow = ["pyarrow"] | ||
| pandas = ["pandas", "pyarrow"] | ||
| duckdb = ["duckdb", "pyarrow"] | ||
| ray = ["ray", "pyarrow", "pandas"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need pandas as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry wondering what's this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Fokko Yes. The Here is the trace when running 2023-03-22 19:22:32,946 INFO worker.py:772 -- Task failed with retryable exception: TaskID(c8ef45ccd0112571ffffffffffffffffffffffff01000000).
(_get_metadata pid=77891) Traceback (most recent call last):
(_get_metadata pid=77891) File "python/ray/_raylet.pyx", line 857, in ray._raylet.execute_task
(_get_metadata pid=77891) File "python/ray/_raylet.pyx", line 861, in ray._raylet.execute_task
(_get_metadata pid=77891) File "/Users/jonasjiang/Library/Caches/pypoetry/virtualenvs/pyiceberg-oQQETec1-py3.9/lib/python3.9/site-packages/ray/data/read_api.py", line 1565, in _get_metadata
(_get_metadata pid=77891) return BlockAccessor.for_block(table).get_metadata(
(_get_metadata pid=77891) File "/Users/jonasjiang/Library/Caches/pypoetry/virtualenvs/pyiceberg-oQQETec1-py3.9/lib/python3.9/site-packages/ray/data/block.py", line 379, in for_block
(_get_metadata pid=77891) import pandas
(_get_metadata pid=77891) ModuleNotFoundError: No module named 'pandas'Here is the reference for The
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @c21 The ray = { version = ">=2.0.0,<=2.3.0", optional = true }For example. If users want to convert the iceberg table stored in AWS Glue to a ray dataset, they can install the pyiceberg by git clone https://github.com/apache/iceberg.git
cd iceberg/python
pip3 install -e ".[glue,ray]"In this way, all the required dependencies for ray are installed, including There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this file represents required dependency, this change looks good to me. |
||
| snappy = ["python-snappy"] | ||
| hive = ["thrift"] | ||
| s3fs = ["s3fs"] | ||
|
|
@@ -237,6 +240,10 @@ ignore_missing_imports = true | |
| module = "duckdb.*" | ||
| ignore_missing_imports = true | ||
|
|
||
| [[tool.mypy.overrides]] | ||
| module = "ray.*" | ||
| ignore_missing_imports = true | ||
|
|
||
| [[tool.mypy.overrides]] | ||
| module = "pyparsing.*" | ||
| ignore_missing_imports = true | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to #7163 (comment), #7163 (comment), it seems sometimes the iceberg-spark docker need more time to finish table creation. Extending the wait time to 30s to ensure the integration test can pass.