spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiszk <...@git.apache.org>
Subject [GitHub] spark pull request #18153: [SPARK-20931][SQL] ABS function support string ty...
Date Thu, 01 Jun 2017 04:59:32 GMT
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message