Github user marmbrus commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9870#discussion_r45519517
  
    --- Diff: 
repl/scala-2.10/src/test/scala/org/apache/spark/repl/ReplSuite.scala ---
    @@ -315,6 +315,30 @@ class ReplSuite extends SparkFunSuite {
         }
       }
     
    +  test("Datasets agg type-inference") {
    +    val output = runInterpreter("local",
    +      """
    +        |import org.apache.spark.sql.functions._
    +        |import org.apache.spark.sql.Encoder
    +        |import org.apache.spark.sql.expressions.Aggregator
    +        |import org.apache.spark.sql.TypedColumn
    +        |/** An `Aggregator` that adds up any numeric type returned by the 
given function. */
    +        |class SumOf[I, N : Numeric](f: I => N) extends Aggregator[I, N, 
N] with Serializable {
    +        |  val numeric = implicitly[Numeric[N]]
    +        |  override def zero: N = numeric.zero
    +        |  override def reduce(b: N, a: I): N = numeric.plus(b, f(a))
    +        |  override def merge(b1: N,b2: N): N = numeric.plus(b1, b2)
    +        |  override def finish(reduction: N): N = reduction
    +        |}
    +        |
    +        |def sum[I, N : Numeric : Encoder](f: I => N): TypedColumn[I, N] = 
new SumOf(f).toColumn
    +        |val ds = Seq((1, 1, 2L), (1, 2, 3L), (1, 3, 4L), (2, 1, 
5L)).toDS()
    +        |ds.groupBy(_._1).agg(sum(_._2), sum(_._3)).collect()
    --- End diff --
    
    @dragos any idea why it fails to infer the type only in the REPL?


---
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.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to