Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlsmith: do not error when UDTs have no members #90456

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions pkg/internal/sqlsmith/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree/treebin"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/errors"
"github.com/lib/pq/oid"
)

Expand Down Expand Up @@ -222,29 +221,25 @@ FROM
members = append(members, string(tree.MustBeDString(d)))
}
}
// Try to construct type information from the resulting row.
switch {
case len(members) > 0:
typ := types.MakeEnum(catid.TypeIDToOID(descpb.ID(id)), 0 /* arrayTypeID */)
typ.TypeMeta = types.UserDefinedTypeMetadata{
Name: &types.UserDefinedTypeName{
Schema: scName,
Name: name,
},
EnumData: &types.EnumMetadata{
LogicalRepresentations: members,
// The physical representations don't matter in this case, but the
// enum related code in tree expects that the length of
// PhysicalRepresentations is equal to the length of LogicalRepresentations.
PhysicalRepresentations: make([][]byte, len(members)),
IsMemberReadOnly: make([]bool, len(members)),
},
}
key := tree.MakeSchemaQualifiedTypeName(scName, name)
udtMapping[key] = typ
default:
return nil, errors.Newf("unsupported SQLSmith type kind: %s", string(membersRaw))
}
// Construct type information from the resulting row. Note that the UDT
// may have no members (e.g., `CREATE TYPE t AS ENUM ()`).
typ := types.MakeEnum(catid.TypeIDToOID(descpb.ID(id)), 0 /* arrayTypeID */)
typ.TypeMeta = types.UserDefinedTypeMetadata{
Name: &types.UserDefinedTypeName{
Schema: scName,
Name: name,
},
EnumData: &types.EnumMetadata{
LogicalRepresentations: members,
// The physical representations don't matter in this case, but the
// enum related code in tree expects that the length of
// PhysicalRepresentations is equal to the length of LogicalRepresentations.
PhysicalRepresentations: make([][]byte, len(members)),
IsMemberReadOnly: make([]bool, len(members)),
},
}
key := tree.MakeSchemaQualifiedTypeName(scName, name)
udtMapping[key] = typ
}
var udts []*types.T
for _, t := range udtMapping {
Expand Down