-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
69779: importccl: add IMPORT INTO UDT support for default+computed columns r=dt a=adityamaru This change builds on the work in #69674 and uses the type descriptors stored on the import job during planning to construct a custom type resolver. This resolver is used when hydrating the types used by the table being imported into, and when processing default + computed columns. Informs: #61133 Release note (sql change): IMPORT INTO now supports UDT for default and computed columns. Release justification: fixes for high-priority or high-severity bugs in existing functionality Co-authored-by: Aditya Maru <[email protected]>
- Loading branch information
Showing
22 changed files
with
403 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2017 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package importccl | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/sql/catalog" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/typedesc" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree" | ||
"github.com/cockroachdb/cockroach/pkg/sql/types" | ||
"github.com/cockroachdb/errors" | ||
"github.com/lib/pq/oid" | ||
) | ||
|
||
type importTypeResolver struct { | ||
typeIDToDesc map[descpb.ID]*descpb.TypeDescriptor | ||
typeNameToDesc map[string]*descpb.TypeDescriptor | ||
} | ||
|
||
func newImportTypeResolver(typeDescs []*descpb.TypeDescriptor) importTypeResolver { | ||
itr := importTypeResolver{ | ||
typeIDToDesc: make(map[descpb.ID]*descpb.TypeDescriptor), | ||
typeNameToDesc: make(map[string]*descpb.TypeDescriptor), | ||
} | ||
for _, typeDesc := range typeDescs { | ||
itr.typeIDToDesc[typeDesc.GetID()] = typeDesc | ||
itr.typeNameToDesc[typeDesc.GetName()] = typeDesc | ||
} | ||
return itr | ||
} | ||
|
||
var _ tree.TypeReferenceResolver = &importTypeResolver{} | ||
|
||
func (i importTypeResolver) ResolveType( | ||
_ context.Context, _ *tree.UnresolvedObjectName, | ||
) (*types.T, error) { | ||
return nil, errors.New("importTypeResolver does not implement ResolveType") | ||
} | ||
|
||
func (i importTypeResolver) ResolveTypeByOID(ctx context.Context, oid oid.Oid) (*types.T, error) { | ||
id, err := typedesc.UserDefinedTypeOIDToID(oid) | ||
if err != nil { | ||
return nil, err | ||
} | ||
name, desc, err := i.GetTypeDescriptor(ctx, id) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return desc.MakeTypesT(ctx, &name, i) | ||
} | ||
|
||
var _ catalog.TypeDescriptorResolver = &importTypeResolver{} | ||
|
||
// GetTypeDescriptor implements the sqlbase.TypeDescriptorResolver interface. | ||
func (i importTypeResolver) GetTypeDescriptor( | ||
_ context.Context, id descpb.ID, | ||
) (tree.TypeName, catalog.TypeDescriptor, error) { | ||
var desc *descpb.TypeDescriptor | ||
var ok bool | ||
if desc, ok = i.typeIDToDesc[id]; !ok { | ||
return tree.TypeName{}, nil, errors.Newf("type descriptor could not be resolved for type id %d", id) | ||
} | ||
typeDesc := typedesc.NewBuilder(desc).BuildImmutableType() | ||
name := tree.MakeUnqualifiedTypeName(desc.GetName()) | ||
return name, typeDesc, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.