Skip to content

Commit 52a25c4

Browse files
committed
SQL: Support multi-index format as table identifier
Extend tableIdentifier to support multi-index format; not just * but also enumeration and exclusion Fix #33162
1 parent d063009 commit 52a25c4

File tree

5 files changed

+28
-54
lines changed

5 files changed

+28
-54
lines changed

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/analysis/index/IndexResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.client.Client;
2020
import org.elasticsearch.cluster.metadata.AliasMetaData;
2121
import org.elasticsearch.cluster.metadata.MappingMetaData;
22+
import org.elasticsearch.common.Strings;
2223
import org.elasticsearch.common.collect.ImmutableOpenMap;
2324
import org.elasticsearch.index.IndexNotFoundException;
2425
import org.elasticsearch.xpack.sql.type.EsField;
@@ -300,7 +301,7 @@ public void resolveAsSeparateMappings(String indexWildcard, String javaRegex, Ac
300301
private static GetIndexRequest createGetIndexRequest(String index) {
301302
return new GetIndexRequest()
302303
.local(true)
303-
.indices(index)
304+
.indices(Strings.commaDelimitedListToStringArray(index))
304305
.features(Feature.MAPPINGS)
305306
//lenient because we throw our own errors looking at the response e.g. if something was not resolved
306307
//also because this way security doesn't throw authorization exceptions but rather honours ignore_unavailable

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/execution/search/Querier.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.action.search.ShardSearchFailure;
1313
import org.elasticsearch.client.Client;
1414
import org.elasticsearch.common.Nullable;
15+
import org.elasticsearch.common.Strings;
1516
import org.elasticsearch.common.logging.Loggers;
1617
import org.elasticsearch.common.unit.TimeValue;
1718
import org.elasticsearch.common.util.CollectionUtils;
@@ -92,7 +93,7 @@ public void query(Schema schema, QueryContainer query, String index, ActionListe
9293
log.trace("About to execute query {} on {}", StringUtils.toString(sourceBuilder), index);
9394
}
9495

95-
SearchRequest search = prepareRequest(client, sourceBuilder, timeout, index);
96+
SearchRequest search = prepareRequest(client, sourceBuilder, timeout, Strings.commaDelimitedListToStringArray(index));
9697

9798
ActionListener<SearchResponse> l;
9899
if (query.isAggsOnly()) {

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/IdentifierBuilder.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,9 @@ public TableIdentifier visitTableIdentifier(TableIdentifierContext ctx) {
2121
ParseTree tree = ctx.name != null ? ctx.name : ctx.TABLE_IDENTIFIER();
2222
String index = tree.getText();
2323

24-
validateIndex(index, source);
2524
return new TableIdentifier(source, visitIdentifier(ctx.catalog), index);
2625
}
2726

28-
// see https://github.com/elastic/elasticsearch/issues/6736
29-
static void validateIndex(String index, Location source) {
30-
for (int i = 0; i < index.length(); i++) {
31-
char c = index.charAt(i);
32-
if (Character.isUpperCase(c)) {
33-
throw new ParsingException(source, "Invalid index name (needs to be lowercase) {}", index);
34-
}
35-
if (c == '\\' || c == '/' || c == '<' || c == '>' || c == '|' || c == ',' || c == ' ') {
36-
throw new ParsingException(source, "Invalid index name (illegal character {}) {}", c, index);
37-
}
38-
}
39-
}
40-
4127
@Override
4228
public String visitIdentifier(IdentifierContext ctx) {
4329
return ctx == null ? null : ctx.getText();

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/parser/IdentifierBuilderTests.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

x-pack/qa/sql/src/main/resources/command.csv-spec

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,27 @@ last_name | VARCHAR
162162
last_name.keyword | VARCHAR
163163
salary | INTEGER
164164
;
165+
166+
167+
describeIncludeExclude
168+
DESCRIBE "test_emp*,-test_alias*";
169+
170+
column:s | type:s
171+
birth_date | TIMESTAMP
172+
dep | STRUCT
173+
dep.dep_id | VARCHAR
174+
dep.dep_name | VARCHAR
175+
dep.dep_name.keyword | VARCHAR
176+
dep.from_date | TIMESTAMP
177+
dep.to_date | TIMESTAMP
178+
emp_no | INTEGER
179+
first_name | VARCHAR
180+
first_name.keyword | VARCHAR
181+
gender | VARCHAR
182+
hire_date | TIMESTAMP
183+
languages | TINYINT
184+
last_name | VARCHAR
185+
last_name.keyword | VARCHAR
186+
salary | INTEGER
187+
;
188+

0 commit comments

Comments
 (0)