Skip to content

Commit f547325

Browse files
Switch to check number of attrs and their datatypes
1 parent 554f062 commit f547325

File tree

6 files changed

+42
-9
lines changed

6 files changed

+42
-9
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/Attribute.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,16 @@ public static boolean semanticEquals(List<Attribute> left, List<Attribute> right
146146
}
147147
return true;
148148
}
149+
150+
public static boolean datatypeEquals(List<Attribute> left, List<Attribute> right) {
151+
if (left.size() != right.size()) {
152+
return false;
153+
}
154+
for (int i = 0; i < left.size(); i++) {
155+
if (left.get(i).dataType().equals(right.get(i).dataType()) == false) {
156+
return false;
157+
}
158+
}
159+
return true;
160+
}
149161
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/LogicalVerifier.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
1515

1616
import static org.elasticsearch.xpack.esql.common.Failure.fail;
17+
import static org.elasticsearch.xpack.esql.core.expression.Attribute.datatypeEquals;
1718
import static org.elasticsearch.xpack.esql.core.expression.Attribute.semanticEquals;
1819

1920
public final class LogicalVerifier {
@@ -50,7 +51,7 @@ public Failures verify(LogicalPlan planAfter, boolean skipRemoteEnrichVerificati
5051
}
5152
});
5253

53-
if (semanticEquals(planBefore.output(), planAfter.output()) == false) {
54+
if (datatypeEquals(planBefore.output(), planAfter.output()) == false) {
5455
failures.add(
5556
fail(planAfter, "Layout has changed from [{}] to [{}]. ", planBefore.output().toString(), planAfter.output().toString())
5657
);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/PhysicalVerifier.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
import org.elasticsearch.xpack.esql.optimizer.rules.PlanConsistencyChecker;
1515
import org.elasticsearch.xpack.esql.plan.logical.Enrich;
1616
import org.elasticsearch.xpack.esql.plan.physical.EnrichExec;
17+
import org.elasticsearch.xpack.esql.plan.physical.EsQueryExec;
1718
import org.elasticsearch.xpack.esql.plan.physical.FieldExtractExec;
1819
import org.elasticsearch.xpack.esql.plan.physical.PhysicalPlan;
1920

21+
import static org.elasticsearch.index.IndexMode.LOOKUP;
2022
import static org.elasticsearch.xpack.esql.common.Failure.fail;
23+
import static org.elasticsearch.xpack.esql.core.expression.Attribute.datatypeEquals;
24+
import static org.elasticsearch.xpack.esql.core.expression.Attribute.semanticEquals;
2125

2226
/** Physical plan verifier. */
2327
public final class PhysicalVerifier {
@@ -67,10 +71,12 @@ public Failures verify(PhysicalPlan planAfter, boolean skipRemoteEnrichVerificat
6771
}
6872
});
6973

70-
if (planBefore.output().equals(planAfter.output()) == false) {
71-
failures.add(
72-
fail(planAfter, "Layout has changed from [{}] to [{}]. ", planBefore.output().toString(), planAfter.output().toString())
73-
);
74+
if (datatypeEquals(planBefore.output(), planAfter.output()) == false) {
75+
if ((planAfter instanceof EsQueryExec esQueryExec && esQueryExec.indexMode() == LOOKUP) == false) {
76+
failures.add(
77+
fail(planAfter, "Layout has changed from [{}] to [{}]. ", planBefore.output().toString(), planAfter.output().toString())
78+
);
79+
}
7480
}
7581

7682
if (depFailures.hasFailures()) {

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/PlannerUtils.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,15 @@ public static PhysicalPlan localPlan(
185185
) {
186186
final LocalMapper localMapper = new LocalMapper();
187187
var isCoordPlan = new Holder<>(Boolean.TRUE);
188-
188+
/*Set<FragmentExec> fragmentExecsUnderLookupJoin = new HashSet<>();
189+
plan.forEachDown(LookupJoinExec.class, lookupJoin -> {
190+
;
191+
// If the LookupJoinExec is the parent of a FragmentExec, we need to skip it
192+
if (lookupJoin.right() instanceof FragmentExec fragmentExec) {
193+
// this change is disabled for now, as it seems physicalOptimizer.localOptimize is still needed even for lookup joins
194+
// fragmentExecsUnderLookupJoin.add(fragmentExec);
195+
}
196+
});*/
189197
var localPhysicalPlan = plan.transformUp(FragmentExec.class, f -> {
190198
isCoordPlan.set(Boolean.FALSE);
191199
var optimizedFragment = logicalOptimizer.localOptimize(f.fragment());
@@ -204,7 +212,12 @@ public static PhysicalPlan localPlan(
204212
)
205213
);
206214
}
207-
var localOptimized = physicalOptimizer.localOptimize(physicalFragment);
215+
PhysicalPlan localOptimized = physicalOptimizer.localOptimize(physicalFragment);
216+
/*if (fragmentExecsUnderLookupJoin.contains(f)) {
217+
localOptimized = physicalFragment;
218+
} else {
219+
localOptimized = physicalOptimizer.localOptimize(physicalFragment);
220+
}*/
208221
return EstimatesRowSize.estimateRowSize(f.estimatedRowSize(), localOptimized);
209222
});
210223
return isCoordPlan.get() ? plan : localPhysicalPlan;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/rule/RuleExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ protected final ExecutionInfo executeWithInfo(TreeType plan) {
175175
if (tf.hasChanged()) {
176176
hasChanged = true;
177177
if (log.isTraceEnabled()) {
178-
log.trace("Rule {} applied\n{}", rule, NodeUtils.diffString(tf.before, tf.after));
178+
log.trace("Rule {} applied with change\n{}", rule, NodeUtils.diffString(tf.before, tf.after));
179179
}
180180
} else {
181181
if (log.isTraceEnabled()) {

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LocalPhysicalPlanOptimizerTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.elasticsearch.search.vectors.KnnVectorQueryBuilder;
3232
import org.elasticsearch.search.vectors.RescoreVectorBuilder;
3333
import org.elasticsearch.test.VersionUtils;
34+
import org.elasticsearch.test.junit.annotations.TestLogging;
3435
import org.elasticsearch.xpack.core.enrich.EnrichPolicy;
3536
import org.elasticsearch.xpack.esql.EsqlTestUtils;
3637
import org.elasticsearch.xpack.esql.EsqlTestUtils.TestSearchStats;
@@ -146,7 +147,7 @@
146147
import static org.hamcrest.Matchers.is;
147148
import static org.hamcrest.Matchers.nullValue;
148149

149-
//@TestLogging(value = "org.elasticsearch.xpack.esql:TRACE,org.elasticsearch.compute:TRACE", reason = "debug")
150+
@TestLogging(value = "org.elasticsearch.xpack.esql:TRACE,org.elasticsearch.compute:TRACE", reason = "debug")
150151
public class LocalPhysicalPlanOptimizerTests extends MapperServiceTestCase {
151152

152153
public static final List<DataType> UNNECESSARY_CASTING_DATA_TYPES = List.of(

0 commit comments

Comments
 (0)