ratmice opened a new pull request, #23466:
URL: https://github.com/apache/datafusion/pull/23466
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases. You can
link an issue to this PR using the GitHub syntax. For example `Closes #123`
indicates that this PR will close issue #123.
-->
- Closes #23386 .
## 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).
<!--
Why are you proposing this change? If this is already explained clearly in
the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your
changes and offer better suggestions for fixes.
-->
## 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`
<!--
There is no need to duplicate the description in the issue here but it is
sometimes worth providing a summary of the individual changes in this PR.
-->
## 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:
```console
$ 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.
```
```console
$ 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'?
```
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are
they covered by existing tests)?
-->
## 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.
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]