Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/18153#discussion_r122371858
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
---
@@ -97,20 +97,30 @@ case class UnaryPositive(child: Expression)
case class Abs(child: Expression)
extends UnaryExpression with ExpectsInputTypes with NullIntolerant {
- override def inputTypes: Seq[AbstractDataType] = Seq(NumericType)
+ override def inputTypes: Seq[AbstractDataType] =
Seq(TypeCollection(NumericType, StringType))
- override def dataType: DataType = child.dataType
+ override def dataType: DataType = child.dataType match {
+ case dt: NumericType => dt
+ case dt: StringType => DoubleType
+ }
private lazy val numeric = TypeUtils.getNumeric(dataType)
- override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode =
dataType match {
+ override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode =
child.dataType match {
case dt: DecimalType =>
defineCodeGen(ctx, ev, c => s"$c.abs()")
case dt: NumericType =>
defineCodeGen(ctx, ev, c =>
s"(${ctx.javaType(dt)})(java.lang.Math.abs($c))")
+ case dt: StringType =>
--- End diff --
Could we move the type promotion to the rule
[PromoteStrings](https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala#L360-L367)?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]