Skip to content

[Bug]: Error occurs when assigning an interface to a field of a struct used for emitting in Go SDK #29582

@natumn

Description

@natumn

What happened?

In the documentation's Inferring Schemas section, it is stated, "Fields of interface types are ignored, unless a schema provider is registered for them."
However, when an interface is assigned to a field of a struct used for emitting, it results in an error instead of being ignored.
Is this an error in the documentation, or is there a bug?
This error has been occurring from Go SDK version v2.44.0 to the current latest version.

Here is a sample code that reproduces the issue:

func init() {
	register.DoFn2x0[[]byte, func(*Foo)](&SampleFn{})
	register.Emitter1[*Foo]() // Failure occurs when this line is added.
}

func main() {
    beam.Init()
    p, s := beam.NewPipelineWithRoot()
    foo := beam.ParDo(s, &SampleFn{}, beam.Impulse(s))
    fmt.Println(foo)
}

type Foo struct {
	Bar Bar
}

type Bar interface {
	Bar()
}

type BarImpl struct{}

func (p *BarImpl) Bar() {}

type SampleFn struct{}

func (fn *SampleFn) ProcessElement(_ []byte, emit func(h *Foo)) {
	foo := &Foo{
		Bar: &BarImpl{},
	}

	emit(foo)
}

When executing the above code, the following error occurs:

- : panic: error reconciling type Foo
    caused by:
    converting Foo to schema
    cannot convert field Bar to schema
    caused by:
    unable to convert unsupported type Bar to schema

Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

Issue Components

  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam YAML
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Samza Runner
  • Component: Twister2 Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions