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

    https://github.com/apache/spark/pull/9870#discussion_r45545095
  
    --- 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 --
    
    I can't reproduce the difference. It won't infer it in a standalone program 
[either](https://gist.github.com/dragos/7c2d3ec962ee2e6862f3).
    
    As I mentioned in our conversation, it's a chicken and egg problem: type 
inference is guided by the expected type, but if the method is overloaded, the 
expected type is not known. And the argument type is what guides overload 
resolution. It works in simple cases, when the overloads have different 
aritites, but with varargs that's no longer the case.


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