SQL: correct index name invocation

Original commit: elastic/x-pack-elasticsearch@cec6dd6dd9
This commit is contained in:
Costin Leau 2018-01-08 14:54:18 +02:00
parent aa85496090
commit dab50f7b77
4 changed files with 10 additions and 11 deletions

View File

@ -66,14 +66,14 @@ public class SqlActionIT extends AbstractSqlIntegTestCase {
SqlListTablesResponse response = client().prepareExecute(SqlListTablesAction.INSTANCE)
.pattern("").get();
List<String> tables = removeInternal(response.getTables());
assertThat(tables, hasSize(3));
assertThat(tables, containsInAnyOrder("foo", "bar", "baz"));
assertThat(tables, hasSize(4));
assertThat(tables, containsInAnyOrder("foo", "bar", "baz", "broken"));
response = client().prepareExecute(SqlListTablesAction.INSTANCE).pattern("b*").get();
tables = removeInternal(response.getTables());
assertThat(tables, hasSize(2));
assertThat(tables, containsInAnyOrder("bar", "baz"));
assertThat(tables, hasSize(3));
assertThat(tables, containsInAnyOrder("bar", "baz", "broken"));
response = client().prepareExecute(SqlListTablesAction.INSTANCE).pattern("not_found").get();
tables = removeInternal(response.getTables());
@ -81,7 +81,7 @@ public class SqlActionIT extends AbstractSqlIntegTestCase {
response = client().prepareExecute(SqlListTablesAction.INSTANCE).pattern("broken").get();
tables = removeInternal(response.getTables());
assertThat(tables, emptyCollectionOf(String.class));
assertThat(tables, hasSize(1));
}

View File

@ -103,7 +103,7 @@ public class RestSqlJdbcAction extends AbstractSqlProtocolRestAction {
private Consumer<RestChannel> metaTable(MetaTableRequest request) {
String indexPattern = hasText(request.pattern()) ? StringUtils.likeToIndexWildcard(request.pattern(), (char) 0) : "*";
String regexPattern = hasText(request.pattern()) ? StringUtils.likeToJavaPattern(request.pattern(), (char) 0) : "*";
String regexPattern = hasText(request.pattern()) ? StringUtils.likeToJavaPattern(request.pattern(), (char) 0) : null;
return channel -> indexResolver.resolveNames(indexPattern, regexPattern, toActionListener(channel, list ->
new MetaTableResponse(list.stream()
@ -113,7 +113,7 @@ public class RestSqlJdbcAction extends AbstractSqlProtocolRestAction {
private Consumer<RestChannel> metaColumn(MetaColumnRequest request) {
String indexPattern = hasText(request.tablePattern()) ? StringUtils.likeToIndexWildcard(request.tablePattern(), (char) 0) : "*";
String regexPattern = hasText(request.tablePattern()) ? StringUtils.likeToJavaPattern(request.tablePattern(), (char) 0) : "*";
String regexPattern = hasText(request.tablePattern()) ? StringUtils.likeToJavaPattern(request.tablePattern(), (char) 0) : null;
Pattern columnMatcher = hasText(request.columnPattern()) ? Pattern.compile(
StringUtils.likeToJavaPattern(request.columnPattern(), (char) 0)) : null;

View File

@ -49,7 +49,7 @@ public class TransportSqlListColumnsAction extends HandledTransportAction<SqlLis
String indexPattern = hasText(request.getTablePattern()) ?
StringUtils.likeToIndexWildcard(request.getTablePattern(), (char) 0) : "*";
String regexPattern = hasText(request.getTablePattern()) ?
StringUtils.likeToJavaPattern(request.getTablePattern(), (char) 0) : "*";
StringUtils.likeToJavaPattern(request.getTablePattern(), (char) 0) : null;
Pattern columnMatcher = hasText(request.getColumnPattern()) ?
Pattern.compile(StringUtils.likeToJavaPattern(request.getColumnPattern(), (char) 0)) : null;

View File

@ -15,7 +15,6 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.sql.analysis.index.IndexResolver;
import org.elasticsearch.xpack.sql.analysis.index.IndexResolver.IndexInfo;
import org.elasticsearch.xpack.sql.util.StringUtils;
import static java.util.stream.Collectors.toList;
import static org.elasticsearch.common.Strings.hasText;
@ -41,8 +40,8 @@ public class TransportSqlListTablesAction extends HandledTransportAction<SqlList
// TODO: This is wrong
// See https://github.com/elastic/x-pack-elasticsearch/pull/3438/commits/61b7c26fe08db2721f0431579f215fe493744af3
// and https://github.com/elastic/x-pack-elasticsearch/issues/3460
String indexPattern = hasText(request.getPattern()) ? StringUtils.likeToIndexWildcard(request.getPattern(), (char) 0) : "*";
String regexPattern = hasText(request.getPattern()) ? StringUtils.likeToJavaPattern(request.getPattern(), (char) 0) : "*";
String indexPattern = hasText(request.getPattern()) ? request.getPattern() : "*";
String regexPattern = null;
indexResolver.resolveNames(indexPattern, regexPattern, ActionListener.wrap(set -> listener.onResponse(
new SqlListTablesResponse(set.stream()