diff options
author | Davies Liu <davies@databricks.com> | 2015-06-30 16:17:46 -0700 |
---|---|---|
committer | Davies Liu <davies@databricks.com> | 2015-06-30 16:17:46 -0700 |
commit | 58ee2a2e47948a895e557fbcabbeadb31f0a1022 (patch) | |
tree | 86d79553be2fd7df6b7afe2b226bb40ede319725 /python/pyspark/sql/tests.py | |
parent | d2495f7cc7d7caaa50d122d2969ddb693e6ecebd (diff) | |
download | spark-58ee2a2e47948a895e557fbcabbeadb31f0a1022.tar.gz spark-58ee2a2e47948a895e557fbcabbeadb31f0a1022.tar.bz2 spark-58ee2a2e47948a895e557fbcabbeadb31f0a1022.zip |
[SPARK-8738] [SQL] [PYSPARK] capture SQL AnalysisException in Python API
Capture the AnalysisException in SQL, hide the long java stack trace, only show the error message.
cc rxin
Author: Davies Liu <davies@databricks.com>
Closes #7135 from davies/ananylis and squashes the following commits:
dad7ae7 [Davies Liu] add comment
ec0c0e8 [Davies Liu] Update utils.py
cdd7edd [Davies Liu] add doc
7b044c2 [Davies Liu] fix python 3
f84d3bd [Davies Liu] capture SQL AnalysisException in Python API
Diffstat (limited to 'python/pyspark/sql/tests.py')
-rw-r--r-- | python/pyspark/sql/tests.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/python/pyspark/sql/tests.py b/python/pyspark/sql/tests.py index 34f397d0ff..5af2ce09bc 100644 --- a/python/pyspark/sql/tests.py +++ b/python/pyspark/sql/tests.py @@ -46,6 +46,7 @@ from pyspark.sql.types import UserDefinedType, _infer_type from pyspark.tests import ReusedPySparkTestCase from pyspark.sql.functions import UserDefinedFunction from pyspark.sql.window import Window +from pyspark.sql.utils import AnalysisException class UTC(datetime.tzinfo): @@ -847,6 +848,12 @@ class SQLTests(ReusedPySparkTestCase): self.assertEqual(row.age, 10) self.assertEqual(row.height, None) + def test_capture_analysis_exception(self): + self.assertRaises(AnalysisException, lambda: self.sqlCtx.sql("select abc")) + self.assertRaises(AnalysisException, lambda: self.df.selectExpr("a + b")) + # RuntimeException should not be captured + self.assertRaises(py4j.protocol.Py4JJavaError, lambda: self.sqlCtx.sql("abc")) + class HiveContextSQLTests(ReusedPySparkTestCase): |