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/11/20 07:31:25 UTC

[GitHub] [spark] MaxGekk commented on a diff in pull request #38727: [SPARK-41205][SQL] Check that format is foldable in `TryToBinary`

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


##########
sql/core/src/test/resources/sql-tests/results/ansi/string-functions.sql.out:
##########
@@ -1597,3 +1597,20 @@ org.apache.spark.sql.AnalysisException
     "invalidValue" : "invalidformat"
   }
 }
+
+
+-- !query
+SELECT to_binary(col1, col2) from values ('abc', 'utf-8') as data(col1, col2)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.AnalysisException
+The 'format' parameter of function 'to_binary' needs to be a string literal.; line 1 pos 7

Review Comment:
   When you move the exception from constructor, you should see `AnalysisException` w/ an error class.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/TryEval.scala:
##########
@@ -227,7 +228,8 @@ case class TryToBinary(
 
   def this(expr: Expression, formatExpression: Expression) =
     this(expr, Some(formatExpression),
-      TryEval(ToBinary(expr, Some(formatExpression), nullOnInvalidFormat = true)))
+      TryEval(ToBinary(expr, Some(TryToBinary.checkFormat(formatExpression)),

Review Comment:
   Could you perform the check in `checkInputDataTypes()` as we do that in other expression, please.
   
   BTW, exceptions from expressions constructors are wrapped by `AnalysisException` additionally which is not convenient to users.



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