LantaoJin opened a new pull request, #49:
URL: https://github.com/apache/datafusion-java/pull/49
## 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 #48 .
## Rationale for this change
<!--
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.
-->
`SessionContextBuilder` (introduced in #28) currently exposes typed setters
for the six most-common session knobs: `batchSize`, `targetPartitions`,
`collectStatistics`, `informationSchema`, `memoryLimit`, and `tempDirectory`.
The Rust `ConfigOptions` struct that backs `SessionConfig` carries roughly 200
keys split across seven sections (`datafusion.catalog.*`,
`datafusion.execution.*`, `datafusion.optimizer.*`, `datafusion.sql_parser.*`,
`datafusion.explain.*`, `datafusion.format.*`, plus user `extensions`). The
Java builder reaches none of these except the six it names explicitly, and
there is no Java surface to read any config value back at all.
DataFusion already exposes string-keyed get/set on its config
(`ConfigOptions::set(key, value)` and `ConfigOptions::entries()`). This PR
mirrors that surface in Java rather than adding ~200 named setters and ~200
getters one at a time.
## What changes are included in this PR?
<!--
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.
-->
- One additive field on the existing `SessionOptions` proto: `map<string,
string> options = 7;`. No existing field changes; wire format stays backward
and forward compatible.
- Two new methods on `SessionContextBuilder`:
- `setOption(String key, String value)` — single entry.
- `setOptions(Map<String, String> entries)` — bulk apply.
- One new method on `SessionContext`:
- `getOption(String key) → String` — read the current value of any
`datafusion.*` config key. Returns the value as a string, or `null` if the key
is recognised but has no value set and no default. Throws `RuntimeException` on
unknown keys (mirrors `setOption`'s strictness for fast feedback on typos), and
`IllegalStateException` when called on a closed context.
- Native side:
- `createSessionContextWithOptions` applies map entries via
`config.options_mut().set(k, v)?` **after** the typed setters, so an explicit
`setOption` call overrides a typed setter for the same knob.
- New `getOptionNative` JNI handler walks
`ctx.copied_config().options().entries()`.
The Rust calls use the `?` form (rather than
`SessionConfig::set_str(...).unwrap()`) so unknown keys or unparseable values
surface as a `RuntimeException` on the Java side carrying DataFusion's error
message, instead of panicking the JVM.
## Are these changes tested?
<!--
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)?
-->
Yes, 12 new tests in `SessionContextBuilderTest`
## Are there any user-facing changes?
<!--
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.
-->
Yes — purely additive. New public API:
- `SessionContextBuilder.setOption(String, String)`
- `SessionContextBuilder.setOptions(Map<String, String>)`
- `SessionContext.getOption(String) → String`
The new `options` field is also exposed on the existing
`org.apache.datafusion.protobuf.SessionOptions` generated class
(`getOptionsMap()` etc.). No API removals, no deprecations, no behavior change
for callers who don't call any of the new methods.
--
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]