spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From datumbox <>
Subject [GitHub] spark issue #17059: [SPARK-19733][ML]Removed unnecessary castings and refact...
Date Mon, 27 Feb 2017 16:56:06 GMT
Github user datumbox commented on the issue:
    Yeah, Scala Long matches. Here is the "stand-alone" script that I used to confirm that
everything works ok (tested on Spark 2.1):
    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) {
          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"int_success"))).show"long_success"))).show"decimal_success"))).show"double_success"))).show
    // these fail with out of int range exception"long_fail"))).show"decimal_fail"))).show"double_fail"))).show"double_fail2"))).show
    // this fails with invalid type exception"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 or file a JIRA ticket
with INFRA.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message