Repository navigation
[Data][2/n] Eager StarExpr expansion + optimizer-rule narrowing - #63776
goutamvenkat-anyscale merged 6 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements eager expansion of StarExpr in Project.__post_init__ when the input schema is known, simplifying downstream optimizer rules by avoiding StarExpr special cases on typed chains. However, the current implementation of _expand_star_exprs appends renamed columns to the end of the list, which causes a critical schema mismatch and breaks column ordering. To resolve this, the star expansion should replace renamed columns in-place, and the corresponding test assertions should be updated accordingly.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces eager expansion of StarExpr into explicit col() references within Project.__post_init__ when the input schema is known. This ensures that downstream optimizer rules do not encounter StarExpr on typed chains, while preserving the fallback behavior for opaque schemas (e.g., UDF maps). To support this, a new helper function _expand_star_exprs is added to ray.data.expressions and integrated into exprlist_to_fields to align plan-time and runtime semantics. Comprehensive unit tests and a new test utility assert_exprs_equal have also been added. There are no review comments, so no feedback is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 97b9b6c27e1d793ecf3b26274fe5afc68b932152. Configure here.
6881818 to
d82257b
Compare
| # Check if filter references columns removed by explicit select. | ||
| # Valid if: projection includes all columns (star, UDF-fallback path) | ||
| # OR predicate columns exist in the explicit output set (typed path, | ||
| # since Phase 2a expands ``StarExpr`` into explicit ``col()`` refs |
There was a problem hiding this comment.
should the reference to phase 2a exist in this comment?
| # ``Project.__post_init__`` when the input schema is known. So this | ||
| # branch is hit only on the UDF-fallback path (Project on top of an | ||
| # opaque-schema input like ``MapBatches``), where we can't enumerate | ||
| # columns and have to fall back to "all columns" (``None``). | ||
| if any(isinstance(expr, StarExpr) for expr in exprs): |
There was a problem hiding this comment.
wait to clarify, the star expression will exist here only when we encounter an unknown schema (like UDF?)
There was a problem hiding this comment.
Yup. If it encounters any black box udf will remain a starexpr
| of its source column. | ||
|
|
||
| Mirrors the runtime expansion in | ||
| ``ray.data._internal.planner.plan_expression.expression_evaluator.eval_projection`` |
There was a problem hiding this comment.
if u reference this, u can probably just have the name of the function, and make sure it's a developer API
Phase 2a: Eager StarExpr expansion in Project.__post_init__. Mirrors DataFusion's ``Projection::try_new``: ``Project.__post_init__`` calls a new ``_expand_star_exprs(exprs, input_schema)`` helper when the upstream input schema is a ``pa.Schema``. The resulting ``Project.exprs`` contains explicit ``col()`` references rather than ``StarExpr``, so downstream optimizer rules treat projection lists uniformly on every typed chain. When the input is opaque (UDF map upstream), ``StarExpr`` is preserved and the runtime ``eval_projection`` expands it per-block. Phase 2b: Narrow star handling in optimizer rules to UDF-fallback. After Phase 2a, every typed chain reaches the optimizer with no ``StarExpr`` in the projection list. The defensive ``StarExpr`` branches in ``projection_pushdown`` (``_collect_referenced_columns``, ``_push_projection_into_read_op``, ``_try_fuse``), ``predicate_pushdown`` (``_can_push_filter_through_projection``), and ``eval_projection`` are now only hit on the UDF-fallback path; document this and remove the resolved TODO at ``_collect_referenced_columns`` (issue ray-project#57720). Also fixes a Phase 1 bug in ``exprlist_to_fields``: duplicate output names (e.g., ``with_column('a', new_expr)`` on an input that already has ``a``) now last-wins to match the runtime ``eval_projection`` upsert semantics. Tests: 6 unit tests for ``_expand_star_exprs`` and 3 integration tests verifying ``Project.exprs`` after ``with_column`` / ``rename_columns`` / ``map_batches -> with_column``, plus a fixed ``exprlist_to_fields`` regression test for column overrides. Co-authored-by: Cursor <[email protected]>
Signed-off-by: Goutam <[email protected]>
Signed-off-by: Goutam <[email protected]>
Signed-off-by: Goutam <[email protected]>
Signed-off-by: Goutam <[email protected]>
Signed-off-by: Goutam <[email protected]>
d82257b to
f8313be
Compare
…project#63776) Phase 2a: Eager StarExpr expansion in Project.__post_init__. ``Project.__post_init__`` calls a new ``_expand_star_exprs(exprs, input_schema)`` helper when the upstream input schema is a ``pa.Schema``. The resulting ``Project.exprs`` contains explicit ``col()`` references rather than ``StarExpr``, so downstream optimizer rules treat projection lists uniformly on every typed chain. When the input is opaque (UDF map upstream), ``StarExpr`` is preserved and the runtime ``eval_projection`` expands it per-block. Phase 2b: Narrow star handling in optimizer rules to UDF-fallback. After Phase 2a, every typed chain reaches the optimizer with no ``StarExpr`` in the projection list. The defensive ``StarExpr`` branches in ``projection_pushdown`` (``_collect_referenced_columns``, ``_push_projection_into_read_op``, ``_try_fuse``), ``predicate_pushdown`` (``_can_push_filter_through_projection``), and ``eval_projection`` are now only hit on the UDF-fallback path; document this and remove the resolved TODO at ``_collect_referenced_columns`` (issue ray-project#57720). Tests: 6 unit tests for ``_expand_star_exprs`` and 3 integration tests verifying ``Project.exprs`` after ``with_column`` / ``rename_columns`` / ``map_batches -> with_column``, plus a fixed ``exprlist_to_fields`` regression test for column overrides. --------- Signed-off-by: Goutam <[email protected]> Co-authored-by: Cursor <[email protected]>
…project#63776) Phase 2a: Eager StarExpr expansion in Project.__post_init__. ``Project.__post_init__`` calls a new ``_expand_star_exprs(exprs, input_schema)`` helper when the upstream input schema is a ``pa.Schema``. The resulting ``Project.exprs`` contains explicit ``col()`` references rather than ``StarExpr``, so downstream optimizer rules treat projection lists uniformly on every typed chain. When the input is opaque (UDF map upstream), ``StarExpr`` is preserved and the runtime ``eval_projection`` expands it per-block. Phase 2b: Narrow star handling in optimizer rules to UDF-fallback. After Phase 2a, every typed chain reaches the optimizer with no ``StarExpr`` in the projection list. The defensive ``StarExpr`` branches in ``projection_pushdown`` (``_collect_referenced_columns``, ``_push_projection_into_read_op``, ``_try_fuse``), ``predicate_pushdown`` (``_can_push_filter_through_projection``), and ``eval_projection`` are now only hit on the UDF-fallback path; document this and remove the resolved TODO at ``_collect_referenced_columns`` (issue ray-project#57720). Tests: 6 unit tests for ``_expand_star_exprs`` and 3 integration tests verifying ``Project.exprs`` after ``with_column`` / ``rename_columns`` / ``map_batches -> with_column``, plus a fixed ``exprlist_to_fields`` regression test for column overrides. --------- Signed-off-by: Goutam <[email protected]> Co-authored-by: Cursor <[email protected]>
…project#63776) Phase 2a: Eager StarExpr expansion in Project.__post_init__. ``Project.__post_init__`` calls a new ``_expand_star_exprs(exprs, input_schema)`` helper when the upstream input schema is a ``pa.Schema``. The resulting ``Project.exprs`` contains explicit ``col()`` references rather than ``StarExpr``, so downstream optimizer rules treat projection lists uniformly on every typed chain. When the input is opaque (UDF map upstream), ``StarExpr`` is preserved and the runtime ``eval_projection`` expands it per-block. Phase 2b: Narrow star handling in optimizer rules to UDF-fallback. After Phase 2a, every typed chain reaches the optimizer with no ``StarExpr`` in the projection list. The defensive ``StarExpr`` branches in ``projection_pushdown`` (``_collect_referenced_columns``, ``_push_projection_into_read_op``, ``_try_fuse``), ``predicate_pushdown`` (``_can_push_filter_through_projection``), and ``eval_projection`` are now only hit on the UDF-fallback path; document this and remove the resolved TODO at ``_collect_referenced_columns`` (issue ray-project#57720). Tests: 6 unit tests for ``_expand_star_exprs`` and 3 integration tests verifying ``Project.exprs`` after ``with_column`` / ``rename_columns`` / ``map_batches -> with_column``, plus a fixed ``exprlist_to_fields`` regression test for column overrides. --------- Signed-off-by: Goutam <[email protected]> Co-authored-by: Cursor <[email protected]> Signed-off-by: 400Ping <[email protected]>

Phase 2a: Eager StarExpr expansion in Project.post_init.
Project.__post_init__calls a new_expand_star_exprs(exprs, input_schema)helper when the upstream input schema is apa.Schema. The resultingProject.exprscontains explicitcol()references rather thanStarExpr, so downstream optimizer rules treat projection lists uniformly on every typed chain. When the input is opaque (UDF map upstream),StarExpris preserved and the runtimeeval_projectionexpands it per-block.Phase 2b: Narrow star handling in optimizer rules to UDF-fallback.
After Phase 2a, every typed chain reaches the optimizer with no
StarExprin the projection list. The defensiveStarExprbranches inprojection_pushdown(_collect_referenced_columns,_push_projection_into_read_op,_try_fuse),predicate_pushdown(_can_push_filter_through_projection), andeval_projectionare now only hit on the UDF-fallback path; document this and remove the resolved TODO at_collect_referenced_columns(issue #57720).Tests: 6 unit tests for
_expand_star_exprsand 3 integration tests verifyingProject.exprsafterwith_column/rename_columns/map_batches -> with_column, plus a fixedexprlist_to_fieldsregression test for column overrides.