|
78 | 78 | import java.util.ArrayList; |
79 | 79 | import java.util.Collection; |
80 | 80 | import java.util.HashMap; |
| 81 | +import java.util.Iterator; |
81 | 82 | import java.util.List; |
82 | 83 | import java.util.Map; |
83 | 84 | import java.util.Set; |
@@ -372,22 +373,34 @@ public void analyzedPlan( |
372 | 373 | return; |
373 | 374 | } |
374 | 375 |
|
375 | | - PreAnalyzer.PreAnalysis preAnalysis = preAnalyzer.preAnalyze(parsed); |
| 376 | + var preAnalysis = preAnalyzer.preAnalyze(parsed); |
376 | 377 | EsqlCCSUtils.initCrossClusterState(indicesExpressionGrouper, verifier.licenseState(), preAnalysis.indices, executionInfo); |
377 | 378 |
|
378 | | - var listener = SubscribableListener. // |
| 379 | + SubscribableListener. // |
379 | 380 | <EnrichResolution>newForked(l -> enrichPolicyResolver.resolvePolicies(preAnalysis.enriches, executionInfo, l)) |
380 | 381 | .<PreAnalysisResult>andThenApply(enrichResolution -> FieldNameUtils.resolveFieldNames(parsed, enrichResolution)) |
381 | | - .<PreAnalysisResult>andThen((l, preAnalysisResult) -> resolveInferences(parsed, preAnalysisResult, l)); |
382 | | - // first resolve the lookup indices, then the main indices |
383 | | - for (var index : preAnalysis.lookupIndices) { |
384 | | - listener = listener.andThen((l, preAnalysisResult) -> preAnalyzeLookupIndex(index, preAnalysisResult, executionInfo, l)); |
385 | | - } |
386 | | - listener.<PreAnalysisResult>andThen((l, result) -> preAnalyzeMainIndices(preAnalysis, executionInfo, result, requestFilter, l)) |
387 | | - .<LogicalPlan>andThen((l, result) -> analyzeWithRetry(parsed, requestFilter, preAnalysis, executionInfo, result, l)) |
| 382 | + .<PreAnalysisResult>andThen((l, r) -> resolveInferences(parsed, r, l)) |
| 383 | + .<PreAnalysisResult>andThen((l, r) -> preAnalyzeLookupIndices(preAnalysis.lookupIndices.iterator(), r, executionInfo, l)) |
| 384 | + .<PreAnalysisResult>andThen((l, r) -> preAnalyzeMainIndices(preAnalysis, executionInfo, r, requestFilter, l)) |
| 385 | + .<LogicalPlan>andThen((l, r) -> analyzeWithRetry(parsed, requestFilter, preAnalysis, executionInfo, r, l)) |
388 | 386 | .addListener(logicalPlanListener); |
389 | 387 | } |
390 | 388 |
|
| 389 | + private void preAnalyzeLookupIndices( |
| 390 | + Iterator<IndexPattern> lookupIndices, |
| 391 | + PreAnalysisResult preAnalysisResult, |
| 392 | + EsqlExecutionInfo executionInfo, |
| 393 | + ActionListener<PreAnalysisResult> listener |
| 394 | + ) { |
| 395 | + if (lookupIndices.hasNext()) { |
| 396 | + preAnalyzeLookupIndex(lookupIndices.next(), preAnalysisResult, executionInfo, listener.delegateFailureAndWrap((l, r) -> { |
| 397 | + preAnalyzeLookupIndices(lookupIndices, r, executionInfo, l); |
| 398 | + })); |
| 399 | + } else { |
| 400 | + listener.onResponse(preAnalysisResult); |
| 401 | + } |
| 402 | + } |
| 403 | + |
391 | 404 | private void preAnalyzeLookupIndex( |
392 | 405 | IndexPattern lookupIndexPattern, |
393 | 406 | PreAnalysisResult result, |
|
0 commit comments