Skip to content

Commit 34e6cef

Browse files
committed
Test
1 parent b5829f9 commit 34e6cef

File tree

6 files changed

+133
-2
lines changed

6 files changed

+133
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apply plugin: 'elasticsearch.internal-es-plugin'
2+
apply plugin: 'elasticsearch.internal-java-rest-test'
3+
apply plugin: org.elasticsearch.gradle.internal.precommit.CheckstylePrecommitPlugin
4+
apply plugin: org.elasticsearch.gradle.internal.precommit.ForbiddenApisPrecommitPlugin
5+
apply plugin: org.elasticsearch.gradle.internal.precommit.ForbiddenPatternsPrecommitPlugin
6+
apply plugin: org.elasticsearch.gradle.internal.precommit.FilePermissionsPrecommitPlugin
7+
apply plugin: org.elasticsearch.gradle.internal.precommit.LoggerUsagePrecommitPlugin
8+
apply plugin: org.elasticsearch.gradle.internal.precommit.TestingConventionsPrecommitPlugin
9+
10+
11+
esplugin {
12+
name = 'extra-checkers'
13+
description = 'An example plugin disallowing CATEGORIZE'
14+
classname ='org.elasticsearch.xpack.esql.qa.extra.ExtraCheckersPlugin'
15+
extendedPlugins = ['x-pack-esql']
16+
}
17+
18+
dependencies {
19+
compileOnly project(':x-pack:plugin:esql')
20+
compileOnly project(':x-pack:plugin:esql-core')
21+
}
22+
23+
tasks.named('javaRestTest') {
24+
usesDefaultDistribution("to be triaged")
25+
maxParallelForks = 1
26+
jvmArgs('--add-opens=java.base/java.nio=ALL-UNNAMED')
27+
}
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.qa.extra;
9+
10+
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
11+
12+
import org.elasticsearch.client.Request;
13+
import org.elasticsearch.client.ResponseException;
14+
import org.elasticsearch.test.TestClustersThreadFilter;
15+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
16+
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
17+
import org.elasticsearch.test.rest.ESRestTestCase;
18+
import org.junit.ClassRule;
19+
20+
import java.io.IOException;
21+
22+
import static org.hamcrest.Matchers.equalTo;
23+
24+
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
25+
public class ExtraCheckersIT extends ESRestTestCase {
26+
@ClassRule
27+
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
28+
.distribution(DistributionType.DEFAULT)
29+
.setting("xpack.security.enabled", "false")
30+
.setting("xpack.license.self_generated.type", "trial")
31+
.shared(true)
32+
.plugin("extra-checkers")
33+
.build();
34+
35+
public void testIncludesCategorize() throws IOException {
36+
Request request = new Request("POST", "/_query");
37+
request.setJsonEntity("""
38+
{
39+
"query": "ROW message=\\"foo bar\\" | STATS COUNT(*) BY CATEGORIZE(message)"
40+
}""");
41+
request.addParameter("error_trace", "");
42+
Exception e = expectThrows(ResponseException.class, () -> client().performRequest(request));
43+
assertThat(e.getMessage(), equalTo("ADFSADF"));
44+
}
45+
46+
@Override
47+
protected String getTestRestCluster() {
48+
return cluster.getHttpAddresses();
49+
}
50+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.qa.extra;
9+
10+
import org.elasticsearch.xpack.esql.analysis.Verifier;
11+
import org.elasticsearch.xpack.esql.common.Failure;
12+
import org.elasticsearch.xpack.esql.common.Failures;
13+
import org.elasticsearch.xpack.esql.expression.function.grouping.Categorize;
14+
import org.elasticsearch.xpack.esql.plan.logical.Aggregate;
15+
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
16+
17+
import java.util.List;
18+
import java.util.function.BiConsumer;
19+
20+
public class DisallowCategorize implements Verifier.ExtraCheckers {
21+
@Override
22+
public List<BiConsumer<LogicalPlan, Failures>> extra() {
23+
return List.of(DisallowCategorize::disallowCategorize);
24+
}
25+
26+
private static void disallowCategorize(LogicalPlan plan, Failures failures) {
27+
if (plan instanceof Aggregate) {
28+
plan.forEachExpression(Categorize.class, cat -> failures.add(new Failure(cat, "CATEGORIZE is unsupported")));
29+
}
30+
}
31+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.qa.extra;
9+
10+
import org.elasticsearch.plugins.Plugin;
11+
import org.elasticsearch.xpack.esql.analysis.Verifier;
12+
13+
/**
14+
* Marker plugin to enable {@link Verifier.ExtraCheckers}.
15+
*/
16+
public class ExtraCheckersPlugin extends Plugin {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
# or more contributor license agreements. Licensed under the Elastic License
4+
# 2.0; you may not use this file except in compliance with the Elastic License
5+
# 2.0.
6+
#
7+
8+
org.elasticsearch.xpack.esql.qa.extra.DisallowCategorize

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/execution/PlanExecutor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public class PlanExecutor {
4949
private final Verifier verifier;
5050
private final PlanTelemetryManager planTelemetryManager;
5151
private final EsqlQueryLog queryLog;
52-
private final List<Verifier.ExtraCheckers> extraCheckers;
5352

5453
public PlanExecutor(
5554
IndexResolver indexResolver,
@@ -66,7 +65,6 @@ public PlanExecutor(
6665
this.verifier = new Verifier(extraCheckers, metrics, licenseState);
6766
this.planTelemetryManager = new PlanTelemetryManager(meterRegistry);
6867
this.queryLog = queryLog;
69-
this.extraCheckers = extraCheckers;
7068
}
7169

7270
public void esql(

0 commit comments

Comments
 (0)