Skip to content

Commit

Permalink
SQL: Support multi-index format as table identifier (#33278)
Browse files Browse the repository at this point in the history
Extend tableIdentifier to support multi-index format; not just * but
also enumeration and exclusion

Fix #33162

(cherry picked from commit 73eb4cb)
  • Loading branch information
costin committed Aug 31, 2018
1 parent dfba216 commit 6e1354c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.xpack.sql.type.EsField;
Expand Down Expand Up @@ -300,7 +301,7 @@ public void resolveAsSeparateMappings(String indexWildcard, String javaRegex, Ac
private static GetIndexRequest createGetIndexRequest(String index) {
return new GetIndexRequest()
.local(true)
.indices(index)
.indices(Strings.commaDelimitedListToStringArray(index))
.features(Feature.MAPPINGS)
//lenient because we throw our own errors looking at the response e.g. if something was not resolved
//also because this way security doesn't throw authorization exceptions but rather honours ignore_unavailable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.CollectionUtils;
Expand Down Expand Up @@ -92,7 +93,7 @@ public void query(Schema schema, QueryContainer query, String index, ActionListe
log.trace("About to execute query {} on {}", StringUtils.toString(sourceBuilder), index);
}

SearchRequest search = prepareRequest(client, sourceBuilder, timeout, index);
SearchRequest search = prepareRequest(client, sourceBuilder, timeout, Strings.commaDelimitedListToStringArray(index));

ActionListener<SearchResponse> l;
if (query.isAggsOnly()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,9 @@ public TableIdentifier visitTableIdentifier(TableIdentifierContext ctx) {
ParseTree tree = ctx.name != null ? ctx.name : ctx.TABLE_IDENTIFIER();
String index = tree.getText();

validateIndex(index, source);
return new TableIdentifier(source, visitIdentifier(ctx.catalog), index);
}

// see https://github.com/elastic/elasticsearch/issues/6736
static void validateIndex(String index, Location source) {
for (int i = 0; i < index.length(); i++) {
char c = index.charAt(i);
if (Character.isUpperCase(c)) {
throw new ParsingException(source, "Invalid index name (needs to be lowercase) {}", index);
}
if (c == '\\' || c == '/' || c == '<' || c == '>' || c == '|' || c == ',' || c == ' ') {
throw new ParsingException(source, "Invalid index name (illegal character {}) {}", c, index);
}
}
}

@Override
public String visitIdentifier(IdentifierContext ctx) {
return ctx == null ? null : ctx.getText();
Expand Down

This file was deleted.

24 changes: 24 additions & 0 deletions x-pack/qa/sql/src/main/resources/command.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,27 @@ last_name | VARCHAR
last_name.keyword | VARCHAR
salary | INTEGER
;


describeIncludeExclude
DESCRIBE "test_emp*,-test_alias*";

column:s | type:s
birth_date | TIMESTAMP
dep | STRUCT
dep.dep_id | VARCHAR
dep.dep_name | VARCHAR
dep.dep_name.keyword | VARCHAR
dep.from_date | TIMESTAMP
dep.to_date | TIMESTAMP
emp_no | INTEGER
first_name | VARCHAR
first_name.keyword | VARCHAR
gender | VARCHAR
hire_date | TIMESTAMP
languages | TINYINT
last_name | VARCHAR
last_name.keyword | VARCHAR
salary | INTEGER
;

0 comments on commit 6e1354c

Please sign in to comment.