NoahKusaba opened a new pull request, #2940:
URL: https://github.com/apache/datafusion-ballista/pull/2940
# Which issue does this PR close?
Part of #2881: the hook in Ballista's core. ballista-iceberg uses it once it
moves to DataFusion 56.
# Rationale for this change
Some things a query reads should be decided each time it runs, not when it's
planned, such as which version of an Iceberg table to read. DataFusion decides
that in `TableProvider::scan`. In Ballista the client never calls `scan`, and
the scheduler physically plans a single job in several places (semi-join
sizing, the adaptive planner, explain), so loading a table there could give one
query several versions.
So ballista-iceberg picks each table's version when the table is looked up.
That means a view, a reused `DataFrame` or a Flight SQL prepared statement
keeps reading the version from when it was planned, and every lookup does
catalog I/O. #2784 works around this for views by re-pinning a view's plan at
lookup.
An integration can't run code once per query today. `upgrade_for_ballista`
builds `BallistaQueryPlanner` with the scheduler's URL, which an integration
never sees, so it can't wrap the planner. Flight SQL queries are planned on the
scheduler, not by that planner at all.
# What changes are included in this PR?
- **`LogicalPlanHook`** (`ballista_core::logical_plan_hook`): an async trait
with one method, `before_submit(plan, session) -> Result<LogicalPlan>`.
- **`SessionConfigExt::with_ballista_logical_plan_hook`** adds a hook after
those already added, and `ballista_logical_plan_hooks` returns them. They run
in that order, so two integrations compose instead of one replacing the other.
- **Hooks run once each time a query is submitted, on the node that planned
it:**
- the client, in `BallistaQueryPlanner::create_physical_plan`, for every
plan it sends to the cluster, including EXPLAIN ANALYZE's inner plan. Plans
that run on the client, such as `SHOW` or a query of `information_schema`
alone, don't run them.
- the scheduler, in the Flight SQL backend's `execute`, before the job is
submitted. A plan sent by a client isn't hooked again on the scheduler, so each
hook runs once per query.
- **A hook's error fails the query with that error, unchanged.**
- **Docs:** the configuration guide lists the new method and what a hook is
for.
Wrapping the `QueryPlanner` instead was considered. It runs on every
physical planning, several times for one job on the scheduler, rather than once
per run. It also needs the scheduler's URL, and each integration would have to
forward Ballista's local-plan special cases.
# Are these changes tested?
Yes:
- **ballista-core unit tests:** a plan without hooks is unchanged; hooks run
in the order they were added; a hook's error is returned unchanged.
- **`ballista/client/tests/logical_plan_hook.rs`** (standalone): a hook
swaps a table for its next version on each run, so running one `DataFrame`
twice reads the first version and then the second. A hook's error fails the
query with it, and a query of `information_schema` alone still runs on the
client without the hook.
- **`ballista/scheduler/tests/flight_sql.rs`:** a Flight SQL prepared
statement executed twice reads the first version and then the second.
# Are there any user-facing changes?
A new public trait and two `SessionConfigExt` methods. Nothing changes for a
session without hooks.
# Follow-ups
The integration half of #2881. ballista-iceberg moves to DataFusion 56 at a
commit that includes this, then pins tables in a hook instead of at lookup.
That removes its pinning catalog wrappers, and #2784 with them.
--
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]