【问题标题】:How can I migrate from avro4s 3.0.4 to 4.0.0-RC2?如何从 avro4s 3.0.4 迁移到 4.0.0-RC2?
【发布时间】:2020-07-28 19:19:56
【问题描述】:

如何从 avro4s 3.0.4 迁移到 4.0.0-RC2? 我有以下编译错误:

[error] /Users/nicolae.marasoiu/proj/data-availability-global-topic-conveyor/src/main/scala/com/ovoenergy/globaltopics/serdes/AvroFormatImplicits.scala:8:15: value const is not a member of object com.sksamuel.avro4s.SchemaFor
[error]     SchemaFor.const(new Schema.Parser().parse(getClass.getResourceAsStream(hasSchema.resourcePath)))
[error]               ^
[error] /Users/nicolae.marasoiu/proj/data-availability-global-topic-conveyor/src/main/scala/com/ovoenergy/globaltopics/serdes/AvroFormatImplicits.scala:11:26: not enough arguments for method apply: (implicit evidence$1: com.sksamuel.avro4s.Encoder[T], implicit evidence$2: com.sksamuel.avro4s.Decoder[T])com.sksamuel.avro4s.RecordFormat[T] in object RecordFormat.
[error] Unspecified value parameter evidence$2.
[error]     RecordFormat.apply[T](AvroSchema[T](readSchema))
[error]                          ^
[error] /Users/nicolae.marasoiu/proj/data-availability-global-topic-conveyor/src/main/scala/com/ovoenergy/globaltopics/serdes/SerdeProvider.scala:29:37: org.apache.avro.Schema does not take parameters
[error]     val schema = SchemaFor[T].schema(DefaultFieldMapper)
[error]                                     ^
[error] /Users/nicolae.marasoiu/proj/data-availability-global-topic-conveyor/src/main/scala/com/ovoenergy/globaltopics/serdes/SerdeProvider.scala:37:70: no arguments allowed for nullary method build: ()com.sksamuel.avro4s.AvroOutputStream[T]
[error]             val os     = AvroOutputStream.binary[T].to(output).build(schema)
[error]                                                                      ^
[error] four errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 17 s, completed 28-Jul-2020 19:42:21
[IJ]sbt:global-topic-conveyor> 

【问题讨论】:

  • 您能否添加一个您要迁移的代码 sn-p?

标签: scala avro avro4s


【解决方案1】:

首先,您可以随时关注avro4s github repository 的更改。此外,您可以看到specific changes made between the versions you specified

你没有附上任何源代码,所以我会尽量解决你的失败,因为我可以从你的失败中理解它们。

  1. SchemaFor.const 在版本 3.0.5 中被删除。您可以在diff between the versions 中看到这一点。假设您有Schema s,并且到目前为止您已启动SchemaFor.const(s),现在您需要启动它:SchemaFor(s)。将使用默认的 fieldMapper。你可以看到它here
  2. RecordFormat 不再接受参数。因此,假设您有一个类型 T,应用在 RecordFormat.apply[T](AvroSchema[T](readSchema)),您需要将其更改为:RecordFormat[T]
  3. 非常类似于数字 1。SchemaFor.schemawas removed。相反,您可以这样做:SchemaFor[T].schemaSchema 不再带参数,所以不能用括号调用它。
  4. AvroOutputStream.build 用于将模式作为参数。它不再需要它了。您需要将AvroOutputStream.binary[T].to(output).build(schema) 更改为:AvroOutputStream.binary[T].to(output).build()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-06
    • 2013-06-18
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 2016-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多