Hi

I am trying to define an UDF that can take an array of tuples as input

def effectiveExpectedExposure(expectedExposures: Seq[(Seq[Float],
Seq[Float])])=
expectedExposures.map(x=> x._1 * x._2).sum/expectedExposures.map(x=>
x._1).sum

sqlContext.udf.register("expectedPositiveExposure",
expectedPositiveExposure _)

I get the following message when I try calling this function, where
noOfMonths and ee are both floats

val df = sqlContext.sql(s"select (collect(struct(noOfMonths, ee))) as eee
 from netExposureCpty where counterparty = 'xyz'")
df.registerTempTable("test")
sqlContext.sql("select effectiveExpectedExposure(eee)  from test")

Error in SQL statement: AnalysisException: cannot resolve 'UDF(eee)' due to
data type mismatch: argument 1 requires array<struct<_1:float,_2:float>>
type, however, 'eee' is of array<struct<noofmonths:float,ee:float>> type.;
line 1 pos 33

Deenar

Reply via email to