Example rewrite pass which impacts validity of the extension node.
(
&self,
plan: LogicalPlan,
_config: &dyn OptimizerConfig,
)
| 429 | |
| 430 | // Example rewrite pass which impacts validity of the extension node. |
| 431 | fn rewrite( |
| 432 | &self, |
| 433 | plan: LogicalPlan, |
| 434 | _config: &dyn OptimizerConfig, |
| 435 | ) -> Result<Transformed<LogicalPlan>, DataFusionError> { |
| 436 | if let LogicalPlan::Extension(Extension { node }) = &plan |
| 437 | && let Some(prev) = node.as_any().downcast_ref::<TopKPlanNode>() |
| 438 | { |
| 439 | return Ok(Transformed::yes(LogicalPlan::Extension(Extension { |
| 440 | node: Arc::new(TopKPlanNode { |
| 441 | k: prev.k, |
| 442 | input: prev.input.clone(), |
| 443 | expr: prev.expr.clone(), |
| 444 | // In a real use case, this rewriter could have change the number of inputs, etc |
| 445 | invariant_mock: Some(InvariantMock { |
| 446 | should_fail_invariant: true, |
| 447 | kind: InvariantLevel::Always, |
| 448 | }), |
| 449 | }), |
| 450 | }))); |
| 451 | }; |
| 452 | |
| 453 | Ok(Transformed::no(plan)) |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | // ------ The implementation of the TopK code follows ----- |