You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@beam.apache.org by Tarrence van As <ta...@vanas.family> on 2021/08/01 20:05:39 UTC

[Question] Golang: Custom Type Coder

Hi all,

Thank you for the great work on Beam. I'm using the golang sdk and hoping
someone might be able to help with defining a customer coder for a type.

I have a type like this:
type Execer struct {
Query string `json:"query,omitempty"`
Args []interface{} `json:"args,omitempty"`
}

Where each element in Args implements `driver.Valuer`.

When trying to run with this as an element of a PCollection I get:

panic: unable to encode type: interface {}

This issue occurs if I try to create a PCollection with `beam.Create(s,
Execer{q, a})` but seems to work (at least with the direct runner) when I
emit the struct like `emit(Execer{q, a})`.

My guess is that I need to define an encode/decode method for the type, but
I'm not sure what interface it should implement. Any direction would be
appreciated.

Tarrence