sigmod commented on a change in pull request #33164:
URL: https://github.com/apache/spark/pull/33164#discussion_r661960275



##########
File path: core/src/test/java/org/apache/spark/SparkThrowableSuite.java
##########
@@ -0,0 +1,150 @@
+package org.apache.spark;

Review comment:
       copy right header?

##########
File path: core/src/main/java/org/apache/spark/SparkThrowable.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.SortedMap;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.lang3.StringUtils;
+
+import org.apache.spark.util.Utils;
+
+/**
+ * Interface mixed into Throwables thrown from Spark.
+ *
+ * - For backwards compatibility, existing throwable types can be thrown with 
an arbitrary error
+ *   message with no error class. See [[SparkException]].
+ * - To promote standardization, throwables should be thrown with an error 
class and message
+ *   parameters to construct an error message with 
SparkThrowableHelper.getMessage(). New throwable
+ *   types should not accept arbitrary error messages. See 
[[SparkArithmeticException]].
+ */
+public interface SparkThrowable {
+    String getErrorClass();

Review comment:
       Add comments for interface methods?

##########
File path: core/src/main/java/org/apache/spark/SparkThrowable.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.SortedMap;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.lang3.StringUtils;
+
+import org.apache.spark.util.Utils;
+
+/**
+ * Interface mixed into Throwables thrown from Spark.
+ *
+ * - For backwards compatibility, existing throwable types can be thrown with 
an arbitrary error
+ *   message with no error class. See [[SparkException]].
+ * - To promote standardization, throwables should be thrown with an error 
class and message
+ *   parameters to construct an error message with 
SparkThrowableHelper.getMessage(). New throwable
+ *   types should not accept arbitrary error messages. See 
[[SparkArithmeticException]].
+ */
+public interface SparkThrowable {
+    String getErrorClass();
+    String getSqlState();
+    String[] getMessageParameters();
+
+    class SparkThrowableHelper {

Review comment:
       Does it have to be an inner class?

##########
File path: core/src/main/java/org/apache/spark/SparkThrowable.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.SortedMap;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.lang3.StringUtils;
+
+import org.apache.spark.util.Utils;
+
+/**
+ * Interface mixed into Throwables thrown from Spark.
+ *
+ * - For backwards compatibility, existing throwable types can be thrown with 
an arbitrary error
+ *   message with no error class. See [[SparkException]].
+ * - To promote standardization, throwables should be thrown with an error 
class and message
+ *   parameters to construct an error message with 
SparkThrowableHelper.getMessage(). New throwable
+ *   types should not accept arbitrary error messages. See 
[[SparkArithmeticException]].
+ */
+public interface SparkThrowable {
+    String getErrorClass();
+    String getSqlState();
+    String[] getMessageParameters();
+
+    class SparkThrowableHelper {
+        protected final static URL errorClassesUrl =
+                
Utils.getSparkClassLoader().getResource("error/error-classes.json");
+
+        protected final static SortedMap<String, ErrorInfo> 
errorClassToInfoMap = getErrorClassToInfoMap();
+
+        public static String getMessage(String errorClass, String[] 
messageParameters) {
+            if (errorClass != null && 
errorClassToInfoMap.containsKey(errorClass)) {
+                ErrorInfo errorInfo = errorClassToInfoMap.get(errorClass);
+                return String.format(errorInfo.messageFormat, (Object[]) 
messageParameters);
+            }
+            throw new IllegalArgumentException(String.format("Cannot find 
error class '%s'", errorClass));
+        }
+
+        public static String getSqlState(String errorClass) {
+            if (errorClass != null && 
errorClassToInfoMap.containsKey(errorClass)) {
+                return errorClassToInfoMap.get(errorClass).sqlState;
+            }
+            return null;
+        }
+
+        static SortedMap<String, ErrorInfo> getErrorClassToInfoMap() {

Review comment:
       private?




-- 
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-unsubscr...@spark.apache.org

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



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

Reply via email to