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

feat(python): Add post-optimization callback #15972

Merged
merged 3 commits into from
May 1, 2024
Merged

feat(python): Add post-optimization callback #15972

merged 3 commits into from
May 1, 2024

Conversation

ritchie46
Copy link
Member

This allows a post-optimization python callback to be inserted.

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Apr 30, 2024
Copy link

codecov bot commented Apr 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.95%. Comparing base (4b23768) to head (6affa95).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15972      +/-   ##
==========================================
+ Coverage   80.89%   80.95%   +0.06%     
==========================================
  Files        1384     1384              
  Lines      178020   178106      +86     
  Branches     3043     3043              
==========================================
+ Hits       144003   144183     +180     
+ Misses      33535    33440      -95     
- Partials      482      483       +1     
Flag Coverage Δ
python 74.43% <100.00%> (+0.06%) ⬆️
rust 78.09% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +587 to +591
// Pass the node visitor which allows the python callback to replace parts of the query plan.
// Remove "cuda" or specify better once we have multiple post-opt callbacks.
lambda.call1(py, (nt,)).map_err(
|e| polars_err!(ComputeError: "'cuda' conversion failed: {}", e),
)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK so the contract here is that the callback should modify the NodeTraverser via set_udf to substitute in the subtree it can execute. But that callback isn't allowed to hold on to the NodeTraverser, since when the callback actually runs the arenas inside it are garbage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Any state that needs to be preserved should be in the callback itself.

@ritchie46 ritchie46 merged commit 556cc83 into main May 1, 2024
26 checks passed
@ritchie46 ritchie46 deleted the node_traverser branch May 1, 2024 07:02
@c-peters c-peters added the accepted Ready for implementation label May 6, 2024
Wouittone pushed a commit to Wouittone/polars that referenced this pull request Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants