scala - IntelliJ 在 udf 函数上构建了一个有 2 个错误的项目 - 没有可用于 Option[Seq[Testclass]] 的 TypeTag
问题描述
我正在通过 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],
)
推荐阅读
- python - 我可以在不预先创建工作簿对象的情况下创建 Python Pandas ExcelWriter 格式吗?
- google-chrome - 为在 Chrome DevTools 中重定向的网站添加 cookie?
- typescript - Mocha --watch 在第二次运行时失败,并显示“addEventListener 不是函数”
- amazon-web-services - 无法使用 AWS S3 将域定向到静态页面
- firebase - 没有 FirebaseUser 的电子邮件验证
- python-3.x - 已解决 Python3,类和 tkinter 的困难
- r - 如何计算R中xy点的周长?
- angular - 什么时候需要消毒剂BypassSecurityUrl
- python - 当窗口调整大小时,也会在 tkinter GUI 中调整大小
- java - java中的程序意外终止