You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "heyihong (via GitHub)" <gi...@apache.org> on 2023/08/01 14:14:51 UTC

[GitHub] [spark] heyihong opened a new pull request, #42266: [SPARK-44575] Implement basic error translation

heyihong opened a new pull request, #42266:
URL: https://github.com/apache/spark/pull/42266

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   - Implement basic error translation for spark connect scala client. 
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   - Better compatibility with the existing control flow
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   - No
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   
   `build/sbt "connect-client-jvm/testOnly *Suite"`


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285520525


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/ErrorFactoryBuilder.scala:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.spark.sql.connect.client
+
+import scala.collection.mutable
+import scala.reflect.ClassTag
+
+private[client] class ErrorFactoryBuilder() {
+
+  private val constructors = mutable.Map[String, (String, Throwable) => Throwable]()

Review Comment:
   ```suggestion
     private val constructors = mutable.Map.empty[String, (String, Throwable) => Throwable]
   ```



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #42266:
URL: https://github.com/apache/spark/pull/42266#issuecomment-1668604341

   Merged to master and branch-3.5.


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] amaliujia commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "amaliujia (via GitHub)" <gi...@apache.org>.
amaliujia commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1282412197


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -47,11 +52,37 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
+  private val errorFactory = new ErrorFactoryBuilder()
+    .addConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .addConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Throwable = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    for (cls <- classes) {
+      errorFactory.get(cls) match {
+        case Some(constructor) =>
+          return constructor(message, null)
+        case None =>
+        // Do nothing

Review Comment:
   `val classes = mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])` 
   
   this is a array of string. Why it is designed as array but just a single value?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285767057


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -53,11 +60,33 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
-    val status = StatusProto.fromThrowable(ex)
-    // TODO: Add finer grained error conversion
-    new SparkException(status.getMessage, ex.getCause)
+  private val errorFactory = new ErrorFactoryBuilder()
+    .registerConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .registerConstructor((message, _) => new AnalysisException(message))

Review Comment:
   Can we set cause to `AnalysisException ` here then?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285523986


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -47,11 +52,37 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
+  private val errorFactory = new ErrorFactoryBuilder()
+    .addConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .addConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Throwable = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    for (cls <- classes) {
+      errorFactory.get(cls) match {
+        case Some(constructor) =>
+          return constructor(message, null)
+        case None =>
+        // Do nothing
+      }
+    }
+
+    new SparkException(message)

Review Comment:
   Why don't you return `Option[Throwable]` instead of throwing an exception here? I think it's easier to follow the code if there's only one place that throws an exception.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] amaliujia commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "amaliujia (via GitHub)" <gi...@apache.org>.
amaliujia commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1282376757


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -47,11 +52,37 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
+  private val errorFactory = new ErrorFactoryBuilder()
+    .addConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .addConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Throwable = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    for (cls <- classes) {
+      errorFactory.get(cls) match {
+        case Some(constructor) =>
+          return constructor(message, null)
+        case None =>
+        // Do nothing

Review Comment:
   Will we ever hit this?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] heyihong commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285579913


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/ErrorFactoryBuilder.scala:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.spark.sql.connect.client
+
+import scala.collection.mutable
+import scala.reflect.ClassTag
+
+private[client] class ErrorFactoryBuilder() {
+
+  private val constructors = mutable.Map[String, (String, Throwable) => Throwable]()
+
+  def addConstructor[T <: Throwable: ClassTag](
+      throwableCtr: (String, Throwable) => T): ErrorFactoryBuilder = {

Review Comment:
   Throwable is cause. I added documentation.



##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/ErrorFactoryBuilder.scala:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.spark.sql.connect.client
+
+import scala.collection.mutable
+import scala.reflect.ClassTag
+
+private[client] class ErrorFactoryBuilder() {
+
+  private val constructors = mutable.Map[String, (String, Throwable) => Throwable]()
+
+  def addConstructor[T <: Throwable: ClassTag](
+      throwableCtr: (String, Throwable) => T): ErrorFactoryBuilder = {

Review Comment:
   Throwable is for cause. I added documentation.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] heyihong commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285573500


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/ErrorFactoryBuilder.scala:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.spark.sql.connect.client
+
+import scala.collection.mutable
+import scala.reflect.ClassTag
+
+private[client] class ErrorFactoryBuilder() {

Review Comment:
   I implement the builder class for two reasons:
   1. Use addConstructor method to infer the class name of the exceptions to update the map
   2. Use a builder class for extensions. There may be other places that need to register a couple of Exceptions. Having a builder class may such extensions easier.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] heyihong commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1286014657


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -53,11 +60,33 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
-    val status = StatusProto.fromThrowable(ex)
-    // TODO: Add finer grained error conversion
-    new SparkException(status.getMessage, ex.getCause)
+  private val errorFactory = new ErrorFactoryBuilder()
+    .registerConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .registerConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Option[Throwable] = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    classes
+      .find(errorFactory.contains(_))
+      .map { cls =>
+        errorFactory.get(cls).get(message, null)

Review Comment:
   errorFactory.contains(cls) should be true if find(...) return Some(cls). So errorFactory.get(cls) should not be null



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] heyihong commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285569259


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -47,11 +52,37 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
+  private val errorFactory = new ErrorFactoryBuilder()
+    .addConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))

Review Comment:
   The current plan is to only construct exceptions by (message, cause) on the client side. We may need to extend Spark related exceptions to support (message, cause) constructor if they don't have one



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] amaliujia commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "amaliujia (via GitHub)" <gi...@apache.org>.
amaliujia commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1282378744


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -47,11 +52,37 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
+  private val errorFactory = new ErrorFactoryBuilder()
+    .addConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .addConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Throwable = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    for (cls <- classes) {
+      errorFactory.get(cls) match {
+        case Some(constructor) =>
+          return constructor(message, null)
+        case None =>
+        // Do nothing

Review Comment:
   oh so this happens when there is nothing found from errorFactory so `do nothing` here means `do not return` then it fall back to `new SparkException(message)`



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285519367


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -47,11 +52,37 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
+  private val errorFactory = new ErrorFactoryBuilder()
+    .addConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))

Review Comment:
   How do we plan to pass other information here? like `start` and `stop`



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] amaliujia commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "amaliujia (via GitHub)" <gi...@apache.org>.
amaliujia commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1282378744


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -47,11 +52,37 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
+  private val errorFactory = new ErrorFactoryBuilder()
+    .addConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .addConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Throwable = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    for (cls <- classes) {
+      errorFactory.get(cls) match {
+        case Some(constructor) =>
+          return constructor(message, null)
+        case None =>
+        // Do nothing

Review Comment:
   oh so this happens when there is nothing found from errorFactory so do nothing here means do not return then it fall back to `new SparkException(message)`



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] heyihong commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1286014657


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -53,11 +60,33 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
-    val status = StatusProto.fromThrowable(ex)
-    // TODO: Add finer grained error conversion
-    new SparkException(status.getMessage, ex.getCause)
+  private val errorFactory = new ErrorFactoryBuilder()
+    .registerConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .registerConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Option[Throwable] = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    classes
+      .find(errorFactory.contains(_))
+      .map { cls =>
+        errorFactory.get(cls).get(message, null)

Review Comment:
   errorFactory.get(cls).get is a constructor. So it should not cause NPE if I understand correctly



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon closed pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation
URL: https://github.com/apache/spark/pull/42266


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] amaliujia commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "amaliujia (via GitHub)" <gi...@apache.org>.
amaliujia commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1282380443


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -47,11 +52,37 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
+  private val errorFactory = new ErrorFactoryBuilder()
+    .addConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .addConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Throwable = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    for (cls <- classes) {
+      errorFactory.get(cls) match {
+        case Some(constructor) =>
+          return constructor(message, null)
+        case None =>
+        // Do nothing

Review Comment:
   But per design it will return on the first found error factory. Why it must be an array but just a string? 



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285519805


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/ErrorFactoryBuilder.scala:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.spark.sql.connect.client
+
+import scala.collection.mutable
+import scala.reflect.ClassTag
+
+private[client] class ErrorFactoryBuilder() {
+
+  private val constructors = mutable.Map[String, (String, Throwable) => Throwable]()
+
+  def addConstructor[T <: Throwable: ClassTag](
+      throwableCtr: (String, Throwable) => T): ErrorFactoryBuilder = {

Review Comment:
   `(String, Throwable) => T`, what is `Throwable` for? Would be great if we can have some doc.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] heyihong commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285573500


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/ErrorFactoryBuilder.scala:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.spark.sql.connect.client
+
+import scala.collection.mutable
+import scala.reflect.ClassTag
+
+private[client] class ErrorFactoryBuilder() {

Review Comment:
   I implement the builder class for two reasons:
   1. Use addConstructor method to infer the class name of the exceptions when updating the map
   2. Use a builder class for extensions. There may be other places that need to register a couple of Exceptions. Having a builder class may such extensions easier.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285770067


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -53,11 +60,33 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
-    val status = StatusProto.fromThrowable(ex)
-    // TODO: Add finer grained error conversion
-    new SparkException(status.getMessage, ex.getCause)
+  private val errorFactory = new ErrorFactoryBuilder()
+    .registerConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .registerConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Option[Throwable] = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    classes
+      .find(errorFactory.contains(_))
+      .map { cls =>
+        errorFactory.get(cls).get(message, null)
+      }
   }
-}
 
+  private def toThrowable(ex: StatusRuntimeException): Throwable = {
+    val status = StatusProto.fromThrowable(ex)
 
+    status
+      .getDetailsList
+      .asScala
+      .find(_.is(classOf[ErrorInfo]))
+      .flatMap { d =>

Review Comment:
   I would cut this monadic chaining (see also https://github.com/databricks/scala-style-guide#chaining).



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] heyihong commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1286014657


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -53,11 +60,33 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
-    val status = StatusProto.fromThrowable(ex)
-    // TODO: Add finer grained error conversion
-    new SparkException(status.getMessage, ex.getCause)
+  private val errorFactory = new ErrorFactoryBuilder()
+    .registerConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .registerConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Option[Throwable] = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    classes
+      .find(errorFactory.contains(_))
+      .map { cls =>
+        errorFactory.get(cls).get(message, null)

Review Comment:
   errorFactory.contains(cls) should be true if find(...) return Some(cls). So errorFactory.get(cls) should not be Some(...)



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285762484


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -53,11 +60,33 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
-    val status = StatusProto.fromThrowable(ex)
-    // TODO: Add finer grained error conversion
-    new SparkException(status.getMessage, ex.getCause)
+  private val errorFactory = new ErrorFactoryBuilder()
+    .registerConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .registerConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Option[Throwable] = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    classes
+      .find(errorFactory.contains(_))
+      .map { cls =>
+        errorFactory.get(cls).get(message, null)

Review Comment:
   hm, I think this results in `Some(null)` instead of `None`, and later it will cause NPE I believe?



##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -53,11 +60,33 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
-    val status = StatusProto.fromThrowable(ex)
-    // TODO: Add finer grained error conversion
-    new SparkException(status.getMessage, ex.getCause)
+  private val errorFactory = new ErrorFactoryBuilder()
+    .registerConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .registerConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Option[Throwable] = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    classes
+      .find(errorFactory.contains(_))

Review Comment:
   ```suggestion
         .find(errorFactory.contains)
   ```



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285522223


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/ErrorFactoryBuilder.scala:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.spark.sql.connect.client
+
+import scala.collection.mutable
+import scala.reflect.ClassTag
+
+private[client] class ErrorFactoryBuilder() {

Review Comment:
   TBH, it seems a bit overcomplicated. It's just a map of string <> exception, and you get the exception from the map. If we want something more fancy, I am okay with keeping this. Otherwise, I would just make it simple.



##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/ErrorFactoryBuilder.scala:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.spark.sql.connect.client
+
+import scala.collection.mutable
+import scala.reflect.ClassTag
+
+private[client] class ErrorFactoryBuilder() {

Review Comment:
   ```suggestion
   private[client] class ErrorFactoryBuilder {
   ```



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285775955


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/ErrorFactoryBuilder.scala:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+package org.apache.spark.sql.connect.client
+
+import scala.collection.mutable
+import scala.reflect.ClassTag
+
+private[client] class ErrorFactoryBuilder {
+
+  private val constructors = mutable.Map.empty[String, (String, Throwable) => Throwable]
+
+  /**
+   * registerConstructors register throwableCtr in ErrorFactoryBuilder.
+   * @param throwableCtr the constructor that construct Throwable based on message and cause.
+   * @return this
+   */
+  def registerConstructor[T <: Throwable: ClassTag](

Review Comment:
   Can we just move this function into `GrpcExceptionConverter`, and just use a map? One example is `FunctionRegistry.expressions`. I really don't think this will be reused somewhere, and we can factor it out if it's going to be reused in the future.
   
   If you have a plan to improve it very soon and you believe this class will be more complicated/reused, I am fine. If not for now, I wouldn't make it as a separate class for now.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] heyihong commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1282903796


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -47,11 +52,37 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
+  private val errorFactory = new ErrorFactoryBuilder()
+    .addConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .addConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Throwable = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    for (cls <- classes) {
+      errorFactory.get(cls) match {
+        case Some(constructor) =>
+          return constructor(message, null)
+        case None =>
+        // Do nothing

Review Comment:
   Because the classes included both the class name and all its parental class names of an exception.  It is possible that the exact match does not happen.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] amaliujia commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "amaliujia (via GitHub)" <gi...@apache.org>.
amaliujia commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1283472402


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -47,11 +52,37 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
+  private val errorFactory = new ErrorFactoryBuilder()
+    .addConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .addConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Throwable = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    for (cls <- classes) {
+      errorFactory.get(cls) match {
+        case Some(constructor) =>
+          return constructor(message, null)
+        case None =>
+        // Do nothing

Review Comment:
   hmmm I see. Sure should work for now.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] heyihong commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1282395373


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -47,11 +52,37 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
+  private val errorFactory = new ErrorFactoryBuilder()
+    .addConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .addConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Throwable = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    for (cls <- classes) {
+      errorFactory.get(cls) match {
+        case Some(constructor) =>
+          return constructor(message, null)
+        case None =>
+        // Do nothing

Review Comment:
   Could you elaborate a little bit on the question? I am not sure if I get it



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] heyihong commented on a diff in pull request #42266: [SPARK-44575][SQL][CONNECT] Implement basic error translation

Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1282395373


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -47,11 +52,37 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = {
+  private val errorFactory = new ErrorFactoryBuilder()
+    .addConstructor((message, _) => new ParseException(None, message, Origin(), Origin()))
+    .addConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): Throwable = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), classOf[Array[String]])
+
+    for (cls <- classes) {
+      errorFactory.get(cls) match {
+        case Some(constructor) =>
+          return constructor(message, null)
+        case None =>
+        // Do nothing

Review Comment:
   Could you elaborate a little bit on the question?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org