1111import org .elasticsearch .common .io .stream .NamedWriteableRegistry ;
1212import org .elasticsearch .common .io .stream .Writeable ;
1313import org .elasticsearch .common .settings .Settings ;
14+ import org .elasticsearch .features .NodeFeature ;
1415import org .elasticsearch .index .Index ;
1516import org .elasticsearch .index .IndexMode ;
1617import org .elasticsearch .index .query .TermQueryBuilder ;
3334import org .elasticsearch .xpack .esql .plan .logical .LogicalPlan ;
3435import org .elasticsearch .xpack .esql .plan .physical .PhysicalPlan ;
3536import org .elasticsearch .xpack .esql .planner .mapper .Mapper ;
37+ import org .elasticsearch .xpack .esql .session .Configuration ;
3638
3739import java .io .IOException ;
3840import java .util .ArrayList ;
3941import java .util .List ;
4042import java .util .Map ;
43+ import java .util .stream .Collectors ;
4144
4245import static org .elasticsearch .xpack .esql .ConfigurationTestUtils .randomConfiguration ;
4346import static org .elasticsearch .xpack .esql .ConfigurationTestUtils .randomTables ;
44- import static org .elasticsearch .xpack .esql .EsqlTestUtils .TEST_CFG ;
4547import static org .elasticsearch .xpack .esql .EsqlTestUtils .TEST_VERIFIER ;
4648import static org .elasticsearch .xpack .esql .EsqlTestUtils .emptyPolicyResolution ;
4749import static org .elasticsearch .xpack .esql .EsqlTestUtils .loadMapping ;
@@ -79,14 +81,15 @@ protected DataNodeRequest createTestInstance() {
7981 | stats x = avg(salary)
8082 """ );
8183 List <ShardId > shardIds = randomList (1 , 10 , () -> new ShardId ("index-" + between (1 , 10 ), "n/a" , between (1 , 10 )));
82- PhysicalPlan physicalPlan = mapAndMaybeOptimize (parse (query ));
84+ Configuration configuration = randomLimitedConfiguration (query );
85+ PhysicalPlan physicalPlan = mapAndMaybeOptimize (parse (query , configuration ), configuration );
8386 Map <Index , AliasFilter > aliasFilters = Map .of (
8487 new Index ("concrete-index" , "n/a" ),
8588 AliasFilter .of (new TermQueryBuilder ("id" , "1" ), "alias-1" )
8689 );
8790 DataNodeRequest request = new DataNodeRequest (
8891 sessionId ,
89- randomConfiguration ( query , randomTables ()) ,
92+ configuration ,
9093 randomAlphaOfLength (10 ),
9194 shardIds ,
9295 aliasFilters ,
@@ -164,7 +167,7 @@ protected DataNodeRequest mutateInstance(DataNodeRequest in) throws IOException
164167 in .clusterAlias (),
165168 in .shardIds (),
166169 in .aliasFilters (),
167- mapAndMaybeOptimize (parse (newQuery )),
170+ mapAndMaybeOptimize (parse (newQuery , in . configuration ()), in . configuration ( )),
168171 in .indices (),
169172 in .indicesOptions ()
170173 );
@@ -260,20 +263,20 @@ protected DataNodeRequest mutateInstance(DataNodeRequest in) throws IOException
260263 };
261264 }
262265
263- static LogicalPlan parse (String query ) {
266+ static LogicalPlan parse (String query , Configuration configuration ) {
264267 Map <String , EsField > mapping = loadMapping ("mapping-basic.json" );
265268 EsIndex test = new EsIndex ("test" , mapping , Map .of ("test" , IndexMode .STANDARD ));
266269 IndexResolution getIndexResult = IndexResolution .valid (test );
267- var logicalOptimizer = new LogicalPlanOptimizer (new LogicalOptimizerContext (TEST_CFG ));
270+ var logicalOptimizer = new LogicalPlanOptimizer (new LogicalOptimizerContext (configuration ));
268271 var analyzer = new Analyzer (
269- new AnalyzerContext (EsqlTestUtils . TEST_CFG , new EsqlFunctionRegistry (), getIndexResult , emptyPolicyResolution ()),
272+ new AnalyzerContext (configuration , new EsqlFunctionRegistry (), getIndexResult , emptyPolicyResolution ()),
270273 TEST_VERIFIER
271274 );
272275 return logicalOptimizer .optimize (analyzer .analyze (new EsqlParser ().createStatement (query )));
273276 }
274277
275- static PhysicalPlan mapAndMaybeOptimize (LogicalPlan logicalPlan ) {
276- var physicalPlanOptimizer = new PhysicalPlanOptimizer (new PhysicalOptimizerContext (TEST_CFG ));
278+ static PhysicalPlan mapAndMaybeOptimize (LogicalPlan logicalPlan , Configuration configuration ) {
279+ var physicalPlanOptimizer = new PhysicalPlanOptimizer (new PhysicalOptimizerContext (configuration ));
277280 var mapper = new Mapper ();
278281 var physical = mapper .map (logicalPlan );
279282 if (randomBoolean ()) {
@@ -286,4 +289,29 @@ static PhysicalPlan mapAndMaybeOptimize(LogicalPlan logicalPlan) {
286289 protected List <String > filteredWarnings () {
287290 return withDefaultLimitWarning (super .filteredWarnings ());
288291 }
292+
293+ /**
294+ * Builds a configuration with a fixed limit of 10000 rows and 1000 bytes.
295+ * <p>
296+ * Without this, warnings would be randomized, and hard to filter from the warnings.
297+ * </p>
298+ */
299+ private Configuration randomLimitedConfiguration (String query ) {
300+ Configuration configuration = randomConfiguration (query , randomTables ());
301+
302+ return new Configuration (
303+ configuration .zoneId (),
304+ configuration .locale (),
305+ configuration .username (),
306+ configuration .clusterName (),
307+ configuration .pragmas (),
308+ 10000 ,
309+ 1000 ,
310+ configuration .query (),
311+ configuration .profile (),
312+ configuration .tables (),
313+ configuration .getQueryStartTimeNanos (),
314+ configuration .activeEsqlFeatures ()
315+ );
316+ }
289317}
0 commit comments