@@ -71,12 +71,6 @@ public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichReso
7171 inlinestatsAggs .add (((InlineStats ) i ).aggregate ());
7272 }
7373
74- if (false == parsed .anyMatch (p -> shouldCollectReferencedFields (p , inlinestatsAggs ))) {
75- // no explicit columns selection, for example "from employees"
76- // also, inlinestats only adds columns to the existent output, its Aggregate shouldn't interfere with potentially using "*"
77- return new PreAnalysisResult (enrichResolution , IndexResolver .ALL_FIELDS , Set .of ());
78- }
79-
8074 Holder <Boolean > projectAll = new Holder <>(false );
8175 parsed .forEachExpressionDown (UnresolvedStar .class , us -> {// explicit "*" fields selection
8276 if (projectAll .get ()) {
@@ -107,6 +101,7 @@ public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichReso
107101 Set <String > wildcardJoinIndices = new java .util .HashSet <>();
108102
109103 var canRemoveAliases = new Holder <>(true );
104+ var needsAllFields = new Holder <>(parsed .anyMatch (p -> shouldCollectReferencedFields (p , inlinestatsAggs )) == false );
110105
111106 var processingLambda = new Holder <Function <LogicalPlan , Boolean >>();
112107 processingLambda .set ((LogicalPlan p ) -> {// go over each plan top-down
@@ -120,6 +115,10 @@ public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichReso
120115 var return_result = child .forEachDownMayReturnEarly (processingLambda .get ());
121116 // No nested Forks for now...
122117 assert return_result ;
118+ if (referencesBuilder .get ().isEmpty ()) {
119+ needsAllFields .set (true );
120+ return true ;
121+ }
123122 forkRefsResult .addAll (referencesBuilder .get ());
124123 }
125124
@@ -210,6 +209,12 @@ public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichReso
210209 });
211210 parsed .forEachDownMayReturnEarly (processingLambda .get ());
212211
212+ if (needsAllFields .get ()) {
213+ // no explicit columns selection, for example "from employees"
214+ // also, inlinestats only adds columns to the existent output, its Aggregate shouldn't interfere with potentially using "*"
215+ return new PreAnalysisResult (enrichResolution , IndexResolver .ALL_FIELDS , Set .of ());
216+ }
217+
213218 // Add JOIN ON column references afterward to avoid Alias removal
214219 referencesBuilder .get ().addAll (joinRefs );
215220 // If any JOIN commands need wildcard field-caps calls, persist the index names
0 commit comments