You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/08/23 02:20:15 UTC

[GitHub] [spark] vitaliili-db opened a new pull request, #37621: [SPARK-40185] Remove column suggestion when the candidate list is empty

vitaliili-db opened a new pull request, #37621:
URL: https://github.com/apache/spark/pull/37621

   <!--
   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.
   -->
   Remove column, attribute or map key suggestion from `UNRESOLVED_*` error if candidate list is empty.
   
   ### 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.
   -->
   When the list of candidates is empty the error message looks incomplete:
   
   `[UNRESOLVED_COLUMN] A column or function parameter with name 'YrMo' cannot be resolved. Did you mean one of the following? []`
   
   This PR is to remove last part of error message:
   
   `[UNRESOLVED_COLUMN] A column or function parameter with name 'YrMo' cannot be resolved.`
   
   ### 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.
   -->
   Unit test


-- 
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] cloud-fan commented on a diff in pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #37621:
URL: https://github.com/apache/spark/pull/37621#discussion_r963268208


##########
core/src/main/resources/error/error-classes.json:
##########
@@ -415,20 +415,56 @@
   },
   "UNRESOLVED_COLUMN" : {
     "message" : [
-      "A column or function parameter with name <objectName> cannot be resolved. Did you mean one of the following? [<objectList>]"
+      "A column or function parameter with name <objectName> cannot be resolved."
     ],
+    "subClass" : {
+      "GENERIC" : {

Review Comment:
   shall we simply add a new error class like `UNRESOLVED_COLUMN_WITH_NO_INPUT_COLUMNS`?



-- 
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] srielau commented on pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
srielau commented on PR #37621:
URL: https://github.com/apache/spark/pull/37621#issuecomment-1237685203

   I guess I prefer the subclass over that.
   
   Sent from my iPhone
   
   On Sep 5, 2022, at 10:33 PM, Wenchen Fan ***@***.***> wrote:
   
   
   
   @cloud-fan commented on this pull request.
   
   ________________________________
   
   In core/src/main/resources/error/error-classes.json<https://github.com/apache/spark/pull/37621#discussion_r963268208>:
   
   >      ],
   +    "subClass" : {
   +      "GENERIC" : {
   
   
   shall we simply add a new error class like UNRESOLVED_COLUMN_WITH_NO_INPUT_COLUMNS?
   
   —
   Reply to this email directly, view it on GitHub<https://github.com/apache/spark/pull/37621#discussion_r963268208>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AA22CFBHHU25NBJMNVWF4OLV43JSTANCNFSM57JXCLFQ>.
   You are receiving this because you were mentioned.Message ID: ***@***.***>
   


-- 
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] MaxGekk commented on a diff in pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on code in PR #37621:
URL: https://github.com/apache/spark/pull/37621#discussion_r955101102


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala:
##########
@@ -164,35 +164,52 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase {
         s"side of the join. The $side-side columns: [${plan.output.map(_.name).mkString(", ")}]")
   }
 
+  private def unresolvedAttributeSuggestion(errorClass: String, candidates: Seq[String]): String = {
+    if (candidates.isEmpty) {
+      ""
+    } else {
+      val candidateIds = candidates.map(toSQLId).mkString(", ")
+      if (errorClass == "UNRESOLVED_MAP_KEY") {
+        s" Otherwise did you mean one of the following column(s)? [$candidateIds]"

Review Comment:
   Could you imagine that we will translate error messages in error-classes.json to local languages. It would be better if we put the text of error message to the json file, and parametrise it by some values that don't require translation.
   
   Is it possible to create sub-classes w/ suggestions in the json file?



-- 
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] vitaliili-db commented on a diff in pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
vitaliili-db commented on code in PR #37621:
URL: https://github.com/apache/spark/pull/37621#discussion_r964078276


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala:
##########
@@ -107,7 +107,7 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog {
       errorClass: String): Nothing = {
     val missingCol = a.sql
     val candidates = operator.inputSet.toSeq.map(_.qualifiedName)
-    val orderedCandidates = StringUtils.orderStringsBySimilarity(missingCol, candidates)
+    val orderedCandidates = StringUtils.orderStringsBySimilarity(missingCol, candidates).take(5)

Review Comment:
   done



-- 
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] vitaliili-db commented on pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
vitaliili-db commented on PR #37621:
URL: https://github.com/apache/spark/pull/37621#issuecomment-1224902237

   @MaxGekk @gengliangwang ptal.


-- 
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] MaxGekk commented on a diff in pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on code in PR #37621:
URL: https://github.com/apache/spark/pull/37621#discussion_r962255122


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala:
##########
@@ -178,7 +178,10 @@ object Project {
           createNewColumn(columnExpr, f.name, f.metadata, Metadata.empty)
         } else {
           if (columnPath.isEmpty) {
-            throw QueryCompilationErrors.unresolvedColumnError(f.name, fields.map(_._1))
+            val candidates = fields.map(_._1)
+            val orderedCandidates =
+              StringUtils.orderStringsBySimilarity(f.name, candidates).take(5)

Review Comment:
   Let's move `.take(5)` to `unresolvedColumnError`



##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala:
##########
@@ -117,8 +117,18 @@ class AnalysisErrorSuite extends AnalysisTest {
       plan: LogicalPlan,
       errorClass: String,
       messageParameters: Array[String]): Unit = {
+    errorClassTest(name, plan, errorClass, null, messageParameters)
+  }
+
+  def errorClassTest(
+    name: String,
+    plan: LogicalPlan,
+    errorClass: String,
+    errorSubClass: String,
+    messageParameters: Array[String]): Unit = {

Review Comment:
   wrong indentation, see https://github.com/databricks/scala-style-guide#spacing-and-indentation



##########
sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala:
##########
@@ -322,19 +322,27 @@ class DatasetSuite extends QueryTest
     val ds = Seq(("a", 1), ("b", 2), ("c", 3)).toDS()
 
     withSQLConf(SQLConf.SUPPORT_QUOTED_REGEX_COLUMN_NAME.key -> "false") {
-      var e = intercept[AnalysisException] {
-        ds.select(expr("`(_1)?+.+`").as[Int])
-      }
-      assert(e.getErrorClass == "UNRESOLVED_COLUMN")
-      assert(e.messageParameters.head == "`(_1)?+.+`")
-
-      e = intercept[AnalysisException] {
-        ds.select(expr("`(_1|_2)`").as[Int])
-      }
-      assert(e.getErrorClass == "UNRESOLVED_COLUMN")
-      assert(e.messageParameters.head == "`(_1|_2)`")
+      checkError(
+        exception = intercept[AnalysisException] {
+          ds.select(expr("`(_1)?+.+`").as[Int])
+        },
+        errorClass = "UNRESOLVED_COLUMN",
+        errorSubClass = Some("WITH_SUGGESTION"),
+        parameters = Map(
+          "objectName" -> "`(_1)?+.+`",
+          "proposal" -> "`_1`, `_2`"))
+
+      checkError(
+        exception = intercept[AnalysisException] {
+          ds.select(expr("`(_1|_2)`").as[Int])
+        },
+        errorClass = "UNRESOLVED_COLUMN",
+        errorSubClass = Some("WITH_SUGGESTION"),
+        parameters = Map(
+          "objectName" -> "`(_1|_2)`",
+          "proposal" -> "`_1`, `_2`"))
 
-      e = intercept[AnalysisException] {
+      var e = intercept[AnalysisException] {

Review Comment:
   Can't you invoke `checkError` too?



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala:
##########
@@ -107,7 +107,7 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog {
       errorClass: String): Nothing = {
     val missingCol = a.sql
     val candidates = operator.inputSet.toSeq.map(_.qualifiedName)
-    val orderedCandidates = StringUtils.orderStringsBySimilarity(missingCol, candidates)
+    val orderedCandidates = StringUtils.orderStringsBySimilarity(missingCol, candidates).take(5)

Review Comment:
   I would prefer to restrict the size in one place inside of `unresolvedAttributeError()`



##########
core/src/main/resources/error/error-classes.json:
##########
@@ -415,20 +415,56 @@
   },
   "UNRESOLVED_COLUMN" : {
     "message" : [
-      "A column or function parameter with name <objectName> cannot be resolved. Did you mean one of the following? [<objectList>]"
+      "A column or function parameter with name <objectName> cannot be resolved."
     ],
+    "subClass" : {
+      "GENERIC" : {

Review Comment:
   @cloud-fan @srielau Are you ok with such approach?



-- 
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] cloud-fan commented on pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on PR #37621:
URL: https://github.com/apache/spark/pull/37621#issuecomment-1239287981

   thanks, merging to master!


-- 
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] vitaliili-db commented on pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
vitaliili-db commented on PR #37621:
URL: https://github.com/apache/spark/pull/37621#issuecomment-1233579923

   @MaxGekk friendly ping.


-- 
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] vitaliili-db commented on pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
vitaliili-db commented on PR #37621:
URL: https://github.com/apache/spark/pull/37621#issuecomment-1235781990

   @cloud-fan ptal


-- 
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] vitaliili-db commented on a diff in pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
vitaliili-db commented on code in PR #37621:
URL: https://github.com/apache/spark/pull/37621#discussion_r956453516


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala:
##########
@@ -164,35 +164,52 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase {
         s"side of the join. The $side-side columns: [${plan.output.map(_.name).mkString(", ")}]")
   }
 
+  private def unresolvedAttributeSuggestion(errorClass: String, candidates: Seq[String]): String = {
+    if (candidates.isEmpty) {
+      ""
+    } else {
+      val candidateIds = candidates.map(toSQLId).mkString(", ")
+      if (errorClass == "UNRESOLVED_MAP_KEY") {
+        s" Otherwise did you mean one of the following column(s)? [$candidateIds]"

Review Comment:
   That is such a great comment! Thank you, I added sub classes for respective errors. We also have some other instances of hard coded strings, I created a ticket ([SPARK-40236](https://issues.apache.org/jira/browse/SPARK-40236)) and fix those.



-- 
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] cloud-fan commented on a diff in pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #37621:
URL: https://github.com/apache/spark/pull/37621#discussion_r963291886


##########
core/src/main/resources/error/error-classes.json:
##########
@@ -415,20 +415,56 @@
   },
   "UNRESOLVED_COLUMN" : {
     "message" : [
-      "A column or function parameter with name <objectName> cannot be resolved. Did you mean one of the following? [<objectList>]"
+      "A column or function parameter with name <objectName> cannot be resolved."
     ],
+    "subClass" : {
+      "GENERIC" : {

Review Comment:
   If we prefer sub error class, `WITHOUT_SUGGESTION` and `WITH_SUGGESTION` LGTM



-- 
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] romainr commented on pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
romainr commented on PR #37621:
URL: https://github.com/apache/spark/pull/37621#issuecomment-1224971894

   👍 for the capping and avoiding suggesting an empty list!


-- 
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] cloud-fan closed pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty
URL: https://github.com/apache/spark/pull/37621


-- 
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] AmplabJenkins commented on pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on PR #37621:
URL: https://github.com/apache/spark/pull/37621#issuecomment-1224372423

   Can one of the admins verify this patch?


-- 
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] srielau commented on a diff in pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
srielau commented on code in PR #37621:
URL: https://github.com/apache/spark/pull/37621#discussion_r962392376


##########
core/src/main/resources/error/error-classes.json:
##########
@@ -415,20 +415,56 @@
   },
   "UNRESOLVED_COLUMN" : {
     "message" : [
-      "A column or function parameter with name <objectName> cannot be resolved. Did you mean one of the following? [<objectList>]"
+      "A column or function parameter with name <objectName> cannot be resolved."
     ],
+    "subClass" : {
+      "GENERIC" : {

Review Comment:
   Well, right now a sub error class spawns a separate doc page. So we are introducing complexity into the tooling. If we want to suppress this (?)
   That being said I do not understand why we can't put in some palace holder like <none> or <empty> or <null>?
   But if you like this one how about WITHOUT_SUGGESTION



-- 
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] vitaliili-db commented on a diff in pull request #37621: [SPARK-40185][SQL] Remove column suggestion when the candidate list is empty

Posted by GitBox <gi...@apache.org>.
vitaliili-db commented on code in PR #37621:
URL: https://github.com/apache/spark/pull/37621#discussion_r964077280


##########
core/src/main/resources/error/error-classes.json:
##########
@@ -415,20 +415,56 @@
   },
   "UNRESOLVED_COLUMN" : {
     "message" : [
-      "A column or function parameter with name <objectName> cannot be resolved. Did you mean one of the following? [<objectList>]"
+      "A column or function parameter with name <objectName> cannot be resolved."
     ],
+    "subClass" : {
+      "GENERIC" : {

Review Comment:
   Renamed.



##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala:
##########
@@ -117,8 +117,18 @@ class AnalysisErrorSuite extends AnalysisTest {
       plan: LogicalPlan,
       errorClass: String,
       messageParameters: Array[String]): Unit = {
+    errorClassTest(name, plan, errorClass, null, messageParameters)
+  }
+
+  def errorClassTest(
+    name: String,
+    plan: LogicalPlan,
+    errorClass: String,
+    errorSubClass: String,
+    messageParameters: Array[String]): Unit = {

Review Comment:
   Done, thank you



##########
sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala:
##########
@@ -322,19 +322,27 @@ class DatasetSuite extends QueryTest
     val ds = Seq(("a", 1), ("b", 2), ("c", 3)).toDS()
 
     withSQLConf(SQLConf.SUPPORT_QUOTED_REGEX_COLUMN_NAME.key -> "false") {
-      var e = intercept[AnalysisException] {
-        ds.select(expr("`(_1)?+.+`").as[Int])
-      }
-      assert(e.getErrorClass == "UNRESOLVED_COLUMN")
-      assert(e.messageParameters.head == "`(_1)?+.+`")
-
-      e = intercept[AnalysisException] {
-        ds.select(expr("`(_1|_2)`").as[Int])
-      }
-      assert(e.getErrorClass == "UNRESOLVED_COLUMN")
-      assert(e.messageParameters.head == "`(_1|_2)`")
+      checkError(
+        exception = intercept[AnalysisException] {
+          ds.select(expr("`(_1)?+.+`").as[Int])
+        },
+        errorClass = "UNRESOLVED_COLUMN",
+        errorSubClass = Some("WITH_SUGGESTION"),
+        parameters = Map(
+          "objectName" -> "`(_1)?+.+`",
+          "proposal" -> "`_1`, `_2`"))
+
+      checkError(
+        exception = intercept[AnalysisException] {
+          ds.select(expr("`(_1|_2)`").as[Int])
+        },
+        errorClass = "UNRESOLVED_COLUMN",
+        errorSubClass = Some("WITH_SUGGESTION"),
+        parameters = Map(
+          "objectName" -> "`(_1|_2)`",
+          "proposal" -> "`_1`, `_2`"))
 
-      e = intercept[AnalysisException] {
+      var e = intercept[AnalysisException] {

Review Comment:
   This error is hard coded, does not have error class yet.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala:
##########
@@ -178,7 +178,10 @@ object Project {
           createNewColumn(columnExpr, f.name, f.metadata, Metadata.empty)
         } else {
           if (columnPath.isEmpty) {
-            throw QueryCompilationErrors.unresolvedColumnError(f.name, fields.map(_._1))
+            val candidates = fields.map(_._1)
+            val orderedCandidates =
+              StringUtils.orderStringsBySimilarity(f.name, candidates).take(5)

Review Comment:
   Done



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