Skip to content

Commit 94a33eb

Browse files
committed
fix EsqlNodeSubclassTests
1 parent 41bcae9 commit 94a33eb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/tree/EsqlNodeSubclassTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.core.PathUtils;
1616
import org.elasticsearch.core.SuppressForbidden;
1717
import org.elasticsearch.dissect.DissectParser;
18+
import org.elasticsearch.index.IndexMode;
1819
import org.elasticsearch.test.ESTestCase;
1920
import org.elasticsearch.xpack.core.enrich.EnrichPolicy;
2021
import org.elasticsearch.xpack.esql.core.capabilities.UnresolvedException;
@@ -42,14 +43,18 @@
4243
import org.elasticsearch.xpack.esql.expression.predicate.fulltext.FullTextPredicate;
4344
import org.elasticsearch.xpack.esql.index.EsIndex;
4445
import org.elasticsearch.xpack.esql.plan.logical.Dissect;
46+
import org.elasticsearch.xpack.esql.plan.logical.EsRelation;
47+
import org.elasticsearch.xpack.esql.plan.logical.Fork;
4548
import org.elasticsearch.xpack.esql.plan.logical.Grok;
4649
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
50+
import org.elasticsearch.xpack.esql.plan.logical.Merge;
4751
import org.elasticsearch.xpack.esql.plan.logical.join.JoinConfig;
4852
import org.elasticsearch.xpack.esql.plan.logical.join.JoinType;
4953
import org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes;
5054
import org.elasticsearch.xpack.esql.plan.physical.EsQueryExec;
5155
import org.elasticsearch.xpack.esql.plan.physical.EsStatsQueryExec.Stat;
5256
import org.elasticsearch.xpack.esql.plan.physical.EsStatsQueryExec.StatsType;
57+
import org.elasticsearch.xpack.esql.plan.physical.MergeExec;
5358
import org.elasticsearch.xpack.esql.plan.physical.OutputExec;
5459
import org.elasticsearch.xpack.esql.plan.physical.PhysicalPlan;
5560
import org.elasticsearch.xpack.esql.session.Configuration;
@@ -89,6 +94,8 @@
8994
import static org.elasticsearch.xpack.esql.ConfigurationTestUtils.randomConfiguration;
9095
import static org.elasticsearch.xpack.esql.core.type.DataType.GEO_POINT;
9196
import static org.elasticsearch.xpack.esql.index.EsIndexSerializationTests.randomEsIndex;
97+
import static org.elasticsearch.xpack.esql.index.EsIndexSerializationTests.randomIndexNameWithModes;
98+
import static org.elasticsearch.xpack.esql.plan.AbstractNodeSerializationTests.randomFieldAttributes;
9299
import static org.mockito.Mockito.mock;
93100

94101
/**
@@ -441,6 +448,9 @@ public void accept(Page page) {
441448
return randomInt();
442449
} else if (argClass == JoinType.class) {
443450
return JoinTypes.LEFT;
451+
} else if (List.of(Fork.class, Merge.class, MergeExec.class).contains(toBuildClass) && argType == LogicalPlan.class) {
452+
// limit recursion of plans, in order to prevent stackoverflow errors
453+
return randomEsRelation();
444454
}
445455

446456
if (Expression.class == argClass) {
@@ -709,6 +719,16 @@ static EsQueryExec.GeoDistanceSort randomGeoDistanceSort() {
709719
);
710720
}
711721

722+
static EsRelation randomEsRelation() {
723+
return new EsRelation(
724+
SourceTests.randomSource(),
725+
randomIdentifier(),
726+
randomFrom(IndexMode.values()),
727+
randomIndexNameWithModes(),
728+
randomFieldAttributes(0, 10, false)
729+
);
730+
}
731+
712732
static FieldAttribute field(String name, DataType type) {
713733
return new FieldAttribute(Source.EMPTY, name, new EsField(name, type, Collections.emptyMap(), false));
714734
}

0 commit comments

Comments
 (0)