LuciferYang commented on code in PR #60549:
URL: https://github.com/apache/spark/pull/60549#discussion_r4631256386
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala:
##########
@@ -856,9 +857,17 @@ case class Cast(
}
override def contextIndependentFoldable: Boolean = {
- child.contextIndependentFoldable && !Cast.needsTimeZone(child.dataType,
dataType)
+ child.contextIndependentFoldable && !Cast.needsTimeZone(child.dataType,
dataType) &&
+ !castsSpecialDatetimeValue
}
+ /**
+ * Whether this casts a special value such as 'today' or 'epoch', which
`SpecialDatetimeValues`
+ * replaces with its value. Evaluating the cast does not give that value.
+ */
+ private[sql] def castsSpecialDatetimeValue: Boolean =
SpecialDatetimeValues.rewrites(dataType) &&
+
SpecialDatetimeValues.constantString(this).exists(SpecialDatetimeValues.replaces(_,
dataType))
Review Comment:
I added `SpecialDatetimeValues.specialValueOf`, which the `lazy val` calls,
and `castReadsCurrentDate` reads the `lazy val` too. For a cast to
TIMESTAMP_LTZ it still evaluates the string separately, to find a time-only
string, which is not a special value.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala:
##########
@@ -172,6 +172,8 @@ class V2ExpressionBuilder(e: Expression, isPredicate:
Boolean = false) extends L
} else {
None
}
+ // Like `current_date()`, such a cast has no V2 form, so that the SQL text
is read instead.
Review Comment:
I rewrote the comment along with [1]: "Only `SpecialDatetimeValues` gives
such a cast its value. 'epoch' becomes its fixed value, and the others have no
V2 form, like `current_date()`."
--
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]