This is an automated email from the ASF dual-hosted git repository.
ruifengz pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new 972065d43558 [SPARK-51139][ML][CONNECT] Refine error class
`MLAttributeNotAllowedException`
972065d43558 is described below
commit 972065d43558f5ea85a119d80a611abefa0511af
Author: Ruifeng Zheng <[email protected]>
AuthorDate: Mon Feb 10 12:10:13 2025 +0800
[SPARK-51139][ML][CONNECT] Refine error class
`MLAttributeNotAllowedException`
### What changes were proposed in this pull request?
Refine error class `MLAttributeNotAllowedException`
### Why are the changes needed?
this error message should contains the class name
### Does this PR introduce _any_ user-facing change?
yes, error change
### How was this patch tested?
updated tests
### Was this patch authored or co-authored using generative AI tooling?
no
Closes #49860 from zhengruifeng/refine_attr_exception.
Authored-by: Ruifeng Zheng <[email protected]>
Signed-off-by: Ruifeng Zheng <[email protected]>
(cherry picked from commit 34e6e447510ea6502d4451cdc1384ddfd5daf991)
Signed-off-by: Ruifeng Zheng <[email protected]>
---
common/utils/src/main/resources/error/error-conditions.json | 2 +-
.../src/main/scala/org/apache/spark/sql/connect/ml/MLException.scala | 4 ++--
.../src/main/scala/org/apache/spark/sql/connect/ml/MLUtils.scala | 2 +-
.../src/test/scala/org/apache/spark/sql/connect/ml/MLSuite.scala | 5 ++++-
4 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/common/utils/src/main/resources/error/error-conditions.json
b/common/utils/src/main/resources/error/error-conditions.json
index ea7fb9d7d511..1fa5f6740894 100644
--- a/common/utils/src/main/resources/error/error-conditions.json
+++ b/common/utils/src/main/resources/error/error-conditions.json
@@ -765,7 +765,7 @@
"subClass" : {
"ATTRIBUTE_NOT_ALLOWED" : {
"message" : [
- "<attribute> is not allowed to be accessed."
+ "<attribute> in <className> is not allowed to be accessed."
]
},
"UNSUPPORTED_EXCEPTION" : {
diff --git
a/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/ml/MLException.scala
b/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/ml/MLException.scala
index eb88bf9169d3..7700eccf6553 100644
---
a/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/ml/MLException.scala
+++
b/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/ml/MLException.scala
@@ -25,8 +25,8 @@ private[spark] case class MlUnsupportedException(message:
String)
messageParameters = Map("message" -> message),
cause = null)
-private[spark] case class MLAttributeNotAllowedException(attribute: String)
+private[spark] case class MLAttributeNotAllowedException(className: String,
attribute: String)
extends SparkException(
errorClass = "CONNECT_ML.ATTRIBUTE_NOT_ALLOWED",
- messageParameters = Map("attribute" -> attribute),
+ messageParameters = Map("className" -> className, "attribute" ->
attribute),
cause = null)
diff --git
a/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/ml/MLUtils.scala
b/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/ml/MLUtils.scala
index 84a26d9e4962..c999772b7d82 100644
---
a/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/ml/MLUtils.scala
+++
b/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/ml/MLUtils.scala
@@ -674,7 +674,7 @@ private[ml] object MLUtils {
cls.isInstance(obj) && methods.contains(method)
}
if (!valid) {
- throw MLAttributeNotAllowedException(method)
+ throw MLAttributeNotAllowedException(obj.getClass.getName, method)
}
}
diff --git
a/sql/connect/server/src/test/scala/org/apache/spark/sql/connect/ml/MLSuite.scala
b/sql/connect/server/src/test/scala/org/apache/spark/sql/connect/ml/MLSuite.scala
index c3ab6248be8f..cc24a2a67439 100644
---
a/sql/connect/server/src/test/scala/org/apache/spark/sql/connect/ml/MLSuite.scala
+++
b/sql/connect/server/src/test/scala/org/apache/spark/sql/connect/ml/MLSuite.scala
@@ -261,9 +261,12 @@ class MLSuite extends MLHelper {
val modelId = trainLogisticRegressionModel(sessionHolder)
val fakeAttributeCmd = fetchCommand(modelId, "notExistingAttribute")
- intercept[MLAttributeNotAllowedException] {
+ val e = intercept[MLAttributeNotAllowedException] {
MLHandler.handleMlCommand(sessionHolder, fakeAttributeCmd)
}
+ val msg = e.getMessage
+ assert(msg.contains("notExistingAttribute"))
+
assert(msg.contains("org.apache.spark.ml.classification.LogisticRegressionModel"))
}
test("Model must be registered into ServiceLoader when loading") {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]