File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -1079,6 +1079,12 @@ def test_capture_illegalargument_exception(self):
10791079 df = self .sqlCtx .createDataFrame ([(1 , 2 )], ["a" , "b" ])
10801080 self .assertRaisesRegexp (IllegalArgumentException , "1024 is not in the permitted values" ,
10811081 lambda : df .select (sha2 (df .a , 1024 )).collect ())
1082+ try :
1083+ df .select (sha2 (df .a , 1024 )).collect ()
1084+ except IllegalArgumentException as e :
1085+ self .assertRegexpMatches (e .desc , "1024 is not in the permitted values" )
1086+ self .assertRegexpMatches (e .stackTrace ,
1087+ "org.apache.spark.sql.functions" )
10821088
10831089 def test_with_column_with_existing_name (self ):
10841090 keys = self .df .withColumn ("key" , self .df .key ).select ("key" ).collect ()
Original file line number Diff line number Diff line change 1818import py4j
1919
2020
21- class AnalysisException (Exception ):
21+ class CapturedException (Exception ):
22+ def __init__ (self , desc , stackTrace ):
23+ self .desc = desc
24+ self .stackTrace = stackTrace
25+
26+ def __str__ (self ):
27+ return repr (self .desc )
28+
29+
30+ class AnalysisException (CapturedException ):
2231 """
2332 Failed to analyze a SQL query plan.
2433 """
2534
2635
27- class IllegalArgumentException (Exception ):
36+ class IllegalArgumentException (CapturedException ):
2837 """
2938 Passed an illegal or inappropriate argument.
3039 """
@@ -36,10 +45,12 @@ def deco(*a, **kw):
3645 return f (* a , ** kw )
3746 except py4j .protocol .Py4JJavaError as e :
3847 s = e .java_exception .toString ()
48+ stackTrace = '\n \t at ' .join (map (lambda x : x .toString (),
49+ e .java_exception .getStackTrace ()))
3950 if s .startswith ('org.apache.spark.sql.AnalysisException: ' ):
40- raise AnalysisException (s .split (': ' , 1 )[1 ])
51+ raise AnalysisException (s .split (': ' , 1 )[1 ], stackTrace )
4152 if s .startswith ('java.lang.IllegalArgumentException: ' ):
42- raise IllegalArgumentException (s .split (': ' , 1 )[1 ])
53+ raise IllegalArgumentException (s .split (': ' , 1 )[1 ], stackTrace )
4354 raise
4455 return deco
4556
You can’t perform that action at this time.
0 commit comments