You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Apache Spark (JIRA)" <ji...@apache.org> on 2015/07/13 09:04:04 UTC
[jira] [Commented] (SPARK-8935) Implement code generation for all
casts
[ https://issues.apache.org/jira/browse/SPARK-8935?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14624288#comment-14624288 ]
Apache Spark commented on SPARK-8935:
-------------------------------------
User 'yijieshen' has created a pull request for this issue:
https://github.com/apache/spark/pull/7365
> 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