Skip to content

Conversation

@Jiashu-Hu
Copy link
Contributor

@Jiashu-Hu Jiashu-Hu commented Mar 21, 2025

Which issue does this PR close?

Rationale for this change

This PR adds documentation for using the ExprPlanner API to plan custom expressions, as requested in #15267. Clear documentation with an example will help users extend DataFusion to support custom operators like PostgreSQL's ->.

What changes are included in this PR?

  • Added a new section ## Custom Expression Planning to document
  • Included an introduction explaining what ExprPlanner does and why it’s useful.
  • Provided a step-by-step example showing how to implement and register an ExprPlanner to make the -> operator concatenate strings (e.g., 'foo'->'bar' outputs foobar).
  • Linked to relevant API docs (ExprPlanner and FunctionRegistry) for further reading.

Are these changes tested?

yes

Are there any user-facing changes?

Yes, since this is an documentation chang

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Mar 21, 2025
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you so much @Jiashu-Hu -- this looks great.

I have some suggestions on how to improve this section and example, but we could also do it as a follow on PR.

It is great to see the docs being improved

ctx.register_expr_planner(Arc::new(MyCustomPlanner))?;
let results = ctx.sql("select 'foo'->'bar';").await?.collect().await?;

pretty::print_batches(&results)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please change this to use `assert_batches_eq! so the actual output is in the test and it is tested in CI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi alamb, Thank you very much for your review! Yes, absolutely, I've updated it with an assert_batches_eq! in the latest commit.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks again @Jiashu-Hu

@alamb alamb merged commit a2db3f0 into apache:main Mar 24, 2025
6 checks passed
qstommyshu pushed a commit to qstommyshu/datafusion that referenced this pull request Mar 27, 2025
* Added Custom Expression Planning Section

* improve syntax

* Update docs/source/library-user-guide/adding-udfs.md

Co-authored-by: Andrew Lamb <[email protected]>

* Update docs/source/library-user-guide/adding-udfs.md

Co-authored-by: Andrew Lamb <[email protected]>

* Update docs/source/library-user-guide/adding-udfs.md

Co-authored-by: Andrew Lamb <[email protected]>

* Update docs/source/library-user-guide/adding-udfs.md

Co-authored-by: Andrew Lamb <[email protected]>

* Update docs/source/library-user-guide/adding-udfs.md

Co-authored-by: Andrew Lamb <[email protected]>

* Update adding-udfs.md

added assert for CI process

* formatted language request by prettier

---------

Co-authored-by: Andrew Lamb <[email protected]>
nirnayroy pushed a commit to nirnayroy/datafusion that referenced this pull request May 2, 2025
* Added Custom Expression Planning Section

* improve syntax

* Update docs/source/library-user-guide/adding-udfs.md

Co-authored-by: Andrew Lamb <[email protected]>

* Update docs/source/library-user-guide/adding-udfs.md

Co-authored-by: Andrew Lamb <[email protected]>

* Update docs/source/library-user-guide/adding-udfs.md

Co-authored-by: Andrew Lamb <[email protected]>

* Update docs/source/library-user-guide/adding-udfs.md

Co-authored-by: Andrew Lamb <[email protected]>

* Update docs/source/library-user-guide/adding-udfs.md

Co-authored-by: Andrew Lamb <[email protected]>

* Update adding-udfs.md

added assert for CI process

* formatted language request by prettier

---------

Co-authored-by: Andrew Lamb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add documentation about how to plan custom expressions

2 participants