-
Notifications
You must be signed in to change notification settings - Fork 915
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
Add partition-wise Select
support to cuDF-Polars
#17495
Merged
rapids-bot
merged 17 commits into
rapidsai:branch-25.02
from
rjzamora:cudf-polars-multi-select
Dec 18, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7c18b0d
add partition-wise Select support
rjzamora a3ceba2
add Filter
rjzamora aa385b7
Merge branch 'branch-25.02' into cudf-polars-multi-select
rjzamora afffad5
Merge branch 'branch-25.02' into cudf-polars-multi-select
rjzamora 6c44403
Merge remote-tracking branch 'upstream/branch-25.02' into cudf-polars…
rjzamora 3017521
simplify child lowering
rjzamora 869f102
Merge branch 'branch-25.02' into cudf-polars-multi-select
rjzamora c17329a
add/use is_pointwise
rjzamora e59f2ca
fix BooleanFunction
rjzamora 640b9ae
cover unary
rjzamora 5cef9e8
move traversal
rjzamora b7d23a2
Merge remote-tracking branch 'upstream/branch-25.02' into cudf-polars…
rjzamora 2ab2664
remove NamedExpr property
rjzamora 78bee6c
Update python/cudf_polars/cudf_polars/dsl/expressions/unary.py
rjzamora b5ed367
Merge branch 'branch-25.02' into cudf-polars-multi-select
rjzamora 738a10d
Merge branch 'branch-25.02' into cudf-polars-multi-select
rjzamora 734d02b
Merge branch 'branch-25.02' into cudf-polars-multi-select
rjzamora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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,36 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
"""Parallel Select Logic.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from cudf_polars.dsl.ir import Select | ||
from cudf_polars.dsl.traversal import traversal | ||
from cudf_polars.experimental.dispatch import lower_ir_node | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import MutableMapping | ||
|
||
from cudf_polars.dsl.ir import IR | ||
from cudf_polars.experimental.base import PartitionInfo | ||
from cudf_polars.experimental.parallel import LowerIRTransformer | ||
|
||
|
||
@lower_ir_node.register(Select) | ||
def _( | ||
ir: Select, rec: LowerIRTransformer | ||
) -> tuple[IR, MutableMapping[IR, PartitionInfo]]: | ||
child, partition_info = rec(ir.children[0]) | ||
pi = partition_info[child] | ||
if pi.count > 1 and not all( | ||
expr.is_pointwise for expr in traversal([e.value for e in ir.exprs]) | ||
): | ||
# TODO: Handle non-pointwise expressions. | ||
raise NotImplementedError( | ||
f"Selection {ir} does not support multiple partitions." | ||
) | ||
new_node = ir.reconstruct([child]) | ||
partition_info[new_node] = pi | ||
return new_node, partition_info |
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,54 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import polars as pl | ||
|
||
from cudf_polars.testing.asserts import assert_gpu_result_equal | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def engine(): | ||
return pl.GPUEngine( | ||
raise_on_fail=True, | ||
executor="dask-experimental", | ||
executor_options={"max_rows_per_partition": 3}, | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def df(): | ||
return pl.LazyFrame( | ||
{ | ||
"a": [1, 2, 3, 4, 5, 6, 7], | ||
"b": [1, 1, 1, 1, 1, 1, 1], | ||
} | ||
) | ||
|
||
|
||
def test_select(df, engine): | ||
query = df.select( | ||
pl.col("a") + pl.col("b"), (pl.col("a") * 2 + pl.col("b")).alias("d") | ||
) | ||
assert_gpu_result_equal(query, engine=engine) | ||
|
||
|
||
def test_select_reduce_raises(df, engine): | ||
query = df.select( | ||
(pl.col("a") + pl.col("b")).max(), | ||
(pl.col("a") * 2 + pl.col("b")).alias("d").mean(), | ||
) | ||
with pytest.raises( | ||
pl.exceptions.ComputeError, | ||
match="NotImplementedError", | ||
): | ||
assert_gpu_result_equal(query, engine=engine) | ||
|
||
|
||
def test_select_with_cse_no_agg(df, engine): | ||
expr = pl.col("a") + pl.col("a") | ||
query = df.select(expr, (expr * 2).alias("b"), ((expr * 2) + 10).alias("c")) | ||
assert_gpu_result_equal(query, engine=engine) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We prefer
assert_ir_translation_raises
for these kind of things, I think.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.
Parallel execution is currently independent of IR translation. When we raise an error, it's because we ran into a non-"pointwise" Select operation (with multiple partitions) after the IR was already translated successfully.
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.
Oh yeah, thanks.
I think for now this is fine, perhaps in the parallel execution environment we don't want "early/eager" fallback. But it might be worthwhile thinking about.
We can think of this lowering as another step in the "IR translation" phase.