Skip to content

Commit 4b3acd4

Browse files
authored
ESQL: revive inlinestats (#122257)
1 parent 65f6b44 commit 4b3acd4

File tree

6 files changed

+44
-28
lines changed

6 files changed

+44
-28
lines changed

docs/changelog/122257.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122257
2+
summary: Revive inlinestats
3+
area: ES|QL
4+
type: bug
5+
issues: []

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import static org.elasticsearch.xpack.esql.EsqlTestUtils.classpathResources;
4949
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.INLINESTATS;
5050
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.INLINESTATS_V2;
51+
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.INLINESTATS_V3;
5152
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.JOIN_LOOKUP_V12;
5253
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.JOIN_PLANNING_V1;
5354
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.METADATA_FIELDS_REMOTE_TEST;
@@ -124,6 +125,7 @@ protected void shouldSkipTest(String testName) throws IOException {
124125
assumeFalse("INLINESTATS not yet supported in CCS", testCase.requiredCapabilities.contains(INLINESTATS.capabilityName()));
125126
assumeFalse("INLINESTATS not yet supported in CCS", testCase.requiredCapabilities.contains(INLINESTATS_V2.capabilityName()));
126127
assumeFalse("INLINESTATS not yet supported in CCS", testCase.requiredCapabilities.contains(JOIN_PLANNING_V1.capabilityName()));
128+
assumeFalse("INLINESTATS not yet supported in CCS", testCase.requiredCapabilities.contains(INLINESTATS_V3.capabilityName()));
127129
assumeFalse("LOOKUP JOIN not yet supported in CCS", testCase.requiredCapabilities.contains(JOIN_LOOKUP_V12.capabilityName()));
128130
}
129131

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// TODO: re-enable the commented tests once the Join functionality stabilizes
33
//
44

5-
maxOfInt-Ignore
6-
required_capability: join_planning_v1
5+
maxOfInt
6+
required_capability: inlinestats_v3
77
// tag::max-languages[]
88
FROM employees
99
| KEEP emp_no, languages
@@ -25,7 +25,7 @@ emp_no:integer | languages:integer | max_lang:integer
2525
;
2626

2727
maxOfIntByKeyword
28-
required_capability: join_planning_v1
28+
required_capability: inlinestats_v3
2929

3030
FROM employees
3131
| KEEP emp_no, languages, gender
@@ -43,7 +43,7 @@ emp_no:integer | languages:integer | gender:keyword | max_lang:integer
4343
;
4444

4545
maxOfLongByKeyword
46-
required_capability: join_planning_v1
46+
required_capability: inlinestats_v3
4747

4848
FROM employees
4949
| KEEP emp_no, avg_worked_seconds, gender
@@ -57,8 +57,8 @@ emp_no:integer | avg_worked_seconds:long | gender:keyword | max_avg_worked_secon
5757
10030 | 394597613 | M | 394597613
5858
;
5959

60-
maxOfLong-Ignore
61-
required_capability: join_planning_v1
60+
maxOfLong
61+
required_capability: inlinestats_v3
6262

6363
FROM employees
6464
| KEEP emp_no, avg_worked_seconds, gender
@@ -71,7 +71,7 @@ emp_no:integer | avg_worked_seconds:long | gender:keyword | max_avg_worked_secon
7171
;
7272

7373
maxOfLongByCalculatedKeyword
74-
required_capability: join_planning_v1
74+
required_capability: inlinestats_v3
7575

7676
// tag::longest-tenured-by-first[]
7777
FROM employees
@@ -94,7 +94,7 @@ emp_no:integer | avg_worked_seconds:long | last_name:keyword | SUBSTRING(last_na
9494
;
9595

9696
maxOfLongByCalculatedNamedKeyword
97-
required_capability: join_planning_v1
97+
required_capability: inlinestats_v3
9898

9999
FROM employees
100100
| KEEP emp_no, avg_worked_seconds, last_name
@@ -112,7 +112,7 @@ emp_no:integer | avg_worked_seconds:long | last_name:keyword | l:keyword | max_a
112112
10087 | 305782871 | Eugenio | E | 305782871
113113
;
114114

115-
maxOfLongByCalculatedDroppedKeyword
115+
maxOfLongByCalculatedDroppedKeyword-Ignore
116116
required_capability: join_planning_v1
117117

118118
FROM employees
@@ -132,7 +132,7 @@ emp_no:integer | avg_worked_seconds:long | last_name:keyword | max_avg_worked_se
132132
;
133133

134134
maxOfLongByEvaledKeyword
135-
required_capability: join_planning_v1
135+
required_capability: inlinestats_v3
136136

137137
FROM employees
138138
| EVAL l = SUBSTRING(last_name, 0, 1)
@@ -152,7 +152,7 @@ emp_no:integer | avg_worked_seconds:long | l:keyword | max_avg_worked_seconds:lo
152152
;
153153

154154
maxOfLongByInt
155-
required_capability: join_planning_v1
155+
required_capability: inlinestats_v3
156156

157157
FROM employees
158158
| KEEP emp_no, avg_worked_seconds, languages
@@ -170,7 +170,7 @@ emp_no:integer | avg_worked_seconds:long | languages:integer | max_avg_worked_se
170170
;
171171

172172
maxOfLongByIntDouble
173-
required_capability: join_planning_v1
173+
required_capability: inlinestats_v3
174174

175175
FROM employees
176176
| KEEP emp_no, avg_worked_seconds, languages, height
@@ -205,7 +205,7 @@ emp_no:integer | languages:integer | avg_worked_seconds:long | gender:keyword |
205205
10007 | 4 | 393084805 | F | 2.863684210555556E8 | 5
206206
;
207207

208-
byMultivaluedSimple
208+
byMultivaluedSimple-Ignore
209209
required_capability: join_planning_v1
210210

211211
// tag::mv-group[]
@@ -223,7 +223,7 @@ abbrev:keyword | type:keyword | scalerank:integer | min_scalerank:integer
223223
// end::mv-group-result[]
224224
;
225225

226-
byMultivaluedMvExpand
226+
byMultivaluedMvExpand-Ignore
227227
required_capability: join_planning_v1
228228

229229
// tag::mv-expand[]
@@ -243,7 +243,7 @@ abbrev:keyword | type:keyword | scalerank:integer | min_scalerank:integer
243243
// end::mv-expand-result[]
244244
;
245245

246-
byMvExpand
246+
byMvExpand-Ignore
247247
required_capability: join_planning_v1
248248

249249
// tag::extreme-airports[]
@@ -307,7 +307,7 @@ count:long | country:keyword | avg:double
307307
17 | United Kingdom | 4.455
308308
;
309309

310-
afterWhere
310+
afterWhere-Ignore
311311
required_capability: join_planning_v1
312312

313313
FROM airports
@@ -366,8 +366,8 @@ abbrev:keyword | city:keyword | region:text | "COUNT(*)":long
366366
FUK | Fukuoka | 中央区 | 2
367367
;
368368

369-
beforeStats-Ignore
370-
required_capability: join_planning_v1
369+
beforeStats
370+
required_capability: inlinestats_v3
371371

372372
FROM airports
373373
| EVAL lat = ST_Y(location)
@@ -379,7 +379,7 @@ northern:long | southern:long
379379
520 | 371
380380
;
381381

382-
beforeKeepSort
382+
beforeKeepSort-Ignore
383383
required_capability: join_planning_v1
384384

385385
FROM employees
@@ -394,7 +394,7 @@ emp_no:integer | languages:integer | max_salary:integer
394394
10003 | 4 | 74572
395395
;
396396

397-
beforeKeepWhere
397+
beforeKeepWhere-Ignore
398398
required_capability: join_planning_v1
399399

400400
FROM employees
@@ -537,8 +537,8 @@ emp_no:integer | one:integer
537537
10005 | 1
538538
;
539539

540-
percentile-Ignore
541-
required_capability: join_planning_v1
540+
percentile
541+
required_capability: inlinestats_v3
542542

543543
FROM employees
544544
| KEEP emp_no, salary

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,13 @@ public enum Cap {
808808
* and https://github.com/elastic/elasticsearch/issues/120803
809809
* Support for queries that have multiple SORTs that cannot become TopN
810810
*/
811-
REMOVE_REDUNDANT_SORT;
811+
REMOVE_REDUNDANT_SORT,
812+
813+
/**
814+
* Fixes a series of issues with inlinestats which had an incomplete implementation after lookup and inlinestats
815+
* were refactored.
816+
*/
817+
INLINESTATS_V3;
812818

813819
private final boolean enabled;
814820

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
import org.elasticsearch.xpack.esql.core.expression.Literal;
1717
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1818
import org.elasticsearch.xpack.esql.core.tree.Source;
19-
import org.elasticsearch.xpack.esql.core.util.CollectionUtils;
2019
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
20+
import org.elasticsearch.xpack.esql.plan.logical.Eval;
2121
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
22-
import org.elasticsearch.xpack.esql.plan.logical.Project;
2322
import org.elasticsearch.xpack.esql.plan.logical.UnaryPlan;
2423
import org.elasticsearch.xpack.esql.plan.logical.local.LocalRelation;
2524

@@ -71,10 +70,9 @@ public static LogicalPlan inlineData(InlineJoin target, LocalRelation data) {
7170
List<Alias> aliases = new ArrayList<>(schema.size());
7271
for (int i = 0; i < schema.size(); i++) {
7372
Attribute attr = schema.get(i);
74-
aliases.add(new Alias(attr.source(), attr.name(), Literal.of(attr, BlockUtils.toJavaObject(blocks[i], 0))));
73+
aliases.add(new Alias(attr.source(), attr.name(), Literal.of(attr, BlockUtils.toJavaObject(blocks[i], 0)), attr.id()));
7574
}
76-
LogicalPlan left = target.left();
77-
return new Project(target.source(), left, CollectionUtils.combine(left.output(), aliases));
75+
return new Eval(target.source(), target.left(), aliases);
7876
} else {
7977
return target.replaceRight(data);
8078
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.xpack.esql.plan.logical.OrderBy;
2323
import org.elasticsearch.xpack.esql.plan.logical.TopN;
2424
import org.elasticsearch.xpack.esql.plan.logical.UnaryPlan;
25+
import org.elasticsearch.xpack.esql.plan.logical.join.InlineJoin;
2526
import org.elasticsearch.xpack.esql.plan.logical.join.Join;
2627
import org.elasticsearch.xpack.esql.plan.logical.join.JoinConfig;
2728
import org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes;
@@ -178,6 +179,10 @@ private PhysicalPlan mapBinary(BinaryPlan bp) {
178179
throw new EsqlIllegalArgumentException("unsupported join type [" + config.type() + "]");
179180
}
180181

182+
if (join instanceof InlineJoin) {
183+
return new FragmentExec(bp);
184+
}
185+
181186
PhysicalPlan left = map(bp.left());
182187

183188
// only broadcast joins supported for now - hence push down as a streaming operator

0 commit comments

Comments
 (0)