Skip to content

Commit

Permalink
workload/schemachange: correct error code for referencing dropping enum
Browse files Browse the repository at this point in the history
This patch changes the error code expected for referencing
an enum that's in the process of being dropped to the proper
one. In addition, we ensure that we are returning the proper
error code whenever we get/lookup type descriptors

Epic: none

Release note: None
  • Loading branch information
annrpom committed Mar 26, 2024
1 parent 06b6c42 commit 3038c13
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/catalog/descs/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (g ByNameGetter) Type(
tn := tree.MakeTableNameWithSchema(
tree.Name(db.GetName()), tree.Name(sc.GetName()), tree.Name(name),
)
return nil, sqlerrors.NewUndefinedRelationError(&tn)
return nil, sqlerrors.NewUndefinedTypeError(&tn)
}
if tbl, ok := desc.(catalog.TableDescriptor); ok {
// A given table name can resolve to either a type descriptor or a table
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,8 @@ func (l *internalLookupCtx) getTableByID(id descpb.ID) (catalog.TableDescriptor,
func (l *internalLookupCtx) getTypeByID(id descpb.ID) (catalog.TypeDescriptor, error) {
typ, ok := l.typDescs[id]
if !ok {
return nil, sqlerrors.NewUndefinedRelationError(
tree.NewUnqualifiedTableName(tree.Name(fmt.Sprintf("[%d]", id))))
return nil, sqlerrors.NewUndefinedTypeError(
tree.NewUnqualifiedTypeName(fmt.Sprintf("[%d]", id)))
}
return typ, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4021,7 +4021,7 @@ func (og *operationGenerator) createFunction(ctx context.Context, tx pgx.Tx) (*o
// 4. Reference a UDT that does not exist.
{pgcode.UndefinedObject, `CREATE FUNCTION { UniqueName } (IN p1 "ThisTypeDoesNotExist") RETURNS VOID LANGUAGE SQL AS $$ SELECT NULL $$`},
// 5. Reference an Enum that's in the process of being dropped
{pgcode.UndefinedTable, `CREATE FUNCTION { UniqueName } (IN p1 { NonPublicEnum }) RETURNS VOID LANGUAGE SQL AS $$ SELECT NULL $$`},
{pgcode.UndefinedObject, `CREATE FUNCTION { UniqueName } (IN p1 { NonPublicEnum }) RETURNS VOID LANGUAGE SQL AS $$ SELECT NULL $$`},
// 6. Reference an Enum value that's in the process of being dropped
{pgcode.InvalidParameterValue, `CREATE FUNCTION { UniqueName } () RETURNS VOID LANGUAGE SQL AS $$ SELECT { DroppingEnumMember } $$`},
}, placeholderMap)
Expand Down

0 comments on commit 3038c13

Please sign in to comment.