From 94973425a8fe8cf96b84bc21466f47ecd98ab279 Mon Sep 17 00:00:00 2001 From: Jiaan Geng Date: Wed, 2 Aug 2023 12:48:48 +0800 Subject: [PATCH] [SPARK-41532][CONNECT][FOLLOWUP] Make the scala client using the same error class as python client ### What changes were proposed in this pull request? The python connect client define the error class in `error_classes.py`. `SESSION_NOT_SAME` is an error class used to check the `SparkSession` of one dataset is the same the other dataset. Please refer [`error_classes.py` ](https://github.com/apache/spark/blob/546e39c5dabc1111243ab81b6238dc893d9993e0/python/pyspark/errors/error_classes.py#L678C1-L678C1) But the scala connect client not the the same error class. ### Why are the changes needed? This PR make the scala client using the same error class as python client. ### Does this PR introduce _any_ user-facing change? 'No'. Just update the inner implementation. ### How was this patch tested? Exists test cases. Closes #42256 from beliefer/SPARK-41532_followup. Authored-by: Jiaan Geng Signed-off-by: Ruifeng Zheng --- common/utils/src/main/resources/error/error-classes.json | 5 +++++ .../jvm/src/main/scala/org/apache/spark/sql/Dataset.scala | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/common/utils/src/main/resources/error/error-classes.json b/common/utils/src/main/resources/error/error-classes.json index 06c47419fcb07..7012c66c8956e 100644 --- a/common/utils/src/main/resources/error/error-classes.json +++ b/common/utils/src/main/resources/error/error-classes.json @@ -409,6 +409,11 @@ "message" : [ "Error instantiating Spark Connect plugin: " ] + }, + "SESSION_NOT_SAME" : { + "message" : [ + "Both Datasets must belong to the same SparkSession." + ] } } }, diff --git a/connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/Dataset.scala b/connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/Dataset.scala index b0dd91293a0be..0f7b376955c96 100644 --- a/connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/Dataset.scala +++ b/connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/Dataset.scala @@ -1750,7 +1750,10 @@ class Dataset[T] private[sql] ( private def checkSameSparkSession(other: Dataset[_]): Unit = { if (this.sparkSession.sessionId != other.sparkSession.sessionId) { - throw new SparkException("Both Datasets must belong to the same SparkSession") + throw new SparkException( + errorClass = "CONNECT.SESSION_NOT_SAME", + messageParameters = Map.empty, + cause = null) } }