You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by jo...@apache.org on 2019/05/17 23:36:49 UTC
[impala] 01/03: IMPALA-8497: Fix ArrayIndexOutOfBoundsException for
queries that end with '\n'
This is an automated email from the ASF dual-hosted git repository.
joemcdonnell pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
commit 4767d9263782d132ca1eeef8fea7761dc746354f
Author: wangsheng <sk...@163.com>
AuthorDate: Tue May 7 10:15:47 2019 +0800
IMPALA-8497: Fix ArrayIndexOutOfBoundsException for queries that
end with '\n'
When query ends with '\n', impala would throw
ArrayIndexOutOfBoundsException, instead of a syntax error.
The bug only affects the queries submitted directly to
Impala outside Impala shell.
Tests:
* Added test cases in ParserTest.java
* Ran all front-end tests
Change-Id: I3f034b351d0468a77773f6482e27ddef818b34d8
Reviewed-on: http://gerrit.cloudera.org:8080/13293
Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
fe/src/main/cup/sql-parser.cup | 3 +-
.../org/apache/impala/analysis/ParserTest.java | 45 ++++++++++++++++++++++
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/fe/src/main/cup/sql-parser.cup b/fe/src/main/cup/sql-parser.cup
index 17e7dd4..df6fbf1 100644
--- a/fe/src/main/cup/sql-parser.cup
+++ b/fe/src/main/cup/sql-parser.cup
@@ -170,7 +170,8 @@ parser code {:
// that parse() has been called and threw an exception
public String getErrorMsg(String stmt) {
if (errorToken_ == null || stmt == null) return null;
- String[] lines = stmt.split("\n");
+ // IMPALA-8497: Fix ArrayIndexOutOfBoundsException for queries that end with '\n'
+ String[] lines = stmt.split("\n", -1);
StringBuffer result = new StringBuffer();
result.append(getErrorTypeMessage(errorToken_.sym) + " in line ");
result.append(errorToken_.left);
diff --git a/fe/src/test/java/org/apache/impala/analysis/ParserTest.java b/fe/src/test/java/org/apache/impala/analysis/ParserTest.java
index cc30926..d63bb7f 100644
--- a/fe/src/test/java/org/apache/impala/analysis/ParserTest.java
+++ b/fe/src/test/java/org/apache/impala/analysis/ParserTest.java
@@ -3435,6 +3435,24 @@ public class ParserTest extends FrontendTestBase {
" ^\n" +
"Encountered: EOF\n" +
"Expected: =\n");
+
+ // End with \n
+ ParserError("SELECT\n",
+ "Syntax error in line 2:\n" +
+ "\n" +
+ "^\n" +
+ "Encountered: EOF\n" +
+ "Expected: ALL, CASE, CAST, DATE, DEFAULT, DISTINCT, EXISTS, FALSE, " +
+ "IF, INTERVAL, LEFT, NOT, NULL, REPLACE, RIGHT, " +
+ "STRAIGHT_JOIN, TRUNCATE, TRUE, IDENTIFIER\n");
+ ParserError("SELECT\n\n",
+ "Syntax error in line 3:\n" +
+ "\n" +
+ "^\n" +
+ "Encountered: EOF\n" +
+ "Expected: ALL, CASE, CAST, DATE, DEFAULT, DISTINCT, EXISTS, FALSE, " +
+ "IF, INTERVAL, LEFT, NOT, NULL, REPLACE, RIGHT, " +
+ "STRAIGHT_JOIN, TRUNCATE, TRUE, IDENTIFIER\n");
}
@Test
@@ -3970,4 +3988,31 @@ public class ParserTest extends FrontendTestBase {
ParserError("select * from .123_bar");
ParserError("select * from . 123_bar");
}
+
+ @Test
+ public void TestLineBreakEnd() {
+ ParserError("--test\n");
+ ParserError("--test\n ");
+ ParserError("SELECT\n");
+ ParserError("SELECT\n ");
+ ParserError("SHOW\n");
+ ParserError("SHOW\n ");
+ ParserError("INSERT\n");
+ ParserError("INSERT\n ");
+ ParserError("DROP\n");
+ ParserError("DROP\n ");
+ ParserError(" \n");
+ ParserError("\n ");
+ ParserError("\n");
+
+ ParserError("SELECT\n\n");
+ ParserError("SELECT\n\n\n");
+ ParserError("SELECT\n\n \n");
+ ParserError("SELECT\n \n\n");
+ ParserError("SELECT\n\n ");
+ ParserError("SELECT \n\n");
+
+ ParsesOk("--test\nSELECT 1\n");
+ ParsesOk("--test\nSELECT 1\n ");
+ }
}