From c8e69b160eb32a3b2fd60f70ca00931e5b20bfc4 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 28 Sep 2017 16:57:24 -0400 Subject: [PATCH] SQL: Fix build Fix a few forgetten things from the validation change. Original commit: elastic/x-pack-elasticsearch@807098dc6a0565ecbf93517dbc9e5a4b62158860 --- qa/sql/build.gradle | 2 - .../qa/sql/security/RestSqlSecurityIT.java | 4 +- .../xpack/qa/sql/jdbc/ErrorsTestCase.java | 2 +- .../function/UnresolvedFunction.java | 6 --- ...t.java => VerifierErrorMessagesTests.java} | 38 +++++-------------- 5 files changed, 12 insertions(+), 40 deletions(-) rename sql/server/src/test/java/org/elasticsearch/xpack/sql/analysis/analyzer/{VerifierErrorMessagesTest.java => VerifierErrorMessagesTests.java} (80%) diff --git a/qa/sql/build.gradle b/qa/sql/build.gradle index 041f55c3077..d927d04df88 100644 --- a/qa/sql/build.gradle +++ b/qa/sql/build.gradle @@ -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. diff --git a/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/RestSqlSecurityIT.java b/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/RestSqlSecurityIT.java index aeb3874806f..80bada842f0 100644 --- a/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/RestSqlSecurityIT.java +++ b/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/RestSqlSecurityIT.java @@ -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 diff --git a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/ErrorsTestCase.java b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/ErrorsTestCase.java index 2ab41a4a4f5..471c428265b 100644 --- a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/ErrorsTestCase.java +++ b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/ErrorsTestCase.java @@ -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()); } } } diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/UnresolvedFunction.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/UnresolvedFunction.java index 01856905a43..433d5a87564 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/UnresolvedFunction.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/UnresolvedFunction.java @@ -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 children, String unresolvedMessage) { super(location, children); diff --git a/sql/server/src/test/java/org/elasticsearch/xpack/sql/analysis/analyzer/VerifierErrorMessagesTest.java b/sql/server/src/test/java/org/elasticsearch/xpack/sql/analysis/analyzer/VerifierErrorMessagesTests.java similarity index 80% rename from sql/server/src/test/java/org/elasticsearch/xpack/sql/analysis/analyzer/VerifierErrorMessagesTest.java rename to sql/server/src/test/java/org/elasticsearch/xpack/sql/analysis/analyzer/VerifierErrorMessagesTests.java index e6fb55f1033..bae19209e20 100644 --- a/sql/server/src/test/java/org/elasticsearch/xpack/sql/analysis/analyzer/VerifierErrorMessagesTest.java +++ b/sql/server/src/test/java/org/elasticsearch/xpack/sql/analysis/analyzer/VerifierErrorMessagesTests.java @@ -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)")); } } \ No newline at end of file