itholic commented on code in PR #39387:
URL: https://github.com/apache/spark/pull/39387#discussion_r1064967250


##########
python/pyspark/errors/utils.py:
##########
@@ -0,0 +1,133 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import os
+import json
+import re
+from typing import Dict
+
+
+ERROR_CLASSES_JSON = "error-classes.json"
+ERROR_CLASSES_PATH = os.path.join(os.path.dirname(__file__), 
ERROR_CLASSES_JSON)
+
+
+class ErrorClassesJsonReader:
+    """
+    A reader to load error information from JSON file.
+    """
+
+    def __init__(self, json_file_path: str):
+        try:
+            self.error_info_map = json.load(open(json_file_path))
+        except NotADirectoryError:
+            # In this case, PySpark is installed as zip file such as 
`pyspark.zip`.
+            # Thus, we use ZipFile to read the error-classes.json inside of 
zip.
+            from zipfile import ZipFile
+
+            # e.g. `/spark-3.3.1-bin-hadoop3/python/lib/pyspark.zip`
+            zip_path = os.path.abspath(os.path.join(json_file_path, "..", 
"..", ".."))
+            with ZipFile(zip_path) as z:
+                # e.g. `errors/error-classes.json`
+                error_classes_relative_path = os.path.join("pyspark/errors", 
ERROR_CLASSES_JSON)
+                with z.open(error_classes_relative_path) as f:
+                    self.error_info_map = json.loads(f.read())

Review Comment:
   This is added for handling the case when PySpark is used as a `.zip` package.
   
   I manually tested by building with `sbt` and `mvn`, and see both way work 
fine.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to