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

[GitHub] [spark] MaxGekk commented on a diff in pull request #42109: [SPARK-44404][SQL] Assign names to the error class _LEGACY_ERROR_TEMP_[1009,1010,1013,1015,1016,1278]

MaxGekk commented on code in PR #42109:
URL: https://github.com/apache/spark/pull/42109#discussion_r1281470846


##########
common/utils/src/main/resources/error/error-classes.json:
##########
@@ -3219,12 +3219,63 @@
     },
     "sqlState" : "0A000"
   },
+  "UNSUPPORTED_TABLE_OPERATION" : {
+    "message" : [
+      "Table <tableName> does not support <operation>."
+    ],
+    "subClass" : {
+      "WITHOUT_SUGGESTION" : {
+        "message" : [
+          ""
+        ]
+      },
+      "WITH_SUGGESTION" : {
+        "message" : [
+          "<suggestion>."
+        ]
+      }
+    }
+  },
+  "UNSUPPORTED_TEMP_VIEW_OPERATION" : {
+    "message" : [
+      "Temp view <tempViewName> does not support <operation>."

Review Comment:
   ```suggestion
         "The temp view <tempViewName> does not support <operation>."
   ```



##########
R/pkg/tests/fulltests/test_sparkSQL.R:
##########
@@ -4193,8 +4193,9 @@ test_that("catalog APIs, listTables, getTable, listColumns, listFunctions, funct
 
   # recoverPartitions does not work with temporary view
   expect_error(recoverPartitions("cars"),
-               paste("Error in recoverPartitions : analysis error - cars is a temp view.",
-                     "'recoverPartitions()' expects a table"), fixed = TRUE)
+               paste("Error in recoverPartitions : analysis error -",
+                     "[UNSUPPORTED_TEMP_VIEW_OPERATION.WITH_SUGGESTION]",
+                     "Temp view `cars` does not support recoverPartitions()"), fixed = TRUE)

Review Comment:
   Could you check the error class only. See other checks in the same file.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala:
##########
@@ -464,49 +465,57 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase {
       cmd: String,
       mismatchHint: Option[String],
       t: TreeNode[_]): Throwable = {
-    val viewStr = if (isTemp) "temp view" else "view"
-    val hintStr = mismatchHint.map(" " + _).getOrElse("")
-    new AnalysisException(
-      errorClass = "_LEGACY_ERROR_TEMP_1013",
-      messageParameters = Map(
-        "nameParts" -> nameParts.quoted,
-        "viewStr" -> viewStr,
-        "cmd" -> cmd,
-        "hintStr" -> hintStr),
-      origin = t.origin)
+    val suggestion = mismatchHint.map(" " + _).getOrElse("")
+    if (isTemp) {
+      new AnalysisException(
+        errorClass = "UNSUPPORTED_TEMP_VIEW_OPERATION.WITH_SUGGESTION",
+        messageParameters = Map(
+          "tempViewName" -> toSQLId(nameParts),
+          "operation" -> cmd,
+          "suggestion" -> suggestion),
+        origin = t.origin)
+    } else {
+      new AnalysisException(
+        errorClass = "UNSUPPORTED_VIEW_OPERATION.WITH_SUGGESTION",
+        messageParameters = Map(
+          "viewName" -> toSQLId(nameParts),
+          "operation" -> cmd,
+          "suggestion" -> suggestion),
+        origin = t.origin)
+    }
   }
 
   def expectViewNotTempViewError(
       nameParts: Seq[String],
       cmd: String,
       t: TreeNode[_]): Throwable = {
     new AnalysisException(
-      errorClass = "_LEGACY_ERROR_TEMP_1014",
+      errorClass = "UNSUPPORTED_TEMP_VIEW_OPERATION.WITHOUT_SUGGESTION",
       messageParameters = Map(
-        "nameParts" -> nameParts.quoted,
-        "cmd" -> cmd),
+        "tempViewName" -> toSQLId(nameParts),
+        "operation" -> cmd),
       origin = t.origin)
   }
 
   def expectViewNotTableError(
       v: ResolvedTable, cmd: String, mismatchHint: Option[String], t: TreeNode[_]): Throwable = {
-    val hintStr = mismatchHint.map(" " + _).getOrElse("")
+    val suggestion = mismatchHint.map(" " + _).getOrElse("")
     new AnalysisException(
-      errorClass = "_LEGACY_ERROR_TEMP_1015",
+      errorClass = "UNSUPPORTED_TABLE_OPERATION.WITH_SUGGESTION",
       messageParameters = Map(
-        "identifier" -> v.identifier.quoted,
-        "cmd" -> cmd,
-        "hintStr" -> hintStr),
+        "tableName" -> toSQLId(v.identifier.quoted),

Review Comment:
   `toSQLId` should perform quoting instead of `.quoted`? Doesn't it?



##########
common/utils/src/main/resources/error/error-classes.json:
##########
@@ -3219,12 +3219,63 @@
     },
     "sqlState" : "0A000"
   },
+  "UNSUPPORTED_TABLE_OPERATION" : {
+    "message" : [
+      "Table <tableName> does not support <operation>."
+    ],
+    "subClass" : {
+      "WITHOUT_SUGGESTION" : {
+        "message" : [
+          ""
+        ]
+      },
+      "WITH_SUGGESTION" : {
+        "message" : [
+          "<suggestion>."
+        ]
+      }
+    }
+  },
+  "UNSUPPORTED_TEMP_VIEW_OPERATION" : {
+    "message" : [
+      "Temp view <tempViewName> does not support <operation>."
+    ],
+    "subClass" : {
+      "WITHOUT_SUGGESTION" : {
+        "message" : [
+          ""
+        ]
+      },
+      "WITH_SUGGESTION" : {
+        "message" : [
+          "<suggestion>."
+        ]
+      }
+    }
+  },
   "UNSUPPORTED_TYPED_LITERAL" : {
     "message" : [
       "Literals of the type <unsupportedType> are not supported. Supported types are <supportedTypes>."
     ],
     "sqlState" : "0A000"
   },
+  "UNSUPPORTED_VIEW_OPERATION" : {
+    "message" : [
+      "View <viewName> does not support <operation>."

Review Comment:
   ```suggestion
         "The view <viewName> does not support <operation>."
   ```



##########
common/utils/src/main/resources/error/error-classes.json:
##########
@@ -3219,12 +3219,63 @@
     },
     "sqlState" : "0A000"
   },
+  "UNSUPPORTED_TABLE_OPERATION" : {
+    "message" : [
+      "Table <tableName> does not support <operation>."

Review Comment:
   ```suggestion
         "The table <tableName> does not support <operation>."
   ```



##########
common/utils/src/main/resources/error/error-classes.json:
##########
@@ -3219,12 +3219,63 @@
     },
     "sqlState" : "0A000"
   },
+  "UNSUPPORTED_TABLE_OPERATION" : {

Review Comment:
   Does this duplicate `UNSUPPORTED_FEATURE.TABLE_OPERATION`?



##########
common/utils/src/main/resources/error/error-classes.json:
##########
@@ -3219,12 +3219,63 @@
     },
     "sqlState" : "0A000"
   },
+  "UNSUPPORTED_TABLE_OPERATION" : {
+    "message" : [
+      "Table <tableName> does not support <operation>."
+    ],
+    "subClass" : {
+      "WITHOUT_SUGGESTION" : {
+        "message" : [
+          ""
+        ]
+      },
+      "WITH_SUGGESTION" : {
+        "message" : [
+          "<suggestion>."

Review Comment:
   Besides of the hits, how many others exist in the source code?
   ```scala
     private def alterViewTypeMismatchHint: Option[String] = Some("Please use ALTER TABLE instead.")
   
     private def alterTableTypeMismatchHint: Option[String] = Some("Please use ALTER VIEW instead.")
   ```
   
   Can you move the text to `error-classes.json`?



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