Github user datumbox commented on the issue:

    https://github.com/apache/spark/pull/17059
  
    Yeah, Scala Long matches. Here is the "stand-alone" script that I used to 
confirm that everything works ok (tested on Spark 2.1):
    ```scala
    import org.apache.spark.sql.types._
    import org.apache.spark.sql.functions._
    
    val u = udf { (n: Any) =>
      n match {
        case v: Int => v
        case v: Number =>
          val intV = v.intValue
          if (v.doubleValue == intV) {
            intV
          }
          else {
            throw new IllegalArgumentException("out of range")
          }
        case _ => throw new IllegalArgumentException("invalid type")
      }
    }
    
    val df = sqlContext.range(10)
      .withColumn("int_success", lit(123))
      .withColumn("long_success", lit(1231L))
      .withColumn("long_fail", lit(1231000000000L))
      .withColumn("decimal_success", lit(123).cast(DecimalType(5, 2)))
      .withColumn("decimal_fail", lit(123.1).cast(DecimalType(5, 2)))
      .withColumn("double_success", lit(123.0))
      .withColumn("double_fail", lit(123.1))
      .withColumn("double_fail2", lit(1231000000000.0))
      .withColumn("string_fail", lit("123.1"))
    
    // these work fine
    df.select(u(df.col("int_success"))).show
    df.select(u(df.col("long_success"))).show
    df.select(u(df.col("decimal_success"))).show
    df.select(u(df.col("double_success"))).show
    
    // these fail with out of int range exception
    df.select(u(df.col("long_fail"))).show
    df.select(u(df.col("decimal_fail"))).show
    df.select(u(df.col("double_fail"))).show
    df.select(u(df.col("double_fail2"))).show
    
    // this fails with invalid type exception
    df.select(u(df.col("string_fail"))).show
    ```
    Cool, I'll commit the changes tonight so that @mlnick can check the final 
code.
    
    @srowen I really appreciate your input; you did raise good points and 
especially for handling the SQL datatypes. Thank you.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to