stevomitric commented on code in PR #59243:
URL: https://github.com/apache/spark/pull/59243#discussion_r4295466347


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala:
##########
@@ -3294,6 +3294,26 @@ case class ParseToTimestamp(
     ) +: format.map(_ => StringTypeWithCollation(supportsTrimCollation = 
true)).toSeq
   }
 
+  override def checkInputDataTypes(): TypeCheckResult = 
super.checkInputDataTypes() match {

Review Comment:
   Nice catch on this - i'm assuming we'll have the same bug on any 
`RuntimeReplaceable` whose wrapper accepts more types then its replacement - 
are there any other instances?



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala:
##########
@@ -3294,6 +3294,26 @@ case class ParseToTimestamp(
     ) +: format.map(_ => StringTypeWithCollation(supportsTrimCollation = 
true)).toSeq
   }
 
+  override def checkInputDataTypes(): TypeCheckResult = 
super.checkInputDataTypes() match {
+    // NumericType is only valid on the no-format path, where `replacement` is 
a plain Cast. With
+    // a format, `replacement` is GetTimestamp, which does not accept numeric 
inputs. Reject it
+    // here so the user gets a DATATYPE_MISMATCH instead of an INTERNAL_ERROR 
about an unresolved
+    // replacement.
+    case TypeCheckSuccess if format.isDefined && 
left.dataType.isInstanceOf[NumericType] =>
+      DataTypeMismatch(
+        errorSubClass = "UNEXPECTED_INPUT_TYPE",
+        messageParameters = Map(
+          "paramIndex" -> ordinalNumber(0),
+          "requiredType" -> Seq(
+            StringTypeWithCollation(supportsTrimCollation = true),
+            DateType,
+            TimestampType,
+            TimestampNTZType).map(toSQLType).mkString(" or "),

Review Comment:
   Do we need timestamp nano here?



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