shyjsarah opened a new pull request, #345:
URL: https://github.com/apache/paimon-rust/pull/345
### Purpose
`SQLContext::register_catalog` always probes/creates a `"default"`
database and calls `set_current_database("default")` on the first catalog. This
breaks for non-admin principals who lack `DESCRIBE` / `CREATEDATABASE` on
`default`: they cannot construct a `SQLContext` at all, even when their queries
target databases they do have access to (via fully-qualified `catalog.db.table`
names). The error surfaces at session init as e.g. `Forbidden: ... DESCRIBE on
DATABASE default`.
This change mirrors Java `FlinkCatalog`'s `defaultDatabase` constructor
parameter and `DISABLE_CREATE_TABLE_IN_DEFAULT_DB` option in Rust.
### Brief change log
- Add `SQLContext::register_catalog_with_default_db(name, catalog,
default_db: Option<&str>)`: `Some(name)` ensures `name` exists (creates if
missing) and sets it as current on the first registered catalog; `None` skips
both the `get_database` probe and the implicit `set_current_database` — callers
are expected to use fully-qualified table names
or call `set_current_database` later.
- `register_catalog(name, catalog)` now delegates with `Some("default")` —
fully backwards-compatible.
- Python binding (`pypaimon_rust`): new `default_database` keyword on
`SQLContext.register_catalog`. Convention chosen so omitting the kwarg keeps
the historical behavior: omitted / `None` → `Some("default")` (back-compat);
`""` → `None` (skip init); `"name"` → `Some("name")` (custom default).
### Tests
Added `ProbeTrackingCatalog` which counts `get_database` /
`create_database` calls and returns `Error::Unsupported` (not
`DatabaseNotExist`) from `get_database`, so failing
to skip the probe surfaces as a hard error — mimicking the Forbidden
condition. Three unit tests:
- `register_catalog_with_none_skips_default_db_probe` — `None` results in
0 calls to `get_database` / `create_database`; registration succeeds; current
catalog is set on the
session.
- `register_catalog_with_some_default_propagates_probe_error` —
`Some("default")` runs the probe once and surfaces the underlying error.
- `register_catalog_default_wrapper_uses_default_db` — bare
`register_catalog()` still delegates with `Some("default")` (back-compat).
All existing tests (175 in `paimon-datafusion`) continue to pass. `cargo
check -p paimon-datafusion -p pypaimon_rust` is clean.
### API and Format
New public method `SQLContext::register_catalog_with_default_db`. Existing
`SQLContext::register_catalog` signature and behavior unchanged. Python
`SQLContext.register_catalog` gains an optional `default_database` kwarg;
existing call sites are unaffected. No storage-format changes.
### Documentation
Rustdoc on both methods explains the `default_db` semantics and the
non-admin-principal motivation. Python kwarg's docstring documents the
three-value convention. No external docs update needed.
--
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]