dongjoon-hyun commented on code in PR #60394:
URL: https://github.com/apache/spark/pull/60394#discussion_r4554662550


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ExprUtils.scala:
##########
@@ -95,6 +97,23 @@ object ExprUtils extends EvalHelper with QueryErrorsBase {
       throw QueryCompilationErrors.nonMapFunctionNotAllowedError()
   }
 
+  /**
+   * Returns the value, possibly null, of a foldable expression, or None if 
the expression is not
+   * foldable or fails to evaluate. `ConstantFolding` keeps a foldable 
expression that fails to
+   * evaluate in a conditional branch, which no row may reach. An expression 
that uses the value
+   * of such a child once, e.g. in generated code, should evaluate the child 
for each row instead,
+   * so that the error is raised only when a row evaluates it, as in `eval`.
+   */
+  def tryEvalFoldable(exp: Expression): Option[Any] = if (exp.foldable) {

Review Comment:
   Thank you, @peter-toth. Right, `ToTime.replacement` evaluates a foldable 
format eagerly, so `to_time` fails in every mode, not only in code generation. 
I confirmed it on Apache Spark 4.3.0 with `spark.sql.timeType.enabled=true`. 
Since it is not a code generation issue, I'll file a new JIRA issue for it.
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to