@@ -23,8 +23,6 @@ import (
2323 "fmt"
2424
2525 "github.com/apache/beam/sdks/go/pkg/beam"
26- "github.com/apache/beam/sdks/go/pkg/beam/core/graph/coder"
27- "github.com/apache/beam/sdks/go/pkg/beam/core/runtime/exec"
2826 "github.com/apache/beam/sdks/go/pkg/beam/core/typex"
2927 "github.com/apache/beam/sdks/go/pkg/beam/transforms/filter"
3028)
@@ -61,26 +59,25 @@ func equals(s beam.Scope, actual, expected beam.PCollection) beam.PCollection {
6159// because all values are held in memory at the same time.
6260func Diff (s beam.Scope , a , b beam.PCollection ) (left , both , right beam.PCollection ) {
6361 imp := beam .Impulse (s )
64- return beam .ParDo3 (s , & diffFn {Coder : beam.EncodedCoder {Coder : a .Coder ()}}, imp , beam.SideInput {Input : a }, beam.SideInput {Input : b })
65- }
6662
67- // TODO(herohde) 7/11/2017: should there be a first-class way to obtain the coder,
68- // such a a specially-typed parameter?
63+ t := beam .ValidateNonCompositeType (a )
64+ beam .ValidateNonCompositeType (b )
65+ return beam .ParDo3 (s , & diffFn {Type : beam.EncodedType {T : t .Type ()}}, imp , beam.SideInput {Input : a }, beam.SideInput {Input : b })
66+ }
6967
7068// diffFn computes the symmetrical multi-set difference of 2 collections, under
7169// coder equality. The Go values returned may be any of the coder-equal ones.
7270type diffFn struct {
73- Coder beam.EncodedCoder `json:"coder "`
71+ Type beam.EncodedType `json:"type "`
7472}
7573
7674func (f * diffFn ) ProcessElement (_ []byte , ls , rs func (* beam.T ) bool , left , both , right func (t beam.T )) error {
77- c := beam .UnwrapCoder (f .Coder .Coder )
78-
79- indexL , err := index (c , ls )
75+ enc := beam .NewElementEncoder (f .Type .T )
76+ indexL , err := index (enc , ls )
8077 if err != nil {
8178 return err
8279 }
83- indexR , err := index (c , rs )
80+ indexR , err := index (enc , rs )
8481 if err != nil {
8582 return err
8683 }
@@ -130,15 +127,14 @@ type indexEntry struct {
130127 value beam.T
131128}
132129
133- func index (c * coder. Coder , iter func (* beam.T ) bool ) (map [string ]indexEntry , error ) {
130+ func index (enc beam. ElementEncoder , iter func (* beam.T ) bool ) (map [string ]indexEntry , error ) {
134131 ret := make (map [string ]indexEntry )
135- enc := exec .MakeElementEncoder (c )
136132
137133 var val beam.T
138134 for iter (& val ) {
139135 var buf bytes.Buffer
140- if err := enc .Encode (exec. FullValue { Elm : val } , & buf ); err != nil {
141- return nil , fmt .Errorf ("value %v not encodable by %v" , val , c )
136+ if err := enc .Encode (val , & buf ); err != nil {
137+ return nil , fmt .Errorf ("value %v not encodable with %v" , val , enc )
142138 }
143139 encoded := buf .String ()
144140
@@ -148,9 +144,6 @@ func index(c *coder.Coder, iter func(*beam.T) bool) (map[string]indexEntry, erro
148144 return ret , nil
149145}
150146
151- // TODO(herohde) 7/11/2017: perhaps extract the coder helpers as more
152- // general and polished utilities for working with coders in user code.
153-
154147// True asserts that all elements satisfy the given predicate.
155148func True (s beam.Scope , col beam.PCollection , fn interface {}) beam.PCollection {
156149 fail (s , filter .Exclude (s , col , fn ), "predicate(%v) = false, want true" )
0 commit comments