Github user kiszk commented on a diff in the pull request: https://github.com/apache/spark/pull/18153#discussion_r119527989 --- 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 => + defineCodeGen(ctx, ev, c => s"java.lang.Math.abs(Double.valueOf($c.toString()))") --- End diff -- I would like to hear @gatorsmile 's opinion. Which specification should Spark support?
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org