Skip to content

Support planning scalar functions in ExprPlanner - #24846

Open
MichaelScofield wants to merge 1 commit into
apache:mainfrom
GreptimeTeam:feat/expr-planner-scalar-function
Open

Support planning scalar functions in ExprPlanner#24846
MichaelScofield wants to merge 1 commit into
apache:mainfrom
GreptimeTeam:feat/expr-planner-scalar-function

Conversation

@MichaelScofield

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

ExprPlanner supports customizing aggregate and window function planning, but scalar functions bypass registered expression planners.

This prevents downstream users from customizing scalar function expressions during SQL planning.

What changes are included in this PR?

  • Add RawScalarExpr to represent a scalar function before final expression construction.
  • Add ExprPlanner::plan_scalar.
  • Route resolved scalar functions through the registered expression planner chain.
  • Preserve the existing default behavior when no planner handles the function.

What is the testing strategy for this PR?

A SQL planner integration test registers a custom scalar function planner that rewrites the semantically equivalent single-argument expression coalesce(42) to 42.

The resulting logical plan verifies that the custom planner handled the scalar function.

Are there any user-facing changes?

Yes. This PR adds the public RawScalarExpr type and the ExprPlanner::plan_scalar extension point.

The new trait method has a default implementation, so existing ExprPlanner implementations remain compatible.

Add RawScalarExpr and route resolved scalar function calls through registered expression planners before constructing ScalarFunction.
@github-actions github-actions Bot added sql SQL Planner logical-expr Logical plan and expressions labels Sep 1, 2026
@MichaelScofield

Copy link
Copy Markdown
Contributor Author

@alamb PTAL

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.58%. Comparing base (45b2f73) to head (43d0638).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/sql/src/expr/function.rs 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #24846    +/-   ##
========================================
  Coverage   81.58%   81.58%            
========================================
  Files        1123     1123            
  Lines      406610   406748   +138     
  Branches   406610   406748   +138     
========================================
+ Hits       331716   331852   +136     
+ Misses      55457    55454     -3     
- Partials    19437    19442     +5     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MichaelScofield

Copy link
Copy Markdown
Contributor Author

@jayzhan211 PTAL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DISCUSSION] Maybe support planning scalar function in ExprPlanner as well?

2 participants