6565import org .elasticsearch .xpack .esql .core .type .EsField ;
6666import org .elasticsearch .xpack .esql .core .util .Holder ;
6767import org .elasticsearch .xpack .esql .enrich .ResolvedEnrichPolicy ;
68+ import org .elasticsearch .xpack .esql .expression .Foldables ;
6869import org .elasticsearch .xpack .esql .expression .Order ;
6970import org .elasticsearch .xpack .esql .expression .function .EsqlFunctionRegistry ;
7071import org .elasticsearch .xpack .esql .expression .function .aggregate .AggregateFunction ;
@@ -7006,6 +7007,8 @@ public void testEnrichBeforeLimit() {
70067007 as (partialLimit .child (), EsRelation .class );
70077008 }
70087009 {
7010+ // Do not assert serialization:
7011+ // This has local LIMIT which does not serialize to a local LIMIT.
70097012 var plan = physicalPlanNoSerializationCheck ("""
70107013 FROM test
70117014 | EVAL employee_id = to_str(emp_no)
@@ -7061,6 +7064,8 @@ public void testLimitThenEnrich() {
70617064 }
70627065
70637066 public void testLimitThenEnrichRemote () {
7067+ // Do not assert serialization:
7068+ // This has local LIMIT which does not serialize to a local LIMIT.
70647069 var plan = physicalPlanNoSerializationCheck ("""
70657070 FROM test
70667071 | LIMIT 10
@@ -7113,6 +7118,8 @@ public void testEnrichBeforeTopN() {
71137118 as (eval .child (), EsRelation .class );
71147119 }
71157120 {
7121+ // Do not assert serialization:
7122+ // This has local LIMIT which does not serialize to a local LIMIT.
71167123 var plan = physicalPlanNoSerializationCheck ("""
71177124 FROM test
71187125 | EVAL employee_id = to_str(emp_no)
@@ -7130,6 +7137,8 @@ public void testEnrichBeforeTopN() {
71307137 as (eval .child (), EsRelation .class );
71317138 }
71327139 {
7140+ // Do not assert serialization:
7141+ // This has local LIMIT which does not serialize to a local LIMIT.
71337142 var plan = physicalPlanNoSerializationCheck ("""
71347143 FROM test
71357144 | EVAL employee_id = to_str(emp_no)
@@ -7150,6 +7159,8 @@ public void testEnrichBeforeTopN() {
71507159
71517160 public void testEnrichAfterTopN () {
71527161 {
7162+ // Do not assert serialization:
7163+ // This has local LIMIT which does not serialize to a local LIMIT.
71537164 var plan = physicalPlanNoSerializationCheck ("""
71547165 FROM test
71557166 | SORT emp_no
@@ -7186,6 +7197,8 @@ public void testEnrichAfterTopN() {
71867197 as (partialTopN .child (), EsRelation .class );
71877198 }
71887199 {
7200+ // Do not assert serialization:
7201+ // This has local LIMIT which does not serialize to a local LIMIT.
71897202 var plan = physicalPlanNoSerializationCheck ("""
71907203 FROM test
71917204 | SORT emp_no
@@ -7197,13 +7210,14 @@ public void testEnrichAfterTopN() {
71977210 var exchange = as (topN .child (), ExchangeExec .class );
71987211 var fragment = as (exchange .child (), FragmentExec .class );
71997212 var dupTopN = as (fragment .fragment (), TopN .class );
7200- assertThat (dupTopN .limit (). toString () , equalTo ("10" ));
7213+ assertThat (Foldables . limitValue ( dupTopN .limit (), dupTopN . sourceText ()) , equalTo (10 ));
72017214 var enrich = as (dupTopN .child (), Enrich .class );
72027215 assertThat (enrich .mode (), equalTo (Enrich .Mode .REMOTE ));
72037216 assertThat (enrich .concreteIndices (), equalTo (Map .of ("cluster_1" , ".enrich-departments-2" )));
72047217 var evalFragment = as (enrich .child (), Eval .class );
72057218 var partialTopN = as (evalFragment .child (), TopN .class );
7206- assertThat (partialTopN .limit ().toString (), equalTo ("10" ));
7219+ assertThat (Foldables .limitValue (partialTopN .limit (), partialTopN .sourceText ()), equalTo (10 ));
7220+ assertTrue (partialTopN .local ());
72077221 as (partialTopN .child (), EsRelation .class );
72087222 }
72097223 }
0 commit comments