|
1 | 1 | mod scan_result; |
2 | 2 |
|
3 | | -use crate::FederationProvider; |
4 | 3 | use crate::{FederatedTableProviderAdaptor, FederatedTableSource, FederationProviderRef}; |
| 4 | +use crate::{FederationAnalyzerForLogicalPlan, FederationProvider}; |
5 | 5 | use datafusion::logical_expr::{col, expr::InSubquery, LogicalPlanBuilder}; |
6 | 6 | use datafusion::optimizer::eliminate_nested_union::EliminateNestedUnion; |
7 | 7 | use datafusion::optimizer::push_down_filter::PushDownFilter; |
@@ -243,12 +243,12 @@ impl FederationAnalyzerRule { |
243 | 243 | // The largest sub-plan is higher up. |
244 | 244 | return Ok((None, ScanResult::Distinct(provider))); |
245 | 245 | } |
246 | | - (true, Some(analyzer)) => { |
| 246 | + (true, Some(FederationAnalyzerForLogicalPlan::With(analyzer))) => { |
247 | 247 | // If this is the root plan node; federate the entire plan |
248 | 248 | let optimized = analyzer.execute_and_check(plan.clone(), config, |_, _| {})?; |
249 | 249 | return Ok((Some(optimized), ScanResult::None)); |
250 | 250 | } |
251 | | - (_, None) => { |
| 251 | + (_, None | Some(FederationAnalyzerForLogicalPlan::Unable)) => { |
252 | 252 | // Provider CAN'T federate this specific plan shape |
253 | 253 | // Fall through to try federating children instead |
254 | 254 | } |
@@ -282,7 +282,9 @@ impl FederationAnalyzerRule { |
282 | 282 | return Ok(original_input); |
283 | 283 | }; |
284 | 284 |
|
285 | | - let Some(analyzer) = provider.analyzer(&original_input) else { |
| 285 | + let Some(FederationAnalyzerForLogicalPlan::With(analyzer)) = |
| 286 | + provider.analyzer(&original_input) |
| 287 | + else { |
286 | 288 | // Either provider has no analyzer, or cannot federate [`LogicalPlan`]. |
287 | 289 | return Ok(original_input); |
288 | 290 | }; |
@@ -413,26 +415,19 @@ impl FederationAnalyzerRule { |
413 | 415 | #[derive(Debug)] |
414 | 416 | pub(crate) struct NopFederationProvider {} |
415 | 417 |
|
416 | | -pub static NOP_NAME: &str = "nop"; |
417 | | - |
418 | 418 | impl FederationProvider for NopFederationProvider { |
419 | 419 | fn name(&self) -> &str { |
420 | | - NOP_NAME |
| 420 | + "nop" |
421 | 421 | } |
422 | 422 |
|
423 | 423 | fn compute_context(&self) -> Option<String> { |
424 | 424 | None |
425 | 425 | } |
426 | 426 |
|
427 | | - fn analyzer(&self, _plan: &LogicalPlan) -> Option<Arc<datafusion::optimizer::Analyzer>> { |
| 427 | + fn analyzer(&self, _plan: &LogicalPlan) -> Option<FederationAnalyzerForLogicalPlan> { |
428 | 428 | None |
429 | 429 | } |
430 | 430 | } |
431 | | -impl NopFederationProvider { |
432 | | - pub fn is_nop(provider: Arc<dyn FederationProvider>) -> bool { |
433 | | - provider.name() == NOP_NAME |
434 | | - } |
435 | | -} |
436 | 431 |
|
437 | 432 | /// Recursively find the [`FederationProvider`] for all [`TableReference`] instances in the plan. |
438 | 433 | /// This is used to resolve the federation providers for [`Expr::OuterReferenceColumn`]. |
@@ -474,7 +469,7 @@ fn wrap_projection(plan: LogicalPlan) -> Result<LogicalPlan> { |
474 | 469 | fn contains_federated_table(plan: &LogicalPlan) -> Result<bool> { |
475 | 470 | let federated_table_exists = plan.exists(|x| { |
476 | 471 | if let (Some(provider), _) = get_leaf_provider(x)? { |
477 | | - return Ok(!NopFederationProvider::is_nop(provider)); |
| 472 | + return Ok(provider.analyzer(plan).is_some()); |
478 | 473 | } |
479 | 474 | Ok(false) |
480 | 475 | })?; |
|
0 commit comments