@@ -394,14 +394,27 @@ public void analyzedPlan(
394
394
}
395
395
396
396
var preAnalysis = preAnalyzer .preAnalyze (parsed );
397
+ var result = FieldNameUtils .resolveFieldNames (parsed , preAnalysis .enriches ().isEmpty () == false );
398
+
397
399
EsqlCCSUtils .initCrossClusterState (indicesExpressionGrouper , verifier .licenseState (), preAnalysis .indexPattern (), executionInfo );
398
400
399
- SubscribableListener . //
400
- <EnrichResolution >newForked (l -> enrichPolicyResolver .resolvePolicies (preAnalysis .enriches (), executionInfo , l ))
401
- .<PreAnalysisResult >andThenApply (enrichResolution -> FieldNameUtils .resolveFieldNames (parsed , enrichResolution ))
402
- .<PreAnalysisResult >andThen ((l , r ) -> resolveInferences (parsed , r , l ))
403
- .<PreAnalysisResult >andThen ((l , r ) -> preAnalyzeMainIndices (preAnalysis , executionInfo , r , requestFilter , l ))
401
+ SubscribableListener .<PreAnalysisResult >newForked (l -> preAnalyzeMainIndices (preAnalysis , executionInfo , result , requestFilter , l ))
402
+ .andThenApply (r -> {
403
+ if (r .indices .isValid ()
404
+ && executionInfo .isCrossClusterSearch ()
405
+ && executionInfo .getRunningClusterAliases ().findAny ().isEmpty ()) {
406
+ LOGGER .debug ("No more clusters to search, ending analysis stage" );
407
+ throw new NoClustersToSearchException ();
408
+ }
409
+ return r ;
410
+ })
404
411
.<PreAnalysisResult >andThen ((l , r ) -> preAnalyzeLookupIndices (preAnalysis .lookupIndices ().iterator (), r , executionInfo , l ))
412
+ .<PreAnalysisResult >andThen ((l , r ) -> {
413
+ enrichPolicyResolver .resolvePolicies (preAnalysis .enriches (), executionInfo , l .map (r ::withEnrichResolution ));
414
+ })
415
+ .<PreAnalysisResult >andThen ((l , r ) -> {
416
+ inferenceService .inferenceResolver ().resolveInferenceIds (parsed , l .map (r ::withInferenceResolution ));
417
+ })
405
418
.<LogicalPlan >andThen ((l , r ) -> analyzeWithRetry (parsed , requestFilter , preAnalysis , executionInfo , r , l ))
406
419
.addListener (logicalPlanListener );
407
420
}
@@ -638,9 +651,7 @@ private void preAnalyzeMainIndices(
638
651
if (indexExpressionToResolve .isEmpty ()) {
639
652
// if this was a pure remote CCS request (no local indices) and all remotes are offline, return an empty IndexResolution
640
653
listener .onResponse (
641
- result .withIndexResolution (
642
- IndexResolution .valid (new EsIndex (preAnalysis .indexPattern ().indexPattern (), Map .of (), Map .of ()))
643
- )
654
+ result .withIndices (IndexResolution .valid (new EsIndex (preAnalysis .indexPattern ().indexPattern (), Map .of (), Map .of ())))
644
655
);
645
656
} else {
646
657
indexResolver .resolveAsMergedMapping (
@@ -657,14 +668,15 @@ private void preAnalyzeMainIndices(
657
668
default -> requestFilter ;
658
669
},
659
670
preAnalysis .indexMode () == IndexMode .TIME_SERIES ,
660
- listener .delegateFailure ((l , indexResolution ) -> {
661
- l .onResponse (result .withIndexResolution (indexResolution ));
671
+ listener .delegateFailureAndWrap ((l , indexResolution ) -> {
672
+ EsqlCCSUtils .updateExecutionInfoWithUnavailableClusters (executionInfo , indexResolution .failures ());
673
+ l .onResponse (result .withIndices (indexResolution ));
662
674
})
663
675
);
664
676
}
665
677
} else {
666
678
// occurs when dealing with local relations (row a = 1)
667
- listener .onResponse (result .withIndexResolution (IndexResolution .invalid ("[none specified]" )));
679
+ listener .onResponse (result .withIndices (IndexResolution .invalid ("[none specified]" )));
668
680
}
669
681
}
670
682
@@ -676,21 +688,8 @@ private void analyzeWithRetry(
676
688
PreAnalysisResult result ,
677
689
ActionListener <LogicalPlan > listener
678
690
) {
679
- if (result .indices .isValid ()) {
680
- EsqlCCSUtils .updateExecutionInfoWithUnavailableClusters (executionInfo , result .indices .failures ());
681
- if (executionInfo .isCrossClusterSearch ()
682
- && executionInfo .getClusterStates (EsqlExecutionInfo .Cluster .Status .RUNNING ).findAny ().isEmpty ()) {
683
- // for a CCS, if all clusters have been marked as SKIPPED, nothing to search so send a sentinel Exception
684
- // to let the LogicalPlanActionListener decide how to proceed
685
- LOGGER .debug ("No more clusters to search, ending analysis stage" );
686
- listener .onFailure (new NoClustersToSearchException ());
687
- return ;
688
- }
689
- }
690
-
691
691
var description = requestFilter == null ? "the only attempt without filter" : "first attempt with filter" ;
692
692
LOGGER .debug ("Analyzing the plan ({})" , description );
693
-
694
693
try {
695
694
if (result .indices .isValid () || requestFilter != null ) {
696
695
// We won't run this check with no filter and no valid indices since this may lead to false positive - missing index report
@@ -715,7 +714,6 @@ private void analyzeWithRetry(
715
714
try {
716
715
// the order here is tricky - if the cluster has been filtered and later became unavailable,
717
716
// do we want to declare it successful or skipped? For now, unavailability takes precedence.
718
- EsqlCCSUtils .updateExecutionInfoWithUnavailableClusters (executionInfo , r .indices .failures ());
719
717
EsqlCCSUtils .updateExecutionInfoWithClustersWithNoMatchingIndices (executionInfo , r .indices , false );
720
718
LogicalPlan plan = analyzedPlan (parsed , r , executionInfo );
721
719
LOGGER .debug ("Analyzed plan (second attempt without filter):\n {}" , plan );
@@ -730,10 +728,6 @@ private void analyzeWithRetry(
730
728
}
731
729
}
732
730
733
- private void resolveInferences (LogicalPlan plan , PreAnalysisResult preAnalysisResult , ActionListener <PreAnalysisResult > l ) {
734
- inferenceService .inferenceResolver ().resolveInferenceIds (plan , l .map (preAnalysisResult ::withInferenceResolution ));
735
- }
736
-
737
731
private PhysicalPlan logicalPlanToPhysicalPlan (LogicalPlan optimizedPlan , EsqlQueryRequest request ) {
738
732
PhysicalPlan physicalPlan = optimizedPhysicalPlan (optimizedPlan );
739
733
physicalPlan = physicalPlan .transformUp (FragmentExec .class , f -> {
@@ -793,43 +787,33 @@ public PhysicalPlan optimizedPhysicalPlan(LogicalPlan optimizedPlan) {
793
787
}
794
788
795
789
public record PreAnalysisResult (
790
+ Set <String > fieldNames ,
791
+ Set <String > wildcardJoinIndices ,
796
792
IndexResolution indices ,
797
793
Map <String , IndexResolution > lookupIndices ,
798
794
EnrichResolution enrichResolution ,
799
- Set <String > fieldNames ,
800
- Set <String > wildcardJoinIndices ,
801
795
InferenceResolution inferenceResolution
802
796
) {
803
797
804
- public PreAnalysisResult (EnrichResolution enrichResolution , Set <String > fieldNames , Set <String > wildcardJoinIndices ) {
805
- this (null , new HashMap <>(), enrichResolution , fieldNames , wildcardJoinIndices , InferenceResolution .EMPTY );
798
+ public PreAnalysisResult (Set <String > fieldNames , Set <String > wildcardJoinIndices ) {
799
+ this (fieldNames , wildcardJoinIndices , null , new HashMap <>(), null , InferenceResolution .EMPTY );
806
800
}
807
801
808
- PreAnalysisResult withInferenceResolution (InferenceResolution newInferenceResolution ) {
809
- return new PreAnalysisResult (
810
- indices (),
811
- lookupIndices (),
812
- enrichResolution (),
813
- fieldNames (),
814
- wildcardJoinIndices (),
815
- newInferenceResolution
816
- );
802
+ PreAnalysisResult withIndices (IndexResolution indices ) {
803
+ return new PreAnalysisResult (fieldNames , wildcardJoinIndices , indices , lookupIndices , enrichResolution , inferenceResolution );
817
804
}
818
805
819
- PreAnalysisResult withIndexResolution (IndexResolution newIndexResolution ) {
820
- return new PreAnalysisResult (
821
- newIndexResolution ,
822
- lookupIndices (),
823
- enrichResolution (),
824
- fieldNames (),
825
- wildcardJoinIndices (),
826
- inferenceResolution ()
827
- );
806
+ PreAnalysisResult addLookupIndexResolution (String index , IndexResolution indexResolution ) {
807
+ lookupIndices .put (index , indexResolution );
808
+ return this ;
828
809
}
829
810
830
- PreAnalysisResult addLookupIndexResolution (String index , IndexResolution newIndexResolution ) {
831
- lookupIndices .put (index , newIndexResolution );
832
- return this ;
811
+ PreAnalysisResult withEnrichResolution (EnrichResolution enrichResolution ) {
812
+ return new PreAnalysisResult (fieldNames , wildcardJoinIndices , indices , lookupIndices , enrichResolution , inferenceResolution );
813
+ }
814
+
815
+ PreAnalysisResult withInferenceResolution (InferenceResolution inferenceResolution ) {
816
+ return new PreAnalysisResult (fieldNames , wildcardJoinIndices , indices , lookupIndices , enrichResolution , inferenceResolution );
833
817
}
834
818
}
835
819
}
0 commit comments