Issue a different error message in case an index doesn't have a mapping (#52967) (#53003)

(cherry picked from commit a0bd83a0579cf196a1d727de2a46b3b101d5a73b)
This commit is contained in:
Andrei Stefan 2020-03-02 14:04:49 +02:00 committed by GitHub
parent 69383acecf
commit 6fecc1db84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 14 deletions

View File

@ -289,7 +289,7 @@ public class IndexResolver {
public static IndexResolution mergedMappings(DataTypeRegistry typeRegistry, String indexPattern, String[] indexNames,
Map<String, Map<String, FieldCapabilities>> fieldCaps) {
if (fieldCaps == null || fieldCaps.isEmpty()) {
if (indexNames.length == 0) {
return IndexResolution.notFound(indexPattern);
}

View File

@ -13,7 +13,9 @@ package org.elasticsearch.xpack.sql.qa;
public interface ErrorsTestCase {
void testSelectInvalidSql() throws Exception;
void testSelectFromMissingIndex() throws Exception;
void testSelectFromIndexWithoutTypes() throws Exception;
void testSelectColumnFromMissingIndex() throws Exception;
void testSelectFromEmptyIndex() throws Exception;
void testSelectColumnFromEmptyIndex() throws Exception;
void testSelectMissingField() throws Exception;
void testSelectMissingFunction() throws Exception;
void testSelectProjectScoreInAggContext() throws Exception;

View File

@ -37,15 +37,30 @@ public abstract class ErrorsTestCase extends CliIntegrationTestCase implements o
}
@Override
public void testSelectFromIndexWithoutTypes() throws Exception {
public void testSelectColumnFromMissingIndex() throws Exception {
assertFoundOneProblem(command("SELECT abc FROM test"));
assertEquals("line 1:17: Unknown index [test]" + END, readLine());
}
@Override
public void testSelectFromEmptyIndex() throws Exception {
// Create an index without any types
Request request = new Request("PUT", "/test");
request.setJsonEntity("{}");
client().performRequest(request);
assertFoundOneProblem(command("SELECT * FROM test"));
//assertEquals("line 1:15: [test] doesn't have any types so it is incompatible with sql" + END, readLine());
assertEquals("line 1:15: Unknown index [test]" + END, readLine());
assertEquals("line 1:8: Cannot determine columns for [*]" + END, readLine());
}
@Override
public void testSelectColumnFromEmptyIndex() throws Exception {
Request request = new Request("PUT", "/test");
request.setJsonEntity("{}");
client().performRequest(request);
assertFoundOneProblem(command("SELECT abc FROM test"));
assertEquals("line 1:8: Unknown column [abc]" + END, readLine());
}
@Override

View File

@ -33,7 +33,15 @@ public class ErrorsTestCase extends JdbcIntegrationTestCase implements org.elast
}
@Override
public void testSelectFromIndexWithoutTypes() throws Exception {
public void testSelectColumnFromMissingIndex() throws Exception {
try (Connection c = esJdbc()) {
SQLException e = expectThrows(SQLException.class, () -> c.prepareStatement("SELECT abc FROM test").executeQuery());
assertEquals("Found 1 problem\nline 1:17: Unknown index [test]", e.getMessage());
}
}
@Override
public void testSelectFromEmptyIndex() throws Exception {
// Create an index without any types
Request request = new Request("PUT", "/test");
request.setJsonEntity("{}");
@ -41,9 +49,19 @@ public class ErrorsTestCase extends JdbcIntegrationTestCase implements org.elast
try (Connection c = esJdbc()) {
SQLException e = expectThrows(SQLException.class, () -> c.prepareStatement("SELECT * FROM test").executeQuery());
// see https://github.com/elastic/elasticsearch/issues/34719
//assertEquals("Found 1 problem\nline 1:15: [test] doesn't have any types so it is incompatible with sql", e.getMessage());
assertEquals("Found 1 problem\nline 1:15: Unknown index [test]", e.getMessage());
assertEquals("Found 1 problem\nline 1:8: Cannot determine columns for [*]", e.getMessage());
}
}
@Override
public void testSelectColumnFromEmptyIndex() throws Exception {
Request request = new Request("PUT", "/test");
request.setJsonEntity("{}");
client().performRequest(request);
try (Connection c = esJdbc()) {
SQLException e = expectThrows(SQLException.class, () -> c.prepareStatement("SELECT abc FROM test").executeQuery());
assertEquals("Found 1 problem\nline 1:8: Unknown column [abc]", e.getMessage());
}
}

View File

@ -317,16 +317,28 @@ public abstract class RestSqlTestCase extends BaseRestSqlTestCase implements Err
}
@Override
public void testSelectFromIndexWithoutTypes() throws Exception {
public void testSelectColumnFromMissingIndex() throws Exception {
String mode = randomFrom("jdbc", "plain");
expectBadRequest(() -> runSql(mode, "SELECT abc FROM missing"), containsString("1:17: Unknown index [missing]"));
}
@Override
public void testSelectFromEmptyIndex() throws Exception {
// Create an index without any types
Request request = new Request("PUT", "/test");
request.setJsonEntity("{}");
client().performRequest(request);
String mode = randomFrom("jdbc", "plain");
expectBadRequest(() -> runSql(mode, "SELECT * FROM test"),
// see https://github.com/elastic/elasticsearch/issues/34719
//containsString("1:15: [test] doesn't have any types so it is incompatible with sql"));
containsString("1:15: Unknown index [test]"));
expectBadRequest(() -> runSql(mode, "SELECT * FROM test"), containsString("1:8: Cannot determine columns for [*]"));
}
@Override
public void testSelectColumnFromEmptyIndex() throws Exception {
Request request = new Request("PUT", "/test");
request.setJsonEntity("{}");
client().performRequest(request);
String mode = randomFrom("jdbc", "plain");
expectBadRequest(() -> runSql(mode, "SELECT abc FROM test"), containsString("1:8: Unknown column [abc]"));
}
@Override