[英]IntelliJ built a project with 2 errors on udf function - No TypeTag available for Option[Seq[Testclass]]
我正在通过IntelliJ为scala程序构建产品。 我没有任何错误地构建了另一个产品。
我没有任何其他尝试,因为这是我第一次用class / udf构建那种代码,我只是为这段代码得到一些参考
case class Testclass(
col1:Option[java.sql.Timestamp],
col2:Option[String],
col3:Option[Int],
col4:Option[Long],
col5:Option[Double],
)
val function = udf((l: Seq[Row], id: String, ts: Timestamp) => scala.util.Try {
l
.filter(c => id.isEmpty || c.getAs[String]("order_transaction_id").equalsIgnoreCase(id))
.filter(c => if (ts != null) c.getAs[Timestamp]("jump_timestamp").before(ts) else true)
.map { c =>
Testclass(
if (!c.isNullAt(0)) Some(c.getAs[Timestamp](0)) else None,
if (!c.isNullAt(1)) Some(c.getString(1)) else None,
if (!c.isNullAt(2)) Some(c.getInt(2)) else None,
if (!c.isNullAt(3)) Some(c.getLong(3)) else None,
if (!c.isNullAt(4)) Some(c.getDouble(4)) else None
)
}
.sortWith((c1, c2) => c1.his_ts.get.before(c2.his_ts.get))
}.toOption)
val dataFrame2 = dataFrame1
.withColumn("column_ABC", function(col("event_lists"), col("event_string"), col("event_timestamp")))
//source is a parquet file, but a little similar with json format
//event_lists is an array for this parquet, all the elements are same as the definition of Testclass
//event_string is a string field
//event_timestamp is a timestamp field
预期结果:构建应该成功,没有任何错误
对不起,我已经想通了
只需将代码与主类相同
case class Testclass(
col1:Option[java.sql.Timestamp],
col2:Option[String],
col3:Option[Int],
col4:Option[Long],
col5:Option[Double],
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.