简体   繁体   English

IntelliJ在udf函数上构建了一个有2个错误的项目 - 没有TypeTag可用于Option [Seq [Testclass]]

[英]IntelliJ built a project with 2 errors on udf function - No TypeTag available for Option[Seq[Testclass]]

I am building a Product via IntelliJ for a scala programme. 我正在通过IntelliJ为scala程序构建产品。 I built another one Product without any error. 我没有任何错误地构建了另一个产品。

I did not have any other try, because this is my first time do build the kind of code with class/udf, I just get some reference for the piece of code 我没有任何其他尝试,因为这是我第一次用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

Expected result: build should be succeeded without any error 预期结果:构建应该成功,没有任何错误

sorry, I have figured out 对不起,我已经想通了

just put the code same level as the master class 只需将代码与主类相同

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM