【问题标题】:How to handle Coders for custom case class如何处理自定义案例类的编码器
【发布时间】:2020-03-13 16:52:25
【问题描述】:

我尝试运行一个简单的 SCIO 代码。

case class Foo(first: String, second: String, third: String)

尝试在SCollection 中使用Foo 会导致错误:

Cannot find an implicit Coder instance for type:

  >> (String, my.Foo)
...
<redacted prose>
...

错误信息中写了很多。 我似乎无法理解,尽管所有这些文本如何为我应该围绕 Coders 做的事情提供任何信息来解决这个问题。

任何人都可以阐明如何解决这个问题。

不使用implicits的奖励积分。

【问题讨论】:

    标签: spotify-scio


    【解决方案1】:

    这是一个简约的例子

    case class DemoEvents (reverse_geo_code_failed:String
                             ,eventType:String
                             ,city:String
                             ,area:String
                            )
    
    class DoFnExample extends DoFn [String, DemoEvents]{
        // `@ProcessElement` is called once per element.
        @ProcessElement
        private[example] def processElement(c: DoFn[String, DemoEvents]#ProcessContext): Unit ={
          //val t = DemoEvents("BNG1111","pickup","ORR","1111")
          implicit val formats: DefaultFormats.type = DefaultFormats
          c.output(parse(c.element()).extract[DemoEvents])
    
        }
      }
    
    val eventStream: SCollection[String] = sc.pubsubSubscription[String](args("pubsub-subscription-name"))
          .withFixedWindows(Duration.standardSeconds(120L))
    
    val events: SCollection[DemoEvents] = eventStream.applyTransform(ParDo.of(new DoFnExample()))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-02
      • 2015-11-28
      • 2015-08-02
      • 2019-10-29
      相关资源
      最近更新 更多