简体   繁体   中英

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. 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

    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],
                )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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