|
23 | 23 | import tempfile
|
24 | 24 | from collections import defaultdict
|
25 | 25 |
|
26 |
| -from pyspark.errors import PySparkTypeError |
| 26 | +from pyspark.errors import PySparkAttributeError, PySparkTypeError |
27 | 27 | from pyspark.sql import SparkSession as PySparkSession, Row
|
28 | 28 | from pyspark.sql.types import (
|
29 | 29 | StructType,
|
@@ -2936,6 +2936,53 @@ def test_map_has_nullable(self):
|
2936 | 2936 | self.assertEqual(cdf2.schema, sdf2.schema)
|
2937 | 2937 | self.assertEqual(cdf2.collect(), sdf2.collect())
|
2938 | 2938 |
|
| 2939 | + def test_unsupported_jvm_attribute(self): |
| 2940 | + # Unsupported jvm attributes for Spark session. |
| 2941 | + unsupported_attrs = ["_jsc", "_jconf", "_jvm", "_jsparkSession"] |
| 2942 | + spark_session = self.connect |
| 2943 | + for attr in unsupported_attrs: |
| 2944 | + with self.assertRaises(PySparkAttributeError) as pe: |
| 2945 | + getattr(spark_session, attr) |
| 2946 | + |
| 2947 | + self.check_error( |
| 2948 | + exception=pe.exception, |
| 2949 | + error_class="JVM_ATTRIBUTE_NOT_SUPPORTED", |
| 2950 | + message_parameters={"attr_name": attr}, |
| 2951 | + ) |
| 2952 | + |
| 2953 | + # Unsupported jvm attributes for DataFrame. |
| 2954 | + unsupported_attrs = ["_jseq", "_jdf", "_jmap", "_jcols"] |
| 2955 | + cdf = self.connect.range(10) |
| 2956 | + for attr in unsupported_attrs: |
| 2957 | + with self.assertRaises(PySparkAttributeError) as pe: |
| 2958 | + getattr(cdf, attr) |
| 2959 | + |
| 2960 | + self.check_error( |
| 2961 | + exception=pe.exception, |
| 2962 | + error_class="JVM_ATTRIBUTE_NOT_SUPPORTED", |
| 2963 | + message_parameters={"attr_name": attr}, |
| 2964 | + ) |
| 2965 | + |
| 2966 | + # Unsupported jvm attributes for Column. |
| 2967 | + with self.assertRaises(PySparkAttributeError) as pe: |
| 2968 | + getattr(cdf.id, "_jc") |
| 2969 | + |
| 2970 | + self.check_error( |
| 2971 | + exception=pe.exception, |
| 2972 | + error_class="JVM_ATTRIBUTE_NOT_SUPPORTED", |
| 2973 | + message_parameters={"attr_name": "_jc"}, |
| 2974 | + ) |
| 2975 | + |
| 2976 | + # Unsupported jvm attributes for DataFrameReader. |
| 2977 | + with self.assertRaises(PySparkAttributeError) as pe: |
| 2978 | + getattr(spark_session.read, "_jreader") |
| 2979 | + |
| 2980 | + self.check_error( |
| 2981 | + exception=pe.exception, |
| 2982 | + error_class="JVM_ATTRIBUTE_NOT_SUPPORTED", |
| 2983 | + message_parameters={"attr_name": "_jreader"}, |
| 2984 | + ) |
| 2985 | + |
2939 | 2986 |
|
2940 | 2987 | @unittest.skipIf(not should_test_connect, connect_requirement_message)
|
2941 | 2988 | class ClientTests(unittest.TestCase):
|
|
0 commit comments