spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Apache Spark (JIRA)" <j...@apache.org>
Subject [jira] [Assigned] (SPARK-8935) Implement code generation for all casts
Date Mon, 13 Jul 2015 07:04:05 GMT

     [ https://issues.apache.org/jira/browse/SPARK-8935?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Apache Spark reassigned SPARK-8935:
-----------------------------------

    Assignee: Yijie Shen  (was: Apache Spark)

> Implement code generation for all casts
> ---------------------------------------
>
>                 Key: SPARK-8935
>                 URL: https://issues.apache.org/jira/browse/SPARK-8935
>             Project: Spark
>          Issue Type: Sub-task
>          Components: SQL
>            Reporter: Reynold Xin
>            Assignee: Yijie Shen
>
> Cast expression only supports a subset of type casts. We should just implement all the
possible casts so we don't need to fall back to non-codegen mode.
> See Cast.scala
> {code}
>   override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
>     // TODO: Add support for more data types.
>     (child.dataType, dataType) match {
>       case (BinaryType, StringType) =>
>         defineCodeGen (ctx, ev, c =>
>           s"${ctx.stringType}.fromBytes($c)")
>       case (DateType, StringType) =>
>         defineCodeGen(ctx, ev, c =>
>           s"""${ctx.stringType}.fromString(
>                 org.apache.spark.sql.catalyst.util.DateTimeUtils.dateToString($c))""")
>       case (TimestampType, StringType) =>
>         defineCodeGen(ctx, ev, c =>
>           s"""${ctx.stringType}.fromString(
>                 org.apache.spark.sql.catalyst.util.DateTimeUtils.timestampToString($c))""")
>       case (_, StringType) =>
>         defineCodeGen(ctx, ev, c => s"${ctx.stringType}.fromString(String.valueOf($c))")
>       // fallback for DecimalType, this must be before other numeric types
>       case (_, dt: DecimalType) =>
>         super.genCode(ctx, ev)
>       case (BooleanType, dt: NumericType) =>
>         defineCodeGen(ctx, ev, c => s"(${ctx.javaType(dt)})($c ? 1 : 0)")
>       case (dt: DecimalType, BooleanType) =>
>         defineCodeGen(ctx, ev, c => s"!$c.isZero()")
>       case (dt: NumericType, BooleanType) =>
>         defineCodeGen(ctx, ev, c => s"$c != 0")
>       case (_: DecimalType, dt: NumericType) =>
>         defineCodeGen(ctx, ev, c => s"($c).to${ctx.primitiveTypeName(dt)}()")
>       case (_: NumericType, dt: NumericType) =>
>         defineCodeGen(ctx, ev, c => s"(${ctx.javaType(dt)})($c)")
>       case other =>
>         super.genCode(ctx, ev)
>     }
>   }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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


Mime
View raw message