SQL: Fix build
Fix a few forgetten things from the validation change. Original commit: elastic/x-pack-elasticsearch@807098dc6a
This commit is contained in:
parent
d634314dd1
commit
c8e69b160e
|
@ -21,8 +21,6 @@ dependencies {
|
|||
}
|
||||
compile "net.sourceforge.csvjdbc:csvjdbc:1.0.31"
|
||||
runtime "com.h2database:h2:1.4.194"
|
||||
runtime 'org.antlr:antlr4-runtime:4.5.1-1'
|
||||
|
||||
|
||||
// There are *no* CLI testing dependencies because we
|
||||
// communicate fork a new CLI process when we need it.
|
||||
|
|
|
@ -199,7 +199,7 @@ public class RestSqlSecurityIT extends ESRestTestCase {
|
|||
assertAuditForSqlGetTableSyncGranted("test_admin", "test");
|
||||
assertAuditForSqlGetTableSyncGranted("only_a", "test");
|
||||
clearAuditEvents();
|
||||
expectBadRequest(() -> runSql("SELECT c FROM test", "only_a"), containsString("line 1:8: Unresolved item 'c'"));
|
||||
expectBadRequest(() -> runSql("SELECT c FROM test", "only_a"), containsString("line 1:8: Unknown column [c]"));
|
||||
/* The user has permission to query the index but one of the
|
||||
* columns that they explicitly mention is hidden from them
|
||||
* by field level access control. This *looks* like a successful
|
||||
|
@ -216,7 +216,7 @@ public class RestSqlSecurityIT extends ESRestTestCase {
|
|||
assertAuditForSqlGetTableSyncGranted("test_admin", "test");
|
||||
assertAuditForSqlGetTableSyncGranted("not_c", "test");
|
||||
clearAuditEvents();
|
||||
expectBadRequest(() -> runSql("SELECT c FROM test", "not_c"), containsString("line 1:8: Unresolved item 'c'"));
|
||||
expectBadRequest(() -> runSql("SELECT c FROM test", "not_c"), containsString("line 1:8: Unknown column [c]"));
|
||||
/* The user has permission to query the index but one of the
|
||||
* columns that they explicitly mention is hidden from them
|
||||
* by field level access control. This *looks* like a successful
|
||||
|
|
|
@ -15,7 +15,7 @@ public class ErrorsTestCase extends JdbcIntegrationTestCase {
|
|||
public void testSelectFromMissingTable() throws Exception {
|
||||
try (Connection c = esJdbc()) {
|
||||
SQLException e = expectThrows(SQLException.class, () -> c.prepareStatement("SELECT * from test").executeQuery());
|
||||
assertEquals("line 1:15: index [test] does not exist", e.getMessage());
|
||||
assertEquals("Found 1 problem(s)\nline 1:15: Unknown index [test]", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,12 +27,6 @@ public class UnresolvedFunction extends Function implements Unresolvable {
|
|||
|
||||
/**
|
||||
* Constructor used for specifying a more descriptive message (typically 'did you mean') instead of the default one.
|
||||
*
|
||||
* @param location
|
||||
* @param name
|
||||
* @param distinct
|
||||
* @param children
|
||||
* @param unresolvedMessage
|
||||
*/
|
||||
public UnresolvedFunction(Location location, String name, boolean distinct, List<Expression> children, String unresolvedMessage) {
|
||||
super(location, children);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.xpack.sql.analysis.analyzer;
|
||||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.sql.analysis.AnalysisException;
|
||||
import org.elasticsearch.xpack.sql.analysis.catalog.Catalog;
|
||||
import org.elasticsearch.xpack.sql.analysis.catalog.EsIndex;
|
||||
|
@ -15,25 +16,21 @@ import org.elasticsearch.xpack.sql.expression.function.FunctionRegistry;
|
|||
import org.elasticsearch.xpack.sql.parser.SqlParser;
|
||||
import org.elasticsearch.xpack.sql.type.DataType;
|
||||
import org.elasticsearch.xpack.sql.type.DataTypes;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class VerifierErrorMessagesTest {
|
||||
public class VerifierErrorMessagesTests extends ESTestCase {
|
||||
|
||||
private SqlParser parser;
|
||||
private FunctionRegistry functionRegistry;
|
||||
private Catalog catalog;
|
||||
private Analyzer analyzer;
|
||||
|
||||
public VerifierErrorMessagesTest() {
|
||||
public VerifierErrorMessagesTests() {
|
||||
parser = new SqlParser();
|
||||
functionRegistry = new DefaultFunctionRegistry();
|
||||
|
||||
|
@ -48,74 +45,57 @@ public class VerifierErrorMessagesTest {
|
|||
}
|
||||
|
||||
private String verify(String sql) {
|
||||
try {
|
||||
analyzer.analyze(parser.createStatement(sql), true);
|
||||
fail("query is valid; expected an invalid one");
|
||||
return "";
|
||||
} catch (AnalysisException ae) {
|
||||
String message = ae.getMessage();
|
||||
assertTrue(message.startsWith("Found "));
|
||||
// test uses 1 or multiple
|
||||
String header = "Found 1 problem(s)\nline ";
|
||||
return message.substring(header.length());
|
||||
}
|
||||
AnalysisException e = expectThrows(AnalysisException.class, () -> analyzer.analyze(parser.createStatement(sql), true));
|
||||
assertTrue(e.getMessage().startsWith("Found "));
|
||||
String header = "Found 1 problem(s)\nline ";
|
||||
return e.getMessage().substring(header.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingIndex() {
|
||||
assertEquals("1:17: Unknown index [missing]", verify("SELECT foo FROM missing"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingColumn() {
|
||||
assertEquals("1:8: Unknown column [xxx]", verify("SELECT xxx FROM test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMispelledColumn() {
|
||||
assertEquals("1:8: Unknown column [txt], did you mean [text]?", verify("SELECT txt FROM test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionOverMissingField() {
|
||||
assertEquals("1:12: Unknown column [xxx]", verify("SELECT ABS(xxx) FROM test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingFunction() {
|
||||
assertEquals("1:8: Unknown function [ZAZ]", verify("SELECT ZAZ(bool) FROM test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMispelledFunction() {
|
||||
assertEquals("1:8: Unknown function [COONT], did you mean [COUNT]?", verify("SELECT COONT(bool) FROM test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingColumnInGroupBy() {
|
||||
assertEquals("1:41: Unknown column [xxx]", verify("SELECT * FROM test GROUP BY DAY_OF_YEAR(xxx)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterOnUnknownColumn() {
|
||||
assertEquals("1:26: Unknown column [xxx]", verify("SELECT * FROM test WHERE xxx = 1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingColumnInOrderby() {
|
||||
// xxx offset is that of the order by field
|
||||
assertEquals("1:29: Unknown column [xxx]", verify("SELECT * FROM test ORDER BY xxx"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingColumnFunctionInOrderby() {
|
||||
// xxx offset is that of the order by field
|
||||
assertEquals("1:41: Unknown column [xxx]", verify("SELECT * FROM test ORDER BY DAY_oF_YEAR(xxx)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleColumns() {
|
||||
// xxx offset is that of the order by field
|
||||
assertEquals("1:43: Unknown column [xxx]\nline 1:8: Unknown column [xxx]", verify("SELECT xxx FROM test GROUP BY DAY_oF_YEAR(xxx)"));
|
||||
assertEquals("1:43: Unknown column [xxx]\nline 1:8: Unknown column [xxx]",
|
||||
verify("SELECT xxx FROM test GROUP BY DAY_oF_YEAR(xxx)"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue