Spark SQL UDF with complex input parameter

后端 未结 2 433
Happy的楠姐
Happy的楠姐 2020-12-19 13:13

I\'m trying to use UDF with input type Array of struct. I have the following structure of data this is only relevant part of a bigger structure

|--investment         


        
2条回答
  •  温柔的废话
    2020-12-19 13:42

    I created a simple library which derives the necessary encoders for complex Product types based on the input type parameters.

    https://github.com/lesbroot/typedudf

    import typedudf.TypedUdf
    import typedudf.ParamEncoder._
    
    case class Foo(x: Int, y: String)
    val fooUdf = TypedUdf((foo: Foo) => foo.x + foo.y.length)
    df.withColumn("sum", fooUdf($"foo"))
    

提交回复
热议问题