@@ -129,13 +129,27 @@ func (r *Routine) Delete(ctx context.Context) (err error) {
129
129
return req .Do ()
130
130
}
131
131
132
+ // RoutineDeterminism specifies the level of determinism that javascript User Defined Functions
133
+ // exhibit.
134
+ type RoutineDeterminism string
135
+
136
+ const (
137
+ // Deterministic indicates that two calls with the same input to a UDF yield the same output.
138
+ Deterministic RoutineDeterminism = "DETERMINISTIC"
139
+ // NotDeterministic indicates that the output of the UDF is not guaranteed to yield the same
140
+ // output each time for a given set of inputs.
141
+ NotDeterministic RoutineDeterminism = "NOT_DETERMINISTIC"
142
+ )
143
+
132
144
// RoutineMetadata represents details of a given BigQuery Routine.
133
145
type RoutineMetadata struct {
134
146
ETag string
135
147
// Type indicates the type of routine, such as SCALAR_FUNCTION or PROCEDURE.
136
- Type string
137
- CreationTime time.Time
138
- Description string
148
+ Type string
149
+ CreationTime time.Time
150
+ Description string
151
+ // DeterminismLevel is only applicable to Javascript UDFs.
152
+ DeterminismLevel RoutineDeterminism
139
153
LastModifiedTime time.Time
140
154
// Language of the routine, such as SQL or JAVASCRIPT.
141
155
Language string
@@ -161,6 +175,7 @@ func (rm *RoutineMetadata) toBQ() (*bq.Routine, error) {
161
175
return r , nil
162
176
}
163
177
r .Description = rm .Description
178
+ r .DeterminismLevel = string (rm .DeterminismLevel )
164
179
r .Language = rm .Language
165
180
r .RoutineType = rm .Type
166
181
r .DefinitionBody = rm .Body
@@ -280,6 +295,7 @@ func routineArgumentsToBQ(in []*RoutineArgument) ([]*bq.Argument, error) {
280
295
type RoutineMetadataToUpdate struct {
281
296
Arguments []* RoutineArgument
282
297
Description optional.String
298
+ DeterminismLevel optional.String
283
299
Type optional.String
284
300
Language optional.String
285
301
Body optional.String
@@ -299,6 +315,21 @@ func (rm *RoutineMetadataToUpdate) toBQ() (*bq.Routine, error) {
299
315
r .Description = optional .ToString (rm .Description )
300
316
forceSend ("Description" )
301
317
}
318
+ if rm .DeterminismLevel != nil {
319
+ processed := false
320
+ // Allow either string or RoutineDeterminism, a type based on string.
321
+ if x , ok := rm .DeterminismLevel .(RoutineDeterminism ); ok {
322
+ r .DeterminismLevel = string (x )
323
+ processed = true
324
+ }
325
+ if x , ok := rm .DeterminismLevel .(string ); ok {
326
+ r .DeterminismLevel = x
327
+ processed = true
328
+ }
329
+ if ! processed {
330
+ panic (fmt .Sprintf ("DeterminismLevel should be either type string or RoutineDetermism in update, got %T" , rm .DeterminismLevel ))
331
+ }
332
+ }
302
333
if rm .Arguments != nil {
303
334
if len (rm .Arguments ) == 0 {
304
335
nullField ("Arguments" )
@@ -348,6 +379,7 @@ func bqToRoutineMetadata(r *bq.Routine) (*RoutineMetadata, error) {
348
379
Type : r .RoutineType ,
349
380
CreationTime : unixMillisToTime (r .CreationTime ),
350
381
Description : r .Description ,
382
+ DeterminismLevel : RoutineDeterminism (r .DeterminismLevel ),
351
383
LastModifiedTime : unixMillisToTime (r .LastModifiedTime ),
352
384
Language : r .Language ,
353
385
ImportedLibraries : r .ImportedLibraries ,
0 commit comments