RunyaoChen commented on code in PR #39855:
URL: https://github.com/apache/spark/pull/39855#discussion_r1093823654
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala:
##########
@@ -2511,40 +2511,41 @@ case class UpCast(child: Expression, target:
AbstractDataType, walkedTypePath: S
*/
case class CheckOverflowInTableInsert(child: Expression, columnName: String)
extends UnaryExpression {
- checkChild(child)
-
- private def checkChild(child: Expression): Unit = child match {
- case _: Cast =>
- case ExpressionProxy(c, _, _) if c.isInstanceOf[Cast] =>
- case _ =>
- throw SparkException.internalError("Child is not Cast or ExpressionProxy
of Cast")
- }
override protected def withNewChildInternal(newChild: Expression):
Expression = {
- checkChild(newChild)
copy(child = newChild)
}
- private def getCast: Cast = child match {
+ private def getCast: Option[Cast] = child match {
case c: Cast =>
- c
+ Some(c)
case ExpressionProxy(c, _, _) =>
- c.asInstanceOf[Cast]
+ Some(c.asInstanceOf[Cast])
Review Comment:
Done.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala:
##########
@@ -2511,40 +2511,41 @@ case class UpCast(child: Expression, target:
AbstractDataType, walkedTypePath: S
*/
case class CheckOverflowInTableInsert(child: Expression, columnName: String)
extends UnaryExpression {
- checkChild(child)
-
- private def checkChild(child: Expression): Unit = child match {
- case _: Cast =>
- case ExpressionProxy(c, _, _) if c.isInstanceOf[Cast] =>
- case _ =>
- throw SparkException.internalError("Child is not Cast or ExpressionProxy
of Cast")
- }
override protected def withNewChildInternal(newChild: Expression):
Expression = {
- checkChild(newChild)
copy(child = newChild)
}
- private def getCast: Cast = child match {
+ private def getCast: Option[Cast] = child match {
case c: Cast =>
- c
+ Some(c)
case ExpressionProxy(c, _, _) =>
- c.asInstanceOf[Cast]
+ Some(c.asInstanceOf[Cast])
+ case _ => None
}
override def eval(input: InternalRow): Any = try {
child.eval(input)
} catch {
case e: SparkArithmeticException =>
- val cast = getCast
- throw QueryExecutionErrors.castingCauseOverflowErrorInTableInsert(
- cast.child.dataType,
- cast.dataType,
- columnName)
+ getCast match {
+ case Some(cast) =>
+ throw QueryExecutionErrors.castingCauseOverflowErrorInTableInsert(
+ cast.child.dataType,
+ cast.dataType,
+ columnName)
+ case None => throw e
+ }
}
override protected def doGenCode(ctx: CodegenContext, ev: ExprCode):
ExprCode = {
- val child = getCast
+ getCast match {
+ case Some(child) => doGenCodeWithNewErrorMsg(ctx, ev, child)
+ case None => child.genCode(ctx)
+ }
+ }
+
+ def doGenCodeWithNewErrorMsg(ctx: CodegenContext, ev: ExprCode, child:
Cast): ExprCode = {
Review Comment:
Done.
--
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]