Skip to content

Commit ef8fe18

Browse files
Make it type+plan
1 parent 93354e9 commit ef8fe18

File tree

3 files changed

+29
-39
lines changed

3 files changed

+29
-39
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/Explain.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
import org.elasticsearch.common.io.stream.StreamOutput;
1111
import org.elasticsearch.xpack.esql.capabilities.TelemetryAware;
1212
import org.elasticsearch.xpack.esql.core.expression.Attribute;
13-
import org.elasticsearch.xpack.esql.core.expression.ReferenceAttribute;
1413
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1514
import org.elasticsearch.xpack.esql.core.tree.Source;
16-
import org.elasticsearch.xpack.esql.core.type.DataType;
1715

1816
import java.util.List;
1917
import java.util.Objects;
@@ -42,36 +40,13 @@ public String getWriteableName() {
4240
throw new UnsupportedOperationException("not serialized");
4341
}
4442

45-
// TODO: implement again
46-
// @Override
47-
// public void execute(EsqlSession session, ActionListener<Result> listener) {
48-
// ActionListener<String> analyzedStringListener = listener.map(
49-
// analyzed -> new Result(
50-
// output(),
51-
// List.of(List.of(query.toString(), Type.PARSED.toString()), List.of(analyzed, Type.ANALYZED.toString()))
52-
// )
53-
// );
54-
//
55-
// session.analyzedPlan(
56-
// query,
57-
// ActionListener.wrap(
58-
// analyzed -> analyzedStringListener.onResponse(analyzed.toString()),
59-
// e -> analyzedStringListener.onResponse(e.toString())
60-
// )
61-
// );
62-
//
63-
// }
64-
6543
public LogicalPlan query() {
6644
return query;
6745
}
6846

6947
@Override
7048
public List<Attribute> output() {
71-
return List.of(
72-
new ReferenceAttribute(Source.EMPTY, "plan", DataType.KEYWORD),
73-
new ReferenceAttribute(Source.EMPTY, "type", DataType.KEYWORD)
74-
);
49+
throw new UnsupportedOperationException();
7550
}
7651

7752
@Override

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,15 @@ public void executeOptimizedPlan(
238238
if (explainMode) {
239239
String physicalPlanString = physicalPlan.toString();
240240
List<Attribute> fields = List.of(
241-
new ReferenceAttribute(EMPTY, "parsedPlan", DataType.KEYWORD),
242-
new ReferenceAttribute(EMPTY, "optimizedLogicalPlan", DataType.KEYWORD),
243-
new ReferenceAttribute(EMPTY, "optimizedPhysicalPlan", DataType.KEYWORD)
241+
new ReferenceAttribute(EMPTY, "role", DataType.KEYWORD),
242+
new ReferenceAttribute(EMPTY, "type", DataType.KEYWORD),
243+
new ReferenceAttribute(EMPTY, "plan", DataType.KEYWORD)
244244
);
245-
List<Object> values = List.of(parsedPlanString, optimizedLogicalPlanString, physicalPlanString);
246-
var blocks = BlockUtils.fromListRow(PlannerUtils.NON_BREAKING_BLOCK_FACTORY, values);
245+
List<List<Object>> values = new ArrayList<>();
246+
values.add(List.of("coordinator", "parsedPlan", parsedPlanString));
247+
values.add(List.of("coordinator", "optimizedLogicalPlan", optimizedLogicalPlanString));
248+
values.add(List.of("coordinator", "optimizedPhysicalPlan", physicalPlanString));
249+
var blocks = BlockUtils.fromList(PlannerUtils.NON_BREAKING_BLOCK_FACTORY, values);
247250
physicalPlan = new LocalSourceExec(Source.EMPTY, fields, LocalSupplier.of(blocks));
248251
}
249252
// TODO: this could be snuck into the underlying listener

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/220_explain.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@ explainRow:
4747
query: 'EXPLAIN (row a = 1)'
4848

4949
- length: { columns: 3 }
50-
- length: { values: 1 }
51-
- match: {columns.0.name: "parsedPlan"}
50+
- match: {columns.0.name: "role"}
5251
- match: {columns.0.type: "keyword"}
53-
- match: {columns.1.name: "optimizedLogicalPlan"}
52+
- match: {columns.1.name: "type"}
5453
- match: {columns.1.type: "keyword"}
55-
- match: {columns.2.name: "optimizedPhysicalPlan"}
54+
- match: {columns.2.name: "plan"}
5655
- match: {columns.2.type: "keyword"}
56+
- length: { values: 3 }
57+
- match: { values.0.0: "coordinator" }
58+
- match: { values.0.1: "parsedPlan" }
59+
- match: { values.1.0: "coordinator" }
60+
- match: { values.1.1: "optimizedLogicalPlan" }
61+
- match: { values.2.0: "coordinator" }
62+
- match: { values.2.1: "optimizedPhysicalPlan" }
5763

5864

5965
---
@@ -66,13 +72,19 @@ explainQuery:
6672
query: 'EXPLAIN (from test | where color == "red" | eval b = 20)'
6773

6874
- length: { columns: 3 }
69-
- length: { values: 1 }
70-
- match: {columns.0.name: "parsedPlan"}
75+
- match: {columns.0.name: "role"}
7176
- match: {columns.0.type: "keyword"}
72-
- match: {columns.1.name: "optimizedLogicalPlan"}
77+
- match: {columns.1.name: "type"}
7378
- match: {columns.1.type: "keyword"}
74-
- match: {columns.2.name: "optimizedPhysicalPlan"}
79+
- match: {columns.2.name: "plan"}
7580
- match: {columns.2.type: "keyword"}
81+
- length: { values: 3 }
82+
- match: { values.0.0: "coordinator" }
83+
- match: { values.0.1: "parsedPlan" }
84+
- match: { values.1.0: "coordinator" }
85+
- match: { values.1.1: "optimizedLogicalPlan" }
86+
- match: { values.2.0: "coordinator" }
87+
- match: { values.2.1: "optimizedPhysicalPlan" }
7688

7789

7890
---

0 commit comments

Comments
 (0)