6363import org .elasticsearch .xpack .esql .core .expression .Attribute ;
6464import org .elasticsearch .xpack .esql .enrich .EnrichLookupService ;
6565import org .elasticsearch .xpack .esql .enrich .LookupFromIndexService ;
66- import org .elasticsearch .xpack .esql .plan .logical .EsRelation ;
67- import org .elasticsearch .xpack .esql .plan .logical .join .Join ;
6866import org .elasticsearch .xpack .esql .plan .physical .ExchangeSinkExec ;
6967import org .elasticsearch .xpack .esql .plan .physical .ExchangeSourceExec ;
70- import org .elasticsearch .xpack .esql .plan .physical .FragmentExec ;
71- import org .elasticsearch .xpack .esql .plan .physical .LookupJoinExec ;
7268import org .elasticsearch .xpack .esql .plan .physical .OutputExec ;
7369import org .elasticsearch .xpack .esql .plan .physical .PhysicalPlan ;
7470import org .elasticsearch .xpack .esql .planner .EsPhysicalOperationProviders ;
8177import java .util .Arrays ;
8278import java .util .Collections ;
8379import java .util .HashMap ;
84- import java .util .HashSet ;
8580import java .util .List ;
8681import java .util .Map ;
8782import java .util .Set ;
@@ -167,11 +162,9 @@ public void execute(
167162 Map <String , OriginalIndices > clusterToConcreteIndices = transportService .getRemoteClusterService ()
168163 .groupIndices (SearchRequest .DEFAULT_INDICES_OPTIONS , PlannerUtils .planConcreteIndices (physicalPlan ).toArray (String []::new ));
169164 QueryPragmas queryPragmas = configuration .pragmas ();
170- Set <String > lookupIndexNames = findLookupIndexNames (physicalPlan );
171- Set <String > concreteIndexNames = selectConcreteIndices (clusterToConcreteIndices , lookupIndexNames );
172165 if (dataNodePlan == null ) {
173- if (concreteIndexNames . isEmpty ( ) == false ) {
174- String error = "expected no concrete indices without data node plan; got " + concreteIndexNames ;
166+ if (clusterToConcreteIndices . values (). stream (). allMatch ( v -> v . indices (). length == 0 ) == false ) {
167+ String error = "expected no concrete indices without data node plan; got " + clusterToConcreteIndices ;
175168 assert false : error ;
176169 listener .onFailure (new IllegalStateException (error ));
177170 return ;
@@ -194,7 +187,7 @@ public void execute(
194187 return ;
195188 }
196189 } else {
197- if (concreteIndexNames . isEmpty ( )) {
190+ if (clusterToConcreteIndices . values (). stream (). allMatch ( v -> v . indices (). length == 0 )) {
198191 var error = "expected concrete indices with data node plan but got empty; data node plan " + dataNodePlan ;
199192 assert false : error ;
200193 listener .onFailure (new IllegalStateException (error ));
@@ -268,42 +261,6 @@ public void execute(
268261 }
269262 }
270263
271- private Set <String > selectConcreteIndices (Map <String , OriginalIndices > clusterToConcreteIndices , Set <String > indexesToIgnore ) {
272- Set <String > concreteIndexNames = new HashSet <>();
273- clusterToConcreteIndices .forEach ((clusterAlias , concreteIndices ) -> {
274- for (String index : concreteIndices .indices ()) {
275- if (indexesToIgnore .contains (index ) == false ) {
276- concreteIndexNames .add (index );
277- }
278- }
279- });
280- return concreteIndexNames ;
281- }
282-
283- private Set <String > findLookupIndexNames (PhysicalPlan physicalPlan ) {
284- Set <String > lookupIndexNames = new HashSet <>();
285- // When planning JOIN on the coordinator node: "LookupJoinExec.lookup()->FragmentExec.fragment()->EsRelation.index()"
286- physicalPlan .forEachDown (
287- LookupJoinExec .class ,
288- lookupJoinExec -> lookupJoinExec .lookup ()
289- .forEachDown (
290- FragmentExec .class ,
291- frag -> frag .fragment ().forEachDown (EsRelation .class , esRelation -> lookupIndexNames .add (esRelation .index ().name ()))
292- )
293- );
294- // When planning JOIN on the data node: "FragmentExec.fragment()->Join.right()->EsRelation.index()"
295- // TODO this only works for LEFT join, so we still need to support RIGHT join
296- physicalPlan .forEachDown (
297- FragmentExec .class ,
298- fragmentExec -> fragmentExec .fragment ()
299- .forEachDown (
300- Join .class ,
301- join -> join .right ().forEachDown (EsRelation .class , esRelation -> lookupIndexNames .add (esRelation .index ().name ()))
302- )
303- );
304- return lookupIndexNames ;
305- }
306-
307264 // For queries like: FROM logs* | LIMIT 0 (including cross-cluster LIMIT 0 queries)
308265 private static void updateShardCountForCoordinatorOnlyQuery (EsqlExecutionInfo execInfo ) {
309266 if (execInfo .isCrossClusterSearch ()) {
0 commit comments