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


##########
python/pyspark/sql/functions.py:
##########
@@ -172,7 +173,9 @@ def lit(col: Any) -> Column:
         return col
     elif isinstance(col, list):
         if any(isinstance(c, Column) for c in col):
-            raise ValueError("lit does not allow a column in a list")
+            raise PySparkException(
+                error_class="COLUMN_IN_LIST", message_parameters={"funcName": 
"lit"}
+            )

Review Comment:
   ditto.
   
   Will migrate more errors in large batches as follow-ups
   
   I believe it would be a big task, so I will create several sub-tasks under 
[umbrella JIRA](https://issues.apache.org/jira/browse/SPARK-41597).



##########
python/pyspark/errors/error-classes.json:
##########
@@ -0,0 +1,7 @@
+{
+  "COLUMN_IN_LIST" : {
+    "message" : [
+      "<funcName> does not allow a column in a list"
+    ]

Review Comment:
   Will add more error-classes in follow-up PRs.
   
   Since this PR introduces the error class for PySpark for the first time, I 
made only one example for the convenience of review.



##########
python/pyspark/sql/tests/test_functions.py:
##########
@@ -1030,9 +1031,13 @@ def test_lit_list(self):
             self.assertEqual(actual, expected)
 
         df = self.spark.range(10)
-        with self.assertRaisesRegex(ValueError, "lit does not allow a column 
in a list"):
+        with self.assertRaises(PySparkException) as pe:
             lit([df.id, df.id])
 
+        self.check_error(
+            exception=pe, error_class="COLUMN_IN_LIST", 
message_parameters={"funcName": "lit"}
+        )

Review Comment:
   ditto.
   
   Will migrate more error tests into error class tests.



-- 
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