-
Notifications
You must be signed in to change notification settings - Fork 25.6k
ESQL: Add extension point for extra plan checks #128840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
b5829f9
350d303
34e6cef
f6f56b4
0d26edd
89bf7c2
aebecdf
eab8e4b
109dad3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| apply plugin: 'elasticsearch.internal-es-plugin' | ||
| apply plugin: 'elasticsearch.internal-java-rest-test' | ||
| apply plugin: org.elasticsearch.gradle.internal.precommit.CheckstylePrecommitPlugin | ||
| apply plugin: org.elasticsearch.gradle.internal.precommit.ForbiddenApisPrecommitPlugin | ||
| apply plugin: org.elasticsearch.gradle.internal.precommit.ForbiddenPatternsPrecommitPlugin | ||
| apply plugin: org.elasticsearch.gradle.internal.precommit.FilePermissionsPrecommitPlugin | ||
| apply plugin: org.elasticsearch.gradle.internal.precommit.LoggerUsagePrecommitPlugin | ||
| apply plugin: org.elasticsearch.gradle.internal.precommit.TestingConventionsPrecommitPlugin | ||
|
|
||
|
|
||
| esplugin { | ||
| name = 'extra-checkers' | ||
| description = 'An example plugin disallowing CATEGORIZE' | ||
| classname ='org.elasticsearch.xpack.esql.qa.extra.ExtraCheckersPlugin' | ||
| extendedPlugins = ['x-pack-esql'] | ||
| } | ||
|
|
||
| dependencies { | ||
| compileOnly project(':x-pack:plugin:esql') | ||
| compileOnly project(':x-pack:plugin:esql-core') | ||
| clusterPlugins project(':x-pack:plugin:esql:qa:server:extra-checkers') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be unnecessary. The |
||
| } | ||
|
|
||
| tasks.named('javaRestTest') { | ||
| usesDefaultDistribution("to be triaged") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make a best effort to not use the default distribution here. We should avoid adding more tests that use this. |
||
| maxParallelForks = 1 | ||
| jvmArgs('--add-opens=java.base/java.nio=ALL-UNNAMED') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this required? |
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.esql.qa.extra; | ||
|
|
||
| import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; | ||
|
|
||
| import org.apache.http.util.EntityUtils; | ||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.Response; | ||
| import org.elasticsearch.client.ResponseException; | ||
| import org.elasticsearch.test.TestClustersThreadFilter; | ||
| import org.elasticsearch.test.cluster.ElasticsearchCluster; | ||
| import org.elasticsearch.test.cluster.local.distribution.DistributionType; | ||
| import org.elasticsearch.test.rest.ESRestTestCase; | ||
| import org.junit.ClassRule; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import static org.hamcrest.Matchers.containsString; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| @ThreadLeakFilters(filters = TestClustersThreadFilter.class) | ||
| public class ExtraCheckersIT extends ESRestTestCase { | ||
| @ClassRule | ||
| public static ElasticsearchCluster cluster = ElasticsearchCluster.local() | ||
| .distribution(DistributionType.DEFAULT) | ||
| .setting("xpack.security.enabled", "false") | ||
| .setting("xpack.license.self_generated.type", "trial") | ||
| .shared(true) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unnecessary. There's only one test in this project. |
||
| .plugin("extra-checkers") | ||
| .build(); | ||
|
|
||
| public void testWithCategorize() { | ||
| ResponseException e = expectThrows(ResponseException.class, () -> runEsql(""" | ||
| { | ||
| "query": "ROW message=\\"foo bar\\" | STATS COUNT(*) BY CATEGORIZE(message) | LIMIT 1" | ||
| }""")); | ||
| assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(400)); | ||
| assertThat(e.getMessage(), containsString("line 1:43: CATEGORIZE is unsupported")); | ||
| } | ||
|
|
||
| public void testWithoutCategorize() throws IOException { | ||
| String result = runEsql(""" | ||
| { | ||
| "query": "ROW message=\\"foo bar\\" | STATS COUNT(*) | LIMIT 1" | ||
| }"""); | ||
| assertThat(result, containsString(""" | ||
| "columns" : [ | ||
| { | ||
| "name" : "COUNT(*)", | ||
| "type" : "long" | ||
| } | ||
| ], | ||
| "values" : [ | ||
| [ | ||
| 1 | ||
| ] | ||
| ] | ||
| """)); | ||
| } | ||
|
|
||
| private String runEsql(String json) throws IOException { | ||
| Request request = new Request("POST", "/_query"); | ||
| request.setJsonEntity(json); | ||
| request.addParameter("error_trace", ""); | ||
| request.addParameter("pretty", ""); | ||
| Response response = client().performRequest(request); | ||
| return EntityUtils.toString(response.getEntity()); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getTestRestCluster() { | ||
| return cluster.getHttpAddresses(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.esql.qa.extra; | ||
|
|
||
| import org.elasticsearch.xpack.esql.analysis.Verifier; | ||
| import org.elasticsearch.xpack.esql.common.Failure; | ||
| import org.elasticsearch.xpack.esql.common.Failures; | ||
| import org.elasticsearch.xpack.esql.expression.function.grouping.Categorize; | ||
| import org.elasticsearch.xpack.esql.plan.logical.Aggregate; | ||
| import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; | ||
|
|
||
| import java.util.List; | ||
| import java.util.function.BiConsumer; | ||
|
|
||
| public class DisallowCategorize implements Verifier.ExtraCheckers { | ||
| @Override | ||
| public List<BiConsumer<LogicalPlan, Failures>> extra() { | ||
| return List.of(DisallowCategorize::disallowCategorize); | ||
| } | ||
|
|
||
| private static void disallowCategorize(LogicalPlan plan, Failures failures) { | ||
| if (plan instanceof Aggregate) { | ||
| plan.forEachExpression(Categorize.class, cat -> failures.add(new Failure(cat, "CATEGORIZE is unsupported"))); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.esql.qa.extra; | ||
|
|
||
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.xpack.esql.analysis.Verifier; | ||
|
|
||
| /** | ||
| * Marker plugin to enable {@link Verifier.ExtraCheckers}. | ||
| */ | ||
| public class ExtraCheckersPlugin extends Plugin {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this just because ES requires our plugin to include something that extends |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # | ||
| # Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| # or more contributor license agreements. Licensed under the Elastic License | ||
| # 2.0; you may not use this file except in compliance with the Elastic License | ||
| # 2.0. | ||
| # | ||
|
|
||
| org.elasticsearch.xpack.esql.qa.extra.DisallowCategorize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should actually use
elasticsearch.base-internal-es-pluginhere, since this is a "test" plugin and not intended to be published or included in Elasticsearch.