-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Handle views in ResolveIndexAction #143561
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 all commits
f1f2d52
bc14932
d2f5158
a04d737
165abbf
97c6455
90b9135
211c085
e92056c
a2dc36a
2c08b88
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 |
|---|---|---|
|
|
@@ -731,19 +731,6 @@ static void resolveIndices( | |
| ); | ||
| } | ||
|
|
||
| // Shortcut for tests that don't need index mode filtering | ||
| static void resolveIndices( | ||
| String[] names, | ||
| IndicesOptions indicesOptions, | ||
| ProjectState projectState, | ||
| IndexNameExpressionResolver resolver, | ||
| List<ResolvedIndex> indices, | ||
| List<ResolvedAlias> aliases, | ||
| List<ResolvedDataStream> dataStreams | ||
| ) { | ||
| resolveIndices(names, indicesOptions, projectState, resolver, indices, aliases, dataStreams, Collections.emptySet()); | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the specified names and/or wildcard expressions to index abstractions. Returns results in the supplied lists. | ||
| * | ||
|
|
@@ -779,6 +766,7 @@ static void resolveIndices( | |
| if (names.length == 1 && (Metadata.ALL.equals(names[0]) || Regex.isMatchAllPattern(names[0]))) { | ||
| names = new String[] { "**" }; | ||
| } | ||
| assert indicesOptions.wildcardOptions().resolveViews() == false : "Views are not supported in ResolveIndexAction"; | ||
|
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. 👍 |
||
| Set<ResolvedExpression> resolvedIndexAbstractions = resolver.resolveExpressions( | ||
| projectState.metadata(), | ||
| indicesOptions, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -359,8 +359,6 @@ public IndexAbstraction resolveWriteIndexAbstraction(ProjectMetadata project, Do | |
| + " indices without one being designated as a write index" | ||
| ); | ||
| } | ||
| } else if (ia.getType() == Type.VIEW) { | ||
| throw new IllegalArgumentException("an ESQL view [" + ia.getName() + "] may not be the target of an index operation"); | ||
| } | ||
| SystemResourceAccess.checkSystemIndexAccess(context, threadContext, ia.getWriteIndex()); | ||
| return ia; | ||
|
|
@@ -1524,6 +1522,13 @@ private static boolean ensureAliasOrIndexExists(Context context, String name, In | |
| throw infe; | ||
| } | ||
| } | ||
| if (indexAbstraction.getType() == Type.VIEW && context.getOptions().wildcardOptions().resolveViews() == false) { | ||
|
Contributor
Author
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 skips view when targeted directly by name. Eventually (but before it is released) we should replace
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. Something to note is that
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. Opened this PR to move them: #143741 |
||
| if (ignoreUnavailable) { | ||
| return false; | ||
| } else { | ||
| throw notFoundException(name); | ||
| } | ||
| } | ||
| if (context.options.allowSelectors()) { | ||
| // Ensure that the selectors are present and that they are compatible with the abstractions they are used with | ||
| assert selector != null : "Earlier logic should have parsed selectors or added the default selectors already"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * 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.action; | ||
|
|
||
| import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; | ||
| import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction; | ||
| import org.elasticsearch.cluster.metadata.View; | ||
| import org.elasticsearch.index.IndexNotFoundException; | ||
| import org.elasticsearch.xpack.esql.view.PutViewAction; | ||
| import org.hamcrest.Matcher; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
| import static org.hamcrest.Matchers.containsInAnyOrder; | ||
| import static org.hamcrest.Matchers.containsString; | ||
| import static org.hamcrest.Matchers.emptyIterable; | ||
|
|
||
| public class ResolveIndexActionIT extends AbstractEsqlIntegTestCase { | ||
|
|
||
| public void testResolveIndex() { | ||
| assertAcked(client().admin().indices().create(new CreateIndexRequest("my-index-1"))); | ||
| assertAcked(client().admin().indices().create(new CreateIndexRequest("other-index-2"))); | ||
|
|
||
| assertAcked( | ||
| client().execute( | ||
| PutViewAction.INSTANCE, | ||
| new PutViewAction.Request(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT, new View("my-view-1", "ROW r=1")) | ||
| ) | ||
| ); | ||
|
|
||
| verifyResolvedIndices( | ||
| new ResolveIndexAction.Request(new String[] { "my-index-1" }), | ||
| containsInAnyOrder("my-index-1"), | ||
| emptyIterable(), | ||
| emptyIterable() | ||
| ); | ||
| verifyResolvedIndices( | ||
| new ResolveIndexAction.Request(new String[] { "my-index-*" }), | ||
| containsInAnyOrder("my-index-1"), | ||
| emptyIterable(), | ||
| emptyIterable() | ||
| ); | ||
|
|
||
| // matched view is not returned, but it does not fail request | ||
|
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. Should this comment move a few lines down and a new comment be here, since we are indeed failing the request when an explicit view name is used. |
||
| expectThrows( | ||
| IndexNotFoundException.class, | ||
| containsString("no such index [my-view-1]"), | ||
| () -> resolveIndices(new ResolveIndexAction.Request(new String[] { "my-view-1" })) | ||
| ); | ||
| verifyResolvedIndices( | ||
| new ResolveIndexAction.Request(new String[] { "my-*" }), | ||
| containsInAnyOrder("my-index-1"), | ||
| emptyIterable(), | ||
| emptyIterable() | ||
| ); | ||
| } | ||
|
|
||
| private ResolveIndexAction.Response resolveIndices(ResolveIndexAction.Request request) { | ||
| return client().admin().indices().resolveIndex(request).actionGet(); | ||
| } | ||
|
|
||
| private void verifyResolvedIndices( | ||
| ResolveIndexAction.Request request, | ||
| Matcher<Iterable<? extends String>> indicesMatcher, | ||
| Matcher<Iterable<? extends String>> aliasesMatcher, | ||
| Matcher<Iterable<? extends String>> dataStreamsMatcher | ||
| ) { | ||
| var response = resolveIndices(request); | ||
| assertThat(toStringList(response.getIndices()), indicesMatcher); | ||
| assertThat(toStringList(response.getAliases()), aliasesMatcher); | ||
| assertThat(toStringList(response.getDataStreams()), dataStreamsMatcher); | ||
| } | ||
|
|
||
| private static List<String> toStringList(List<? extends ResolveIndexAction.ResolvedIndexAbstraction> list) { | ||
| return list.stream().map(ResolveIndexAction.ResolvedIndexAbstraction::getName).toList(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -272,14 +272,13 @@ setup: | |
| query: 'FROM test | WHERE animal == "dog"' | ||
|
|
||
| - do: | ||
| catch: /no such index \[myview\]/ | ||
| search: | ||
| index: myview | ||
| body: { query: { match_all: {} } } | ||
|
|
||
| - length: { hits.hits: 0 } | ||
|
Contributor
Author
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 change also causes a
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. I think the change in behaviour makes sense. |
||
|
|
||
| - do: | ||
| catch: /an ESQL view \[myview\] may not be the target of an index operation/ | ||
| catch: /no such index \[myview\]/ | ||
|
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. I think the change in behaviour makes sense. But I also note that we should get the old error message if we write to write to a view, and there is no test for that. We could add such a test in a separate PR, or here. |
||
| index: | ||
| index: myview | ||
| id: "1" | ||
|
|
||
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.
Inlined method used only in test. We should not have test only code in production