Skip to content

Commit 5c1e3e2

Browse files
authored
ESQL: Replace [ccq.mode] in favor of a policy prefix (#105224)
For consistency, replace [ccq.mode:<type>] with _<resolution>:policyName `ENRICH [ccq.mode=any] policyName` becomes `ENRICH _any:policyName`
1 parent ac36aa7 commit 5c1e3e2

File tree

17 files changed

+1282
-1411
lines changed

17 files changed

+1282
-1411
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ public static String randomEnrichCommand(String name, Enrich.Mode mode, String m
221221
}
222222
withFields = " WITH " + String.join(",", fields);
223223
}
224-
String enrich = "ENRICH";
224+
String enrich = "ENRICH ";
225225
if (mode != Enrich.Mode.ANY || randomBoolean()) {
226-
enrich += " [ccq.mode: " + mode + "] ";
226+
enrich += " _" + mode + ":";
227227
}
228-
enrich += " " + name;
228+
enrich += name;
229229
enrich += onField;
230230
enrich += withFields;
231231
List<String> all = new ArrayList<>(before);

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClustersEnrichIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ public void testTopNThenEnrichRemote() {
414414
| %s
415415
""", enrichHosts(Enrich.Mode.REMOTE));
416416
var error = expectThrows(VerificationException.class, () -> runQuery(query).close());
417-
assertThat(error.getMessage(), containsString("enrich with [ccq.mode:remote] can't be executed after LIMIT"));
417+
assertThat(error.getMessage(), containsString("ENRICH with remote policy can't be executed after LIMIT"));
418418
}
419419

420420
public void testLimitThenEnrichRemote() {
@@ -425,7 +425,7 @@ public void testLimitThenEnrichRemote() {
425425
| %s
426426
""", enrichHosts(Enrich.Mode.REMOTE));
427427
var error = expectThrows(VerificationException.class, () -> runQuery(query).close());
428-
assertThat(error.getMessage(), containsString("enrich with [ccq.mode:remote] can't be executed after LIMIT"));
428+
assertThat(error.getMessage(), containsString("ENRICH with remote policy can't be executed after LIMIT"));
429429
}
430430

431431
public void testAggThenEnrichRemote() {
@@ -438,7 +438,7 @@ public void testAggThenEnrichRemote() {
438438
| sort vendor
439439
""", enrichHosts(Enrich.Mode.ANY), enrichVendors(Enrich.Mode.REMOTE));
440440
var error = expectThrows(VerificationException.class, () -> runQuery(query).close());
441-
assertThat(error.getMessage(), containsString("enrich with [ccq.mode:remote] can't be executed after STATS"));
441+
assertThat(error.getMessage(), containsString("ENRICH with remote policy can't be executed after STATS"));
442442
}
443443

444444
public void testEnrichCoordinatorThenEnrichRemote() {
@@ -452,7 +452,7 @@ public void testEnrichCoordinatorThenEnrichRemote() {
452452
var error = expectThrows(VerificationException.class, () -> runQuery(query).close());
453453
assertThat(
454454
error.getMessage(),
455-
containsString("enrich with [ccq.mode:remote] can't be executed after another enrich with [ccq.mode:coordinator]")
455+
containsString("ENRICH with remote policy can't be executed after another ENRICH with coordinator policy")
456456
);
457457
}
458458

x-pack/plugin/esql/src/main/antlr/EsqlBaseLexer.g4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ fragment ENRICH_POLICY_NAME_BODY
291291
;
292292
293293
ENRICH_POLICY_NAME
294-
: (LETTER | DIGIT) ENRICH_POLICY_NAME_BODY*
294+
// allow prefix for the policy to specify its resolution
295+
: (ENRICH_POLICY_NAME_BODY+ COLON)? ENRICH_POLICY_NAME_BODY+
295296
;
296297
297298
ENRICH_QUOTED_IDENTIFIER

x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.g4

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,9 @@ showCommand
249249
;
250250

251251
enrichCommand
252-
: ENRICH setting* policyName=ENRICH_POLICY_NAME (ON matchField=qualifiedNamePattern)? (WITH enrichWithClause (COMMA enrichWithClause)*)?
252+
: ENRICH policyName=ENRICH_POLICY_NAME (ON matchField=qualifiedNamePattern)? (WITH enrichWithClause (COMMA enrichWithClause)*)?
253253
;
254254

255255
enrichWithClause
256256
: (newName=qualifiedNamePattern ASSIGN)? enrichField=qualifiedNamePattern
257257
;
258-
259-
setting
260-
: OPENING_BRACKET name=SETTING COLON value=SETTING CLOSING_BRACKET
261-
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Verifier.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ private static Failure validateUnsignedLongNegation(Neg neg) {
387387
* TODO:
388388
* For Limit and TopN, we can insert the same node after the remote enrich (also needs to move projections around)
389389
* to eliminate this limitation. Otherwise, we force users to write queries that might not perform well.
390-
* For example, `FROM test | ORDER @timestamp | LIMIT 10 | ENRICH[ccq.mode:remote]` doesn't work.
391-
* In that case, users have to write it as `FROM test | ENRICH[ccq.mode:remote] | ORDER @timestamp | LIMIT 10`,
390+
* For example, `FROM test | ORDER @timestamp | LIMIT 10 | ENRICH _remote:` doesn't work.
391+
* In that case, users have to write it as `FROM test | ENRICH _remote: | ORDER @timestamp | LIMIT 10`,
392392
* which is equivalent to bringing all data to the coordinating cluster.
393393
* We might consider implementing the actual remote enrich on the coordinating cluster, however, this requires
394394
* retaining the originating cluster and restructing pages for routing, which might be complicated.
@@ -409,15 +409,13 @@ private static void checkRemoteEnrich(LogicalPlan plan, Set<Failure> failures) {
409409
}
410410
if (u instanceof Enrich enrich && enrich.mode() == Enrich.Mode.REMOTE) {
411411
if (limit[0]) {
412-
failures.add(fail(enrich, "enrich with [ccq.mode:remote] can't be executed after LIMIT"));
412+
failures.add(fail(enrich, "ENRICH with remote policy can't be executed after LIMIT"));
413413
}
414414
if (agg[0]) {
415-
failures.add(fail(enrich, "enrich with [ccq.mode:remote] can't be executed after STATS"));
415+
failures.add(fail(enrich, "ENRICH with remote policy can't be executed after STATS"));
416416
}
417417
if (enrichCoord[0]) {
418-
failures.add(
419-
fail(enrich, "enrich with [ccq.mode:remote] can't be executed after another enrich with [ccq.mode:coordinator]")
420-
);
418+
failures.add(fail(enrich, "ENRICH with remote policy can't be executed after another ENRICH with coordinator policy"));
421419
}
422420
}
423421
});

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseLexer.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)