Repository navigation
Automatically check "invariants" #13652
Description
Activity
take
Possible tasks
- Define API to check LP invariant. PR: Introduce LogicalPlan invariants, begin automatically checking them #13651
- Define API to check physical plan invariants: Interface for physical plan invariant checking. #13986
- Explore possible API for user-defined invariants, and potential use cases with user-defined plan elements (e.g. physical plan nodes, analyzer and optimizer rules, etc). Refer to conversation here.
- Consider options (e.g. generate of docs) to align the published docs with the invariants encoded.
- Implement more invariants.
For the physical optimization invariants, we have that the output physical plan schema cannot change; meaning the output results cannot change, but how we get the results can.
What else should be included as a responsibility/check? Maintain input ordering if required?
(The idea is to have a check, perhaps run in debug mode, that would error if a user-defined physical plan or optimization pass fails to maintain the invariant. Throw error closer to the source when debugging.)
For the physical optimization invariants, we have that the output physical plan schema cannot change; meaning the output results cannot change, but how we get the results can.
What else should be included as a responsibility/check? Maintain input ordering if required?
Here are some ideas based on bugs we have hit / my memory of what has changed and caused us pain:
- Union inputs (can there be more than 2 inputs -- we use such plans in InfluxData but I am not sure what if anything else makes assumptions)
- Union input schemas (I think initially they need to be 'coercable' and to be executable they need to be identical)
- Projection_exec can't have zero exprs (is this an invariant?)
My impression was that the plan construction occurred with the LP (as we do), and not by constructing their own de novo physical plan. Is this correct?
If so, then I think the above list of invariants to check would most likely occur at the LP-level (not the physical plan). I can definitely put up a PR for those. Thank you!
Whereas for the physical plan invariants, (not LP), do we want any invariant checking there? Because I looked at the apache docs & physical plan APIs and from (my naive) understanding these are the only two invariants to check after physical plan mutations (a.k.a. PhysicalOptimizerRule applied). Is this correct? 🤔
My impression was that the plan construction occurred with the LP (as we do), and not by constructing their own de novo physical plan. Is this correct?
I am sorry -- I don't understand what you are asking (is LP LogicalPlan?) What does a de novo physical plan mean? You mean like creating a
ExecutionPlandirectly (not from aLogicalPlan)?If so, then I think the above list of invariants to check would most likely occur at the LP-level (not the physical plan). I can definitely put up a PR for those. Thank you!
Whereas for the physical plan invariants, (not LP), do we want any invariant checking there? Because I looked at the apache docs & physical plan APIs and from (my naive) understanding these are the only two invariants to check after physical plan mutations (a.k.a. PhysicalOptimizerRule applied). Is this correct? 🤔
I am not sure what the actual invariants are (part of this project I think is to discover that information)
In my opinion we should be seeking to discover what the existing implicit assumptions are and encode them explicitly in the invariant check. Once we have all the existing assumptions encoded then we can move on to trying to add more assumptions
I just discovered that @houqp basically filed this same ticket 2 years ago:
Reacted by wiedldI suggest we use this ticket to track the infrastructure for checking invariants
Agreed. Modifying this list above, we have infrastructure components of:
- Define infrastructure to check LP invariant. PR: Introduce LogicalPlan invariants, begin automatically checking them #13651
- Define infrastructure to check physical plan invariants: Interface for physical plan invariant checking. #13986
- Define infrastructure for user-defined invariants. See issue: Define extension API for user-defined invariants. #14029
Reacted by Andrew LambTask complete!
Is your feature request related to a problem or challenge?
I extracted this from #13651 so it was more visible
During upgrade, downstream systems often experience issues due to implicit changes (not explicit API changes) of LogicalPlans that DataFusion code begins relying on, and which result in unintended consequences when upgrading to a new version of DataFusion (see #13525).
Describe the solution you'd like
The idea is to make the current implicit assumptions ("Invariants" in more formal language)( explict and automatically check them.
Examples of implicit assumptions:
UnionExecmust have the same schemaDescribe alternatives you've considered
I like the approach @wiedld took in #13651 :
Additional context
Sub tasks: