GitHub user ueshin opened a pull request:

    https://github.com/apache/spark/pull/533

    [SPARK-1610] [SQL] Fix Cast to use exact type value when cast from 
BooleanType to NumericTy...

    ...pe.
    
    `Cast` from `BooleanType` to `NumericType` are all using `Int` value.
    But it causes `ClassCastException` when the casted value is used by the 
following evaluation like the code below:
    
    ``` scala
    scala> import org.apache.spark.sql.catalyst._
    import org.apache.spark.sql.catalyst._
    
    scala> import types._
    import types._
    
    scala> import expressions._
    import expressions._
    
    scala> Add(Cast(Literal(true), ShortType), Literal(1.toShort)).eval()
    java.lang.ClassCastException: java.lang.Integer cannot be cast to 
java.lang.Short
        at scala.runtime.BoxesRunTime.unboxToShort(BoxesRunTime.java:102)
        at scala.math.Numeric$ShortIsIntegral$.plus(Numeric.scala:72)
        at 
org.apache.spark.sql.catalyst.expressions.Add$$anonfun$eval$2.apply(arithmetic.scala:58)
        at 
org.apache.spark.sql.catalyst.expressions.Add$$anonfun$eval$2.apply(arithmetic.scala:58)
        at 
org.apache.spark.sql.catalyst.expressions.Expression.n2(Expression.scala:114)
        at 
org.apache.spark.sql.catalyst.expressions.Add.eval(arithmetic.scala:58)
        at .<init>(<console>:17)
        at .<clinit>(<console>)
        at .<init>(<console>:7)
        at .<clinit>(<console>)
        at $print(<console>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734)
        at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983)
        at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573)
        at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604)
        at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568)
        at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:760)
        at 
scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:805)
        at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:717)
        at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:581)
        at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:588)
        at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:591)
        at 
scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:882)
        at 
scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:837)
        at 
scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:837)
        at 
scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
        at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:837)
        at 
scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:83)
        at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:105)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
    ```

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ueshin/apache-spark issues/SPARK-1610

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/533.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #533
    
----
commit 70f36e8e14ac63aa6944907bf9dba8fe59f04881
Author: Takuya UESHIN <[email protected]>
Date:   2014-04-24T11:37:04Z

    Fix Cast to use exact type value when cast from BooleanType to NumericType.

----


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to