This is an automated email from the ASF dual-hosted git repository. zabetak pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push: new 6e061e65595 HIVE-28064: Add cause to ParseException for diagnosability purposes (Stamatis Zampetakis reviewed by okumin, Butao Zhang) 6e061e65595 is described below commit 6e061e6559522c8a060c1b55439ada0001bf5e5d Author: Stamatis Zampetakis <zabe...@gmail.com> AuthorDate: Tue Feb 6 12:59:24 2024 +0100 HIVE-28064: Add cause to ParseException for diagnosability purposes (Stamatis Zampetakis reviewed by okumin, Butao Zhang) The ParseException contains high level information about problems encountered during parsing but currently the stacktrace is pretty shallow. The end-user gets a hint about what the error might be but the developer has no way to tell how far we went into parsing the given statement and which grammar rule failed to pass. Add RecognitionException (when available) as cause in ParseException to provide better insights around the origin of the problem and grammar rules that were invoked till the crash. Close apache/hive#5067 --- .../java/org/apache/hadoop/hive/ql/parse/ParseDriver.java | 12 ++++++------ .../java/org/apache/hadoop/hive/ql/parse/ParseException.java | 11 +++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/parser/src/java/org/apache/hadoop/hive/ql/parse/ParseDriver.java b/parser/src/java/org/apache/hadoop/hive/ql/parse/ParseDriver.java index 7e54bdf95d5..c99895756d0 100644 --- a/parser/src/java/org/apache/hadoop/hive/ql/parse/ParseDriver.java +++ b/parser/src/java/org/apache/hadoop/hive/ql/parse/ParseDriver.java @@ -122,7 +122,7 @@ public class ParseDriver { try { r = parser.statement(); } catch (RecognitionException e) { - throw new ParseException(parser.errors); + throw new ParseException(parser.errors, e); } if (lexer.getErrors().size() == 0 && parser.errors.size() == 0) { @@ -152,7 +152,7 @@ public class ParseDriver { try { r = parser.hint(); } catch (RecognitionException e) { - throw new ParseException(parser.errors); + throw new ParseException(parser.errors, e); } if (lexer.getErrors().size() == 0 && parser.errors.size() == 0) { @@ -191,7 +191,7 @@ public class ParseDriver { try { r = parser.selectClause(); } catch (RecognitionException e) { - throw new ParseException(parser.errors); + throw new ParseException(parser.errors, e); } if (lexer.getErrors().size() == 0 && parser.errors.size() == 0) { @@ -215,7 +215,7 @@ public class ParseDriver { try { r = parser.expression(); } catch (RecognitionException e) { - throw new ParseException(parser.errors); + throw new ParseException(parser.errors, e); } if (lexer.getErrors().size() == 0 && parser.errors.size() == 0) { @@ -238,7 +238,7 @@ public class ParseDriver { try { r = parser.triggerExpressionStandalone(); } catch (RecognitionException e) { - throw new ParseException(parser.errors); + throw new ParseException(parser.errors, e); } if (lexer.getErrors().size() != 0) { throw new ParseException(lexer.getErrors()); @@ -258,7 +258,7 @@ public class ParseDriver { try { r = parser.triggerActionExpressionStandalone(); } catch (RecognitionException e) { - throw new ParseException(parser.errors); + throw new ParseException(parser.errors, e); } if (lexer.getErrors().size() != 0) { throw new ParseException(lexer.getErrors()); diff --git a/parser/src/java/org/apache/hadoop/hive/ql/parse/ParseException.java b/parser/src/java/org/apache/hadoop/hive/ql/parse/ParseException.java index 7d945adf0d3..5b2d17a19e7 100644 --- a/parser/src/java/org/apache/hadoop/hive/ql/parse/ParseException.java +++ b/parser/src/java/org/apache/hadoop/hive/ql/parse/ParseException.java @@ -18,8 +18,6 @@ package org.apache.hadoop.hive.ql.parse; -import java.util.ArrayList; - /** * ParseException. * @@ -27,13 +25,18 @@ import java.util.ArrayList; public class ParseException extends Exception { private static final long serialVersionUID = 1L; - ArrayList<ParseError> errors; + private final Iterable<ParseError> errors; - public ParseException(ArrayList<ParseError> errors) { + public ParseException(Iterable<ParseError> errors) { super(); this.errors = errors; } + public ParseException(Iterable<ParseError> errors, Throwable cause) { + super(cause); + this.errors = errors; + } + @Override public String getMessage() {