如何填充数组中的case类值参数?

时间:2019-04-09 13:00:45

标签: scala apache-spark dataset rdd case-class

我正在创建一个具有很多value参数的case类。我有一个用逗号分隔的字符串,并希望使用这些拆分参数创建一个对象。

case class Loan(
     id: Long,
     member_id: Long,
     loan_amnt: Double,
     funded_amnt: Double,
     funded_amnt_inv: Double,
     term: String)
{

// There are some implicit converters here: stringToDouble, stringToLong etc.

def fromString(objectData: String) : Loan = {
     val values = objectData.split(",")
     Loan(
         values(0),
         values(1),
         values(2),
         values(3),
         values(4),
         values(5))
}

相反,会是这样吗?

Loan(values: _*) // this won't work, just to be understandable.

0 个答案:

没有答案