@@ -55,13 +55,21 @@ func (r resource) Validate() error {
5555 return nil
5656}
5757
58+ type fieldConfig struct {
59+ CastToString bool `json:"castToString"`
60+ }
61+
62+ func (fc fieldConfig ) Validate () error {
63+ return nil
64+ }
65+
5866var _ boilerplate.Connector = & FileDriver {}
5967
6068// FileDriver contains the behaviors particular to a destination system and file format.
6169type FileDriver struct {
6270 NewConfig func (raw json.RawMessage ) (Config , error )
6371 NewStore func (ctx context.Context , config Config ) (Store , error )
64- NewEncoder func (config Config , b * pf.MaterializationSpec_Binding , w io.WriteCloser ) StreamEncoder
72+ NewEncoder func (config Config , b * pf.MaterializationSpec_Binding , w io.WriteCloser ) ( StreamEncoder , error )
6573 NewConstraints func (p * pf.Projection ) * pm.Response_Validated_Constraint
6674 DocumentationURL func () string
6775 ConfigSchema func () ([]byte , error )
@@ -131,8 +139,6 @@ func (d FileDriver) NewTransactor(ctx context.Context, open pm.Request_Open, _ *
131139 bindings := make ([]binding , 0 , len (open .Materialization .Bindings ))
132140
133141 for _ , b := range open .Materialization .Bindings {
134- b := b // for the newEncoder closure
135-
136142 var res resource
137143 if err := pf .UnmarshalStrict (b .ResourceConfigJson , & res ); err != nil {
138144 return nil , nil , nil , err
@@ -143,7 +149,7 @@ func (d FileDriver) NewTransactor(ctx context.Context, open pm.Request_Open, _ *
143149 backfill : b .Backfill ,
144150 path : res .Path ,
145151 includeDoc : b .FieldSelection .Document != "" ,
146- newEncoder : func (w io.WriteCloser ) StreamEncoder {
152+ newEncoder : func (w io.WriteCloser ) ( StreamEncoder , error ) {
147153 // Partial application of the driverCfg and b arguments to the FileDriver's NewEncoder
148154 // function, for convenience.
149155 return d .NewEncoder (driverCfg , b , w )
@@ -184,7 +190,7 @@ type binding struct {
184190 backfill uint32
185191 path string
186192 includeDoc bool
187- newEncoder func (w io.WriteCloser ) StreamEncoder
193+ newEncoder func (w io.WriteCloser ) ( StreamEncoder , error )
188194}
189195
190196// File keys are the full "path" to a file, usually applied as a key for an object in an object
@@ -244,7 +250,7 @@ func (t *transactor) Store(it *m.StoreIterator) (m.StartCommitFunc, error) {
244250 var encoder StreamEncoder
245251 var group errgroup.Group
246252
247- startFile := func (b binding ) {
253+ startFile := func (b binding ) error {
248254 // Start a new file upload. This may be called multiple times in a single transaction if
249255 // there is more data than can fit in a single file.
250256 r , w := io .Pipe ()
@@ -261,7 +267,9 @@ func (t *transactor) Store(it *m.StoreIterator) (m.StartCommitFunc, error) {
261267 return nil
262268 })
263269
264- encoder = b .newEncoder (w )
270+ var err error
271+ encoder , err = b .newEncoder (w )
272+ return err
265273 }
266274
267275 finishFile := func () error {
@@ -290,7 +298,9 @@ func (t *transactor) Store(it *m.StoreIterator) (m.StartCommitFunc, error) {
290298 lastBinding = it .Binding
291299
292300 if encoder == nil {
293- startFile (b )
301+ if err := startFile (b ); err != nil {
302+ return nil , fmt .Errorf ("startFile for binding %d: %w" , it .Binding , err )
303+ }
294304 }
295305
296306 row := make ([]any , 0 , len (it .Key )+ len (it .Values )+ 1 )
0 commit comments