Skip to content

Cli entrypoint pr2#23466

Open
ratmice wants to merge 3 commits into
apache:mainfrom
ratmice:cli_entrypoint_pr2
Open

Cli entrypoint pr2#23466
ratmice wants to merge 3 commits into
apache:mainfrom
ratmice:cli_entrypoint_pr2

Conversation

@ratmice

@ratmice ratmice commented Jul 10, 2026

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

In order for a provider of custom UDF (libaries such as geodatafusion) to get a version equivalent to datafusion-cli which registers their UDF and extensions, they currently need to reimplement a lot of argument parsing, which is a lot of boiler plate.

While this PR tries to reduce the amount of boiler plate, it also tries to make it more flexible so that downstream can add
their own arguments (see the included cli-custom-udf example).

What changes are included in this PR?

Refactor the main_inner function into a CliSession type, export the Args type publicly as CliArgs.
Migrate the to using thiserror as the todo suggests, since we're now mixing clap and datafusion errors.

This patch doesn't modify prior library functions. It moves some binary functions into a library new module.
But there isn't any changes to any existing library functions.

Existing examples now respond to arguments e.g. cargo run --example cli-session-context -- --help

Are these changes tested?

The existing datafusion-cli binary, new and existing examples, have been tested from the command line.

Because this example duplicates each output row an additional time:

$ cargo run --example cli-session-context -- --maxrows 1
DataFusion CLI v54.0.0
> select 1;
+----------+
| Int64(1) |
+----------+
| 1        |
| .        |
| .        |
| .        |
+----------+
2 row(s) fetched. (First 1 displayed. Use --maxrows to adjust)
Elapsed 0.011 seconds.
$ cargo run --example cli-custom-udf --
DataFusion CLI v54.0.0
> select hello(1);
+-----------------+
| hello(Int64(1)) |
+-----------------+
| hello 1         |
+-----------------+
1 row(s) fetched.
Elapsed 0.009 seconds.
$ cargo run --example cli-custom-udf -- --maxrows 1 --register-hello=false
DataFusion CLI v54.0.0
> select hello(1);
Error during planning: Invalid function 'hello'.
Did you mean 'ceil'?

Are there any user-facing changes?

There are no breaking changes, should be semver compatible. This just adds API on top of the existing library,
it migrates the example, so it can benefit from argument parsing, but existing binaries using the library should
be unaffected in any way.

pub fn builder() -> CliSessionBuilder {
CliSessionBuilder::default()
}
pub async fn entry_point() -> Result<(), CliError> {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Perhaps some bikeshedding here...

I'm not totally enamored with the name, but it seemed descriptive,
we could I guess impl default and use CliSession::default().run().await? instead
of having this entry_point function I suppose.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Registering custom udf in datafusion-cli could be easier

1 participant