spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yjshen <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-8935][SQL] Implement code generation fo...
Date Tue, 21 Jul 2015 17:30:01 GMT
Github user yjshen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7365#discussion_r35129721
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
---
    @@ -418,51 +418,518 @@ case class Cast(child: Expression, dataType: DataType)
       protected override def nullSafeEval(input: Any): Any = cast(input)
     
       override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    -    // TODO: Add support for more data types.
    -    (child.dataType, dataType) match {
    +    val nullSafeCast = nullSafeCastFunction(child.dataType, dataType, ctx)
    +    if (nullSafeCast != null) {
    +      val eval = child.gen(ctx)
    +      eval.code +
    +        castCode(ctx, eval.primitive, eval.isNull, ev.primitive, ev.isNull, dataType,
nullSafeCast)
    +    } else {
    +      super.genCode(ctx, ev)
    +    }
    +  }
    +
    +  // three function arguments are: child.primitive, result.primitive and result.isNull
    +  // it returns the code snippets to be put in null safe evaluation region
    +  private[this] type CastFunction = (String, String, String) => String
    +
    +  private[this] def nullSafeCastFunction(
    +      from: DataType,
    +      to: DataType,
    +      ctx: CodeGenContext): CastFunction = to match {
    +
    +    case _ if from == NullType => (c, evPrim, evNull) => s"$evNull = true;"
    +    case _ if to == from => (c, evPrim, evNull) => s"$evPrim = $c;"
    +    case StringType => castToStringCode(from, ctx)
    +    case BinaryType => castToBinaryCode(from)
    +    case DateType => castToDateCode(from, ctx)
    +    case decimal: DecimalType => castToDecimalCode(from, decimal)
    +    case TimestampType => castToTimestampCode(from, ctx)
    +    case IntervalType => castToIntervalCode(from)
    +    case BooleanType => castToBooleanCode(from)
    +    case ByteType => castToByteCode(from)
    +    case ShortType => castToShortCode(from)
    +    case IntegerType => castToIntCode(from)
    +    case FloatType => castToFloatCode(from)
    +    case LongType => castToLongCode(from)
    +    case DoubleType => castToDoubleCode(from)
    +
    +    case array: ArrayType => castArrayCode(from.asInstanceOf[ArrayType], array, ctx)
    +    case map: MapType => castMapCode(from.asInstanceOf[MapType], map, ctx)
    +    case struct: StructType => castStructCode(from.asInstanceOf[StructType], struct,
ctx)
    +    case other => null
    --- End diff --
    
    I think it should be removed, this was from the origin implementation when only limited
cast codegen exists, since I have all the cast with interpreted eval, I think just remove
this is reasonable


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