@@ -210,32 +210,22 @@ func (n *alterFunctionRenameNode) startExec(params runParams) error {
210
210
}
211
211
}
212
212
213
- // Disallow renaming if this rename operation will break other UDF's invoking
214
- // this one.
215
- var dependentFuncs []string
216
- for _ , dep := range fnDesc .GetDependedOnBy () {
217
- desc , err := params .p .Descriptors ().ByIDWithoutLeased (params .p .Txn ()).Get ().Desc (params .ctx , dep .ID )
218
- if err != nil {
219
- return err
220
- }
221
- _ , ok := desc .(catalog.FunctionDescriptor )
222
- if ! ok {
223
- continue
224
- }
225
- fullyResolvedName , err := params .p .GetQualifiedFunctionNameByID (params .ctx , int64 (dep .ID ))
226
- if err != nil {
227
- return err
228
- }
229
- dependentFuncs = append (dependentFuncs , fullyResolvedName .FQString ())
213
+ // Disallow renaming if this rename operation will break other UDF's or views
214
+ // invoking this one.
215
+ dependentObjects , err := getFuncRefsDisallowingAlter (params , fnDesc )
216
+ if err != nil {
217
+ return err
230
218
}
231
- if len (dependentFuncs ) > 0 {
219
+ if len (dependentObjects ) > 0 {
220
+ // TODO(#146475): once functions are rewritten to use ID references, we can
221
+ // allow renames for views.
232
222
return errors .UnimplementedErrorf (
233
223
errors.IssueLink {
234
224
IssueURL : build .MakeIssueURL (83233 ),
235
225
Detail : "renames are disallowed because references are by name" ,
236
226
},
237
- "cannot rename function %q because other functions ([%v]) still depend on it" ,
238
- fnDesc .Name , strings .Join (dependentFuncs , ", " ))
227
+ "cannot rename function %q because other functions or views ([%v]) still depend on it" ,
228
+ fnDesc .Name , strings .Join (dependentObjects , ", " ))
239
229
}
240
230
241
231
scDesc .RemoveFunction (fnDesc .GetName (), fnDesc .GetID ())
@@ -383,33 +373,21 @@ func (n *alterFunctionSetSchemaNode) startExec(params runParams) error {
383
373
if err != nil {
384
374
return err
385
375
}
386
- // Disallow renaming if this rename operation will break other UDF's invoking
387
- // this one.
388
- var dependentFuncs []string
389
- for _ , dep := range fnDesc .GetDependedOnBy () {
390
- desc , err := params .p .Descriptors ().ByIDWithoutLeased (params .p .Txn ()).Get ().Desc (params .ctx , dep .ID )
391
- if err != nil {
392
- return err
393
- }
394
- _ , ok := desc .(catalog.FunctionDescriptor )
395
- if ! ok {
396
- continue
397
- }
398
- fullyResolvedName , err := params .p .GetQualifiedFunctionNameByID (params .ctx , int64 (dep .ID ))
399
- if err != nil {
400
- return err
401
- }
402
- dependentFuncs = append (dependentFuncs , fullyResolvedName .FQString ())
376
+ // Disallow renaming if this rename operation will break other UDF's or views
377
+ // invoking this one.
378
+ dependentObjects , err := getFuncRefsDisallowingAlter (params , fnDesc )
379
+ if err != nil {
380
+ return err
403
381
}
404
- if len (dependentFuncs ) > 0 {
382
+ if len (dependentObjects ) > 0 {
405
383
return errors .UnimplementedErrorf (
406
384
errors.IssueLink {
407
385
IssueURL : build .MakeIssueURL (83233 ),
408
386
Detail : "set schema is disallowed because there are references from " +
409
387
"other objects by name" ,
410
388
},
411
- "cannot set schema for function %q because other functions ([%v]) still depend on it" ,
412
- fnDesc .Name , strings .Join (dependentFuncs , ", " ))
389
+ "cannot set schema for function %q because other functions or views ([%v]) still depend on it" ,
390
+ fnDesc .Name , strings .Join (dependentObjects , ", " ))
413
391
}
414
392
415
393
switch sc .SchemaKind () {
@@ -548,3 +526,35 @@ func toSchemaOverloadSignature(fnDesc *funcdesc.Mutable) descpb.SchemaDescriptor
548
526
}
549
527
return ret
550
528
}
529
+
530
+ func getFuncRefsDisallowingAlter (
531
+ params runParams , fnDesc * funcdesc.Mutable ,
532
+ ) (dependentObjects []string , err error ) {
533
+ for _ , dep := range fnDesc .GetDependedOnBy () {
534
+ desc , err := params .p .Descriptors ().ByIDWithoutLeased (params .p .Txn ()).Get ().Desc (params .ctx , dep .ID )
535
+ if err != nil {
536
+ return nil , err
537
+ }
538
+ switch t := desc .(type ) {
539
+ case catalog.TableDescriptor :
540
+ if ! t .IsView () {
541
+ continue
542
+ }
543
+ fullyResolvedName , err := params .p .GetQualifiedTableNameByID (
544
+ params .ctx , int64 (dep .ID ), tree .ResolveAnyTableKind )
545
+ if err != nil {
546
+ return nil , err
547
+ }
548
+ dependentObjects = append (dependentObjects , fullyResolvedName .FQString ())
549
+ case catalog.FunctionDescriptor :
550
+ fullyResolvedName , err := params .p .GetQualifiedFunctionNameByID (params .ctx , int64 (dep .ID ))
551
+ if err != nil {
552
+ return nil , err
553
+ }
554
+ dependentObjects = append (dependentObjects , fullyResolvedName .FQString ())
555
+ default :
556
+ continue
557
+ }
558
+ }
559
+ return dependentObjects , nil
560
+ }
0 commit comments