shrirangmhalgi commented on code in PR #56999:
URL: https://github.com/apache/spark/pull/56999#discussion_r3523305883


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala:
##########
@@ -2631,15 +2631,37 @@ case class ParseToDate(
 
   override def children: Seq[Expression] = left +: format.toSeq
 
+  private def inputTypeForDate: AbstractDataType = {
+    TypeCollection(
+      StringTypeWithCollation(supportsTrimCollation = true),
+      DateType,
+      TimestampType,
+      TimestampNTZType)
+  }
+
   override def inputTypes: Seq[AbstractDataType] = {
     // Note: ideally this function should only take string input, but we allow 
more types here to
     // be backward compatible.
-    TypeCollection(
-      StringTypeWithCollation(supportsTrimCollation = true),
-        DateType,
-        TimestampType,
-        TimestampNTZType) +:
-      format.map(_ => StringTypeWithCollation(supportsTrimCollation = 
true)).toSeq
+    inputTypeForDate +: format.map(_ =>
+      StringTypeWithCollation(supportsTrimCollation = true)).toSeq
+  }
+
+  override def checkInputDataTypes(): TypeCheckResult = {
+    def timeInput(expression: Expression): Option[Expression] = expression 
match {
+      case Cast(child, _, _, _) if child.dataType.isInstanceOf[TimeType] => 
Some(child)

Review Comment:
   nit: With the coercion rules blocking implicit TIME -> Date/Timestamp, this 
`checkInputDataTypes` guard only fires for an explicit user-written 
`CAST(TIME'...' AS TIMESTAMP)` passed to `to_date`. Is blocking explicit casts 
intentional here? If a user deliberately writes `to_date(CAST(TIME'12:00:00' AS 
TIMESTAMP))`, they've already accepted the conversion -- rejecting it at the 
function level seems overly protective.
   
   If the intent is defense-in-depth for the implicit path only, consider 
checking `!child.resolved || child.origin.isGenerated` to distinguish 
user-written vs analyzer-inserted casts.



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