简体   繁体   English

没有 TypeTag 可用于案例 class 使用 scala 3 和火花 3

[英]No TypeTag available for a case class using scala 3 with spark 3

I have my code that runs a spark job with scala 3我的代码使用 scala 3 运行火花作业

@main def startDatasetJob(): Unit =
  val spark = SparkSession.builder()
    .appName("Datasets")
    .master("local[*]")
    .getOrCreate()

  case class CarRow(Name: String,
                 Miles_per_Gallon: Double,
                 Cylinders: Long,
                 Displacement: Double,
                 Horsepower: Long,
                 Weight_in_lbs: Long,
                 Acceleration: Double,
                 Year: Date,
                 Origin: String
                )

  implicit val carEncoder: Encoder[CarRow] = Encoders.product[CarRow]
  val carsDF = spark.read
    .format("json")
    .option("inferSchema", "true")
    .load("src/main/resources/data/cars.json")

  val carDS = carsDF.as[CarRow]

but get the error message但收到错误消息

No TypeTag available for CarRow
  implicit val carEncoder: Encoder[CarRow] = Encoders.product[CarRow]

get a bit confused why the compiler seems unable to load the case class, if any one can help有点困惑为什么编译器似乎无法加载案例 class,如果有人可以提供帮助

Spark's encoder derivation relies on Scala 2.x mechanisms, some of them no longer exist. Spark 的编码器推导依赖于 Scala 2.x 机制,其中一些已不存在。

Have you tried with spark-scala3 ?你试过spark-scala3吗? It provides the encoder derivation for Scala 3.它为 Scala 3 提供编码器推导。

libraryDependencies += "io.github.vincenzobaz" %% "spark-scala3" % "0.1.3"

Then然后

import scala3encoders.given

(see the examples in the repo) (请参阅 repo 中的示例)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Scala-没有TypeTag可用当使用案例类尝试获取TypeTag时发生异常吗? - Scala - No TypeTag Available Exception when using case class to try to get TypeTag? Scala Spark Encoders.product[X](其中 X 是一个案例类)不断给我“No TypeTag available for X”错误 - Scala Spark Encoders.product[X] (where X is a case class) keeps giving me "No TypeTag available for X" error 没有适用于案例类别Type的TypeTag - No TypeTag available for case class Type Spark Scala API:官方示例中spark.createDataFrame中没有typeTag - Spark Scala API: No typeTag available in spark.createDataFrame in official example 带有scala2.10.6的spark1.6.2没有可用的TypeTag - spark1.6.2 with scala2.10.6 No TypeTag available 具有“No TypeTag available”的Scala / Spark应用程序“def main”样式App中的错误 - Scala/Spark App with “No TypeTag available” Error in “def main” style App Scala编译器在使用泛型的方法中说“没有TypeTag可用于T” - Scala compiler says “No TypeTag available for T” in method using generics Spark 数据帧 udf 没有可用的 TypeTag - Spark dataframe udf No TypeTag available Scala:在方法中使用TypeTag - Scala: Using TypeTag in a method scala如何参数化案例类,并将案例类变量传递给[T &lt;:Product:TypeTag] - scala how to parameterized case class, and pass the case class variable to [T <: Product: TypeTag]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM