-
Notifications
You must be signed in to change notification settings - Fork 25.6k
SQL: add support for index aliases for SYS COLUMNS command #53525
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 8 commits
947e501
dabcccf
3aa01f3
26bf119
93d8162
80f0b63
d34271a
bf8df94
9ed8fa2
cd6c420
079be6b
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |||||
| package org.elasticsearch.xpack.ql.index; | ||||||
|
|
||||||
| import com.carrotsearch.hppc.cursors.ObjectCursor; | ||||||
| import com.carrotsearch.hppc.cursors.ObjectObjectCursor; | ||||||
|
|
||||||
| import org.elasticsearch.ElasticsearchSecurityException; | ||||||
| import org.elasticsearch.action.ActionListener; | ||||||
|
|
@@ -16,12 +17,14 @@ | |||||
| import org.elasticsearch.action.admin.indices.get.GetIndexResponse; | ||||||
| import org.elasticsearch.action.fieldcaps.FieldCapabilities; | ||||||
| import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest; | ||||||
| import org.elasticsearch.action.fieldcaps.FieldCapabilitiesResponse; | ||||||
| import org.elasticsearch.action.support.IndicesOptions; | ||||||
| import org.elasticsearch.action.support.IndicesOptions.Option; | ||||||
| import org.elasticsearch.action.support.IndicesOptions.WildcardStates; | ||||||
| import org.elasticsearch.client.Client; | ||||||
| import org.elasticsearch.cluster.metadata.AliasMetaData; | ||||||
| import org.elasticsearch.common.Strings; | ||||||
| import org.elasticsearch.common.collect.ImmutableOpenMap; | ||||||
| import org.elasticsearch.index.IndexNotFoundException; | ||||||
| import org.elasticsearch.index.IndexSettings; | ||||||
| import org.elasticsearch.xpack.ql.QlIllegalArgumentException; | ||||||
|
|
@@ -42,9 +45,11 @@ | |||||
| import java.util.Collections; | ||||||
| import java.util.Comparator; | ||||||
| import java.util.EnumSet; | ||||||
| import java.util.HashMap; | ||||||
| import java.util.HashSet; | ||||||
| import java.util.Iterator; | ||||||
| import java.util.LinkedHashMap; | ||||||
| import java.util.LinkedHashSet; | ||||||
| import java.util.List; | ||||||
| import java.util.Map; | ||||||
| import java.util.Map.Entry; | ||||||
|
|
@@ -164,7 +169,6 @@ public boolean equals(Object obj) { | |||||
| private final String clusterName; | ||||||
| private final DataTypeRegistry typeRegistry; | ||||||
|
|
||||||
|
|
||||||
| public IndexResolver(Client client, String clusterName, DataTypeRegistry typeRegistry) { | ||||||
| this.client = client; | ||||||
| this.clusterName = clusterName; | ||||||
|
|
@@ -296,7 +300,7 @@ public static IndexResolution mergedMappings(DataTypeRegistry typeRegistry, Stri | |||||
| } | ||||||
|
|
||||||
| // merge all indices onto the same one | ||||||
| List<EsIndex> indices = buildIndices(typeRegistry, indexNames, null, fieldCaps, i -> indexPattern, (n, types) -> { | ||||||
| List<EsIndex> indices = buildIndices(typeRegistry, indexNames, null, fieldCaps, null, i -> indexPattern, (n, types) -> { | ||||||
| StringBuilder errorMessage = new StringBuilder(); | ||||||
|
|
||||||
| boolean hasUnmapped = types.containsKey(UNMAPPED); | ||||||
|
|
@@ -473,17 +477,32 @@ private static FieldCapabilitiesRequest createFieldCapsRequest(String index, boo | |||||
| public void resolveAsSeparateMappings(String indexWildcard, String javaRegex, boolean includeFrozen, | ||||||
| ActionListener<List<EsIndex>> listener) { | ||||||
| FieldCapabilitiesRequest fieldRequest = createFieldCapsRequest(indexWildcard, includeFrozen); | ||||||
| client.fieldCaps(fieldRequest, | ||||||
| ActionListener.wrap( | ||||||
| response -> listener.onResponse( | ||||||
| separateMappings(typeRegistry, indexWildcard, javaRegex, response.getIndices(), response.get())), | ||||||
| listener::onFailure)); | ||||||
| client.fieldCaps(fieldRequest, wrap(response -> { | ||||||
| client.admin().indices().getAliases(createGetAliasesRequest(response, includeFrozen), wrap(aliases -> | ||||||
| listener.onResponse(separateMappings(typeRegistry, javaRegex, response.getIndices(), response.get(), aliases.getAliases())), | ||||||
| ex -> { | ||||||
| if (ex instanceof IndexNotFoundException || ex instanceof ElasticsearchSecurityException) { | ||||||
| listener.onResponse(separateMappings(typeRegistry, javaRegex, response.getIndices(), response.get(), null)); | ||||||
| } else { | ||||||
| listener.onFailure(ex); | ||||||
| } | ||||||
| })); | ||||||
| }, | ||||||
| listener::onFailure)); | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| public static List<EsIndex> separateMappings(DataTypeRegistry typeRegistry, String indexPattern, String javaRegex, String[] indexNames, | ||||||
| Map<String, Map<String, FieldCapabilities>> fieldCaps) { | ||||||
| return buildIndices(typeRegistry, indexNames, javaRegex, fieldCaps, Function.identity(), (s, cap) -> null); | ||||||
| private GetAliasesRequest createGetAliasesRequest(FieldCapabilitiesResponse response, boolean includeFrozen) { | ||||||
| return new GetAliasesRequest() | ||||||
| .local(true) | ||||||
| .aliases("*") | ||||||
| .indices(response.getIndices()) | ||||||
| .indicesOptions(includeFrozen ? FIELD_CAPS_FROZEN_INDICES_OPTIONS : FIELD_CAPS_INDICES_OPTIONS); | ||||||
| } | ||||||
|
|
||||||
| public static List<EsIndex> separateMappings(DataTypeRegistry typeRegistry, String javaRegex, String[] indexNames, | ||||||
| Map<String, Map<String, FieldCapabilities>> fieldCaps, ImmutableOpenMap<String, List<AliasMetaData>> aliases) { | ||||||
| return buildIndices(typeRegistry, indexNames, javaRegex, fieldCaps, aliases, Function.identity(), (s, cap) -> null); | ||||||
| } | ||||||
|
|
||||||
| private static class Fields { | ||||||
|
|
@@ -496,16 +515,27 @@ private static class Fields { | |||||
| * each field. | ||||||
| */ | ||||||
| private static List<EsIndex> buildIndices(DataTypeRegistry typeRegistry, String[] indexNames, String javaRegex, | ||||||
| Map<String, Map<String, FieldCapabilities>> fieldCaps, | ||||||
| Map<String, Map<String, FieldCapabilities>> fieldCaps, ImmutableOpenMap<String, List<AliasMetaData>> aliases, | ||||||
astefan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| Function<String, String> indexNameProcessor, | ||||||
| BiFunction<String, Map<String, FieldCapabilities>, InvalidMappedField> validityVerifier) { | ||||||
|
|
||||||
| if (indexNames == null || indexNames.length == 0) { | ||||||
| if ((indexNames == null || indexNames.length == 0) && (aliases == null || aliases.size() == 0)) { | ||||||
|
||||||
| return emptyList(); | ||||||
| } | ||||||
|
|
||||||
| final List<String> resolvedIndices = asList(indexNames); | ||||||
| Map<String, Fields> indices = new LinkedHashMap<>(resolvedIndices.size()); | ||||||
| Set<String> resolvedAliases = new HashSet<>(); | ||||||
| if (aliases != null) { | ||||||
| Iterator<ObjectObjectCursor<String, List<AliasMetaData>>> iterator = aliases.iterator(); | ||||||
| while (iterator.hasNext()) { | ||||||
| for(AliasMetaData alias : iterator.next().value) { | ||||||
|
||||||
| for(AliasMetaData alias : iterator.next().value) { | |
| for (AliasMetaData alias : iterator.next().value) { |
Outdated
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.
nit: s/accross/across.
Outdated
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.
Can it be simply <>?
| aliasToIndices.putIfAbsent(aliasName, new HashSet<String>()); | |
| aliasToIndices.putIfAbsent(aliasName, new HashSet<>()); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.sql.qa.single_node; | ||
|
|
||
| import org.elasticsearch.xpack.sql.qa.jdbc.SysColumnsTestCase; | ||
|
|
||
| public class SysColumnsIT extends SysColumnsTestCase { | ||
|
|
||
| } |
Uh oh!
There was an error while loading. Please reload this page.