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

[GitHub] [spark] Leibnizhu opened a new pull request, #40634: [SPARK-42840][SQL] Rename the error class _LEGACY_ERROR_TEMP_2004 to NO_DEFAULT_FOR_DATA_TYPE

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

   <!--
   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.
   -->
   
   In the PR, I propose to assign the proper name `NO_DEFAULT_FOR_DATA_TYPE`  to the legacy error class `_LEGACY_ERROR_TEMP_2004` , and modify test suite to use checkError() which checks the error class name, context and etc. Also this PR improves the error message.
   
   
   ### 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.
   -->
   Proper name improves user experience Spark SQL.
   
   ### 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'.
   -->
   Yes, the PR changes an user-facing error message.
   
   ### 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.
   -->
   By running the modified test suites:
   
   ```bash
    build/sbt "sql/testOnly org.apache.spark.sql.catalyst.expressions.LiteralExpressionSuite"
   ```
   
   this exception is thrown in `Literal.default`, but i can't find a real case to trigger it, so i wrote only unit test.
   
   `Literal.default` throw this exception for `CharType`, `VarcharType` and other user-defined DataType.
   
   `Literal.default` is called in these cases below:
   
   1. in `org.apache.spark.sql.catalyst.expressions.aggregate.Average`, for getting initial value; but in this case, DataType would only be  DecimalType / YearMonthIntervalType / DayTimeIntervalType / DoubleType; these types are supported by `Literal.default`.
   2. in `org.apache.spark.sql.catalyst.expressions.aggregate.Sum`, is same as `Average`
   3. in `org.apache.spark.sql.catalyst.planning.ExtractEquiJoinKeys` and `org.apache.spark.sql.catalyst.plans.logical.AsOfJoin`; In real scene, they are use for DateFrame api, but `CharType` and `VarcharType` cannot be as a part of DataFrame's schema( they would be converted to StringType); and user-defined DataType do not have a matched Encoder in `org.apache.spark.sql.catalyst.encoders.RowEncoder#encoderForDataType`


-- 
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] Leibnizhu commented on pull request #40634: [SPARK-42840][SQL] Change `_LEGACY_ERROR_TEMP_2004` error to internal error

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

   > @Leibnizhu Could you fix PR's description and title according to your actual changes, please.
   
   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] MaxGekk commented on a diff in pull request #40634: [SPARK-42840][SQL] Rename the error class _LEGACY_ERROR_TEMP_2004 to NO_DEFAULT_FOR_DATA_TYPE

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


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/LiteralExpressionSuite.scala:
##########
@@ -88,6 +88,17 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
     checkEvaluation(Literal.default(StructType(StructField("a", StringType) :: Nil)), Row(""))
     // ExamplePointUDT.sqlType is ArrayType(DoubleType, false).
     checkEvaluation(Literal.default(new ExamplePointUDT), Array())
+
+    // DateType without default value`
+    List(CharType(1), VarcharType(1)).foreach(errType => {
+      checkError(
+        exception = intercept[SparkRuntimeException] {
+          Literal.default(errType)

Review Comment:
   Can you trigger the error from user code, for instance, some SQL query? If not, we should convert this error to an internal error `SparkException.internalError()`.



-- 
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 closed pull request #40634: [SPARK-42840][SQL] Change `_LEGACY_ERROR_TEMP_2004` error to internal error

Posted by "MaxGekk (via GitHub)" <gi...@apache.org>.
MaxGekk closed pull request #40634: [SPARK-42840][SQL] Change `_LEGACY_ERROR_TEMP_2004` error to internal error 
URL: https://github.com/apache/spark/pull/40634


-- 
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] Leibnizhu commented on pull request #40634: [SPARK-42840][SQL] Change `_LEGACY_ERROR_TEMP_2004` error to internal error

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

   > @Leibnizhu Congratulations with your first contribution to Apache Spark!
   
   thx 😁😁😁


-- 
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] Leibnizhu commented on a diff in pull request #40634: [SPARK-42840][SQL] Rename the error class _LEGACY_ERROR_TEMP_2004 to NO_DEFAULT_FOR_DATA_TYPE

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


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/LiteralExpressionSuite.scala:
##########
@@ -88,6 +88,17 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
     checkEvaluation(Literal.default(StructType(StructField("a", StringType) :: Nil)), Row(""))
     // ExamplePointUDT.sqlType is ArrayType(DoubleType, false).
     checkEvaluation(Literal.default(new ExamplePointUDT), Array())
+
+    // DateType without default value`
+    List(CharType(1), VarcharType(1)).foreach(errType => {
+      checkError(
+        exception = intercept[SparkRuntimeException] {
+          Literal.default(errType)

Review Comment:
   fixed



##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/LiteralExpressionSuite.scala:
##########
@@ -88,6 +88,17 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
     checkEvaluation(Literal.default(StructType(StructField("a", StringType) :: Nil)), Row(""))
     // ExamplePointUDT.sqlType is ArrayType(DoubleType, false).
     checkEvaluation(Literal.default(new ExamplePointUDT), Array())
+
+    // DateType without default value`
+    List(CharType(1), VarcharType(1)).foreach(errType => {
+      checkError(
+        exception = intercept[SparkRuntimeException] {
+          Literal.default(errType)

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] MaxGekk commented on a diff in pull request #40634: [SPARK-42840][SQL] Rename the error class _LEGACY_ERROR_TEMP_2004 to NO_DEFAULT_FOR_DATA_TYPE

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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala:
##########
@@ -339,10 +339,11 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase {
         "type" ->  toSQLType(dataType)))
   }
 
-  def noDefaultForDataTypeError(dataType: DataType): SparkRuntimeException = {
-    new SparkRuntimeException(
-      errorClass = "_LEGACY_ERROR_TEMP_2004",
+  def noDefaultForDataTypeError(dataType: DataType): SparkException = {
+    val errorMessage = SparkThrowableHelper.getMessage(
+      errorClass = "NO_DEFAULT_FOR_DATA_TYPE",
       messageParameters = Map("dataType" -> dataType.toString()))

Review Comment:
   Could you wrap `dataType` by `toSQLType()`, please.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala:
##########
@@ -339,10 +339,11 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase {
         "type" ->  toSQLType(dataType)))
   }
 
-  def noDefaultForDataTypeError(dataType: DataType): SparkRuntimeException = {
-    new SparkRuntimeException(
-      errorClass = "_LEGACY_ERROR_TEMP_2004",
+  def noDefaultForDataTypeError(dataType: DataType): SparkException = {
+    val errorMessage = SparkThrowableHelper.getMessage(

Review Comment:
   Just form the error message directly from `"No default value for type: <dataType>."` using interpolation.



##########
core/src/main/resources/error/error-classes.json:
##########
@@ -1190,6 +1190,11 @@
     },
     "sqlState" : "42000"
   },
+  "NO_DEFAULT_FOR_DATA_TYPE" : {

Review Comment:
   Please, remove the error class. We introduce error classes only for user-facing errors.



-- 
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 pull request #40634: [SPARK-42840][SQL] Change `_LEGACY_ERROR_TEMP_2004` error to internal error

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

   +1, LGTM. Merging to master.
   Thank you, @Leibnizhu.


-- 
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] Leibnizhu commented on a diff in pull request #40634: [SPARK-42840][SQL] Rename the error class _LEGACY_ERROR_TEMP_2004 to NO_DEFAULT_FOR_DATA_TYPE

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


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/LiteralExpressionSuite.scala:
##########
@@ -88,6 +88,17 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
     checkEvaluation(Literal.default(StructType(StructField("a", StringType) :: Nil)), Row(""))
     // ExamplePointUDT.sqlType is ArrayType(DoubleType, false).
     checkEvaluation(Literal.default(new ExamplePointUDT), Array())
+
+    // DateType without default value`
+    List(CharType(1), VarcharType(1)).foreach(errType => {
+      checkError(
+        exception = intercept[SparkRuntimeException] {
+          Literal.default(errType)

Review Comment:
   no. 
   
   As analyzed in the this PR's description, if user defines a DataType which is not supported in `Literal.default`, then this DataType does not have a matched Encoder in `RowEncoder#encoderForDataType` (related to SPARK-41993 ), and his code doesn't work.
   
   I will change the exception to `SparkException.internalError()`



-- 
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 pull request #40634: [SPARK-42840][SQL] Change `_LEGACY_ERROR_TEMP_2004` error to internal error

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

   @Leibnizhu Congratulations with your first contribution to Apache Spark!


-- 
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] Leibnizhu commented on pull request #40634: [SPARK-42840][SQL] Rename the error class _LEGACY_ERROR_TEMP_2004 to NO_DEFAULT_FOR_DATA_TYPE

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

   @MaxGekk Plz review this PR, thx


-- 
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] Leibnizhu commented on a diff in pull request #40634: [SPARK-42840][SQL] Rename the error class _LEGACY_ERROR_TEMP_2004 to NO_DEFAULT_FOR_DATA_TYPE

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


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/LiteralExpressionSuite.scala:
##########
@@ -88,6 +88,17 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
     checkEvaluation(Literal.default(StructType(StructField("a", StringType) :: Nil)), Row(""))
     // ExamplePointUDT.sqlType is ArrayType(DoubleType, false).
     checkEvaluation(Literal.default(new ExamplePointUDT), Array())
+
+    // DateType without default value`
+    List(CharType(1), VarcharType(1)).foreach(errType => {
+      checkError(
+        exception = intercept[SparkRuntimeException] {
+          Literal.default(errType)

Review Comment:
   no. 
   
   As analyzed in the this PR's description, if user defines a DataType which is not supported in `Literal.default`, then this DataType does not have a matched Encoder in `RowEncoder#encoderForDataType`, and his code doesn't work.
   
   I will change the exception to `SparkException.internalError()`



-- 
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 pull request #40634: [SPARK-42840][SQL] Rename the error class _LEGACY_ERROR_TEMP_2004 to NO_DEFAULT_FOR_DATA_TYPE

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

   @Leibnizhu Could you fix PR's description and title according to your actual changes, please.


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