簡體   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]]

我正在通過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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM