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

sql/schemachanger: add enum type values as an element #83802

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions pkg/ccl/schemachangerccl/testdata/decomp/multiregion
Original file line number Diff line number Diff line change
Expand Up @@ -964,3 +964,18 @@ ElementState:
objectId: 105
parentSchemaId: 106
Status: PUBLIC
- EnumTypeValue:
logicalRepresentation: us-east1
physicalRepresentation: QA==
typeId: 105
Status: PUBLIC
- EnumTypeValue:
logicalRepresentation: us-east2
physicalRepresentation: gA==
typeId: 105
Status: PUBLIC
- EnumTypeValue:
logicalRepresentation: us-east3
physicalRepresentation: wA==
typeId: 105
Status: PUBLIC
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ upsert descriptor #105
+ - ABSENT
+ - DROPPED
+ - ABSENT
+ - ABSENT
+ - ABSENT
+ - ABSENT
+ jobId: "1"
+ relevantStatements:
+ - statement:
Expand All @@ -241,6 +244,9 @@ upsert descriptor #105
+ - 19
+ - 20
+ - 21
+ - 22
+ - 23
+ - 24
+ targets:
+ - elementProto:
+ namespace:
Expand Down Expand Up @@ -297,6 +303,33 @@ upsert descriptor #105
+ subWorkId: 1
+ targetStatus: ABSENT
+ - elementProto:
+ enumTypeValue:
+ logicalRepresentation: us-east1
+ physicalRepresentation: QA==
+ typeId: 105
+ metadata:
+ sourceElementId: 3
+ subWorkId: 1
+ targetStatus: ABSENT
+ - elementProto:
+ enumTypeValue:
+ logicalRepresentation: us-east2
+ physicalRepresentation: gA==
+ typeId: 105
+ metadata:
+ sourceElementId: 3
+ subWorkId: 1
+ targetStatus: ABSENT
+ - elementProto:
+ enumTypeValue:
+ logicalRepresentation: us-east3
+ physicalRepresentation: wA==
+ typeId: 105
+ metadata:
+ sourceElementId: 3
+ subWorkId: 1
+ targetStatus: ABSENT
+ - elementProto:
+ objectParent:
+ objectId: 105
+ parentSchemaId: 106
Expand Down Expand Up @@ -432,13 +465,13 @@ upsert descriptor #107
+ statement: DROP DATABASE multi_region_test_db CASCADE
+ statementTag: DROP DATABASE
+ targetRanks:
+ - 22
+ - 23
+ - 24
+ - 25
+ - 26
+ - 27
+ - 28
+ - 29
+ - 30
+ - 31
+ targets:
+ - elementProto:
+ namespace:
Expand Down Expand Up @@ -556,9 +589,6 @@ upsert descriptor #108
+ statement: DROP DATABASE multi_region_test_db CASCADE
+ statementTag: DROP DATABASE
+ targetRanks:
+ - 29
+ - 30
+ - 31
+ - 32
+ - 33
+ - 34
Expand All @@ -576,6 +606,9 @@ upsert descriptor #108
+ - 46
+ - 47
+ - 48
+ - 49
+ - 50
+ - 51
+ targets:
+ - elementProto:
+ namespace:
Expand Down Expand Up @@ -830,9 +863,6 @@ upsert descriptor #108
- statement: DROP DATABASE multi_region_test_db CASCADE
- statementTag: DROP DATABASE
- targetRanks:
- - 29
- - 30
- - 31
- - 32
- - 33
- - 34
Expand All @@ -850,6 +880,9 @@ upsert descriptor #108
- - 46
- - 47
- - 48
- - 49
- - 50
- - 51
- targets:
- - elementProto:
- namespace:
Expand Down
9 changes: 7 additions & 2 deletions pkg/sql/schemachanger/scbuild/testdata/drop_database
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ DROP DATABASE db1 CASCADE
usesSequenceIds:
- 107
tableId: 110
- [[ColumnFamily:{DescID: 109, ColumnFamilyID: 0, Name: primary}, ABSENT], PUBLIC]
- [[ColumnFamily:{DescID: 109, Name: primary, ColumnFamilyID: 0}, ABSENT], PUBLIC]
details:
name: primary
tableId: 109
- [[ColumnFamily:{DescID: 110, ColumnFamilyID: 0, Name: primary}, ABSENT], PUBLIC]
- [[ColumnFamily:{DescID: 110, Name: primary, ColumnFamilyID: 0}, ABSENT], PUBLIC]
details:
name: primary
tableId: 110
Expand Down Expand Up @@ -734,6 +734,11 @@ DROP DATABASE db1 CASCADE
details:
arrayTypeId: 116
typeId: 115
- [[EnumTypeValue:{DescID: 115, Name: a}, ABSENT], PUBLIC]
details:
logicalRepresentation: a
physicalRepresentation: gA==
typeId: 115
- [[IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC]
details:
columnId: 1
Expand Down
9 changes: 7 additions & 2 deletions pkg/sql/schemachanger/scbuild/testdata/drop_owned_by
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ DROP OWNED BY r
usesSequenceIds:
- 106
tableId: 109
- [[ColumnFamily:{DescID: 108, ColumnFamilyID: 0, Name: primary}, ABSENT], PUBLIC]
- [[ColumnFamily:{DescID: 108, Name: primary, ColumnFamilyID: 0}, ABSENT], PUBLIC]
details:
name: primary
tableId: 108
- [[ColumnFamily:{DescID: 109, ColumnFamilyID: 0, Name: primary}, ABSENT], PUBLIC]
- [[ColumnFamily:{DescID: 109, Name: primary, ColumnFamilyID: 0}, ABSENT], PUBLIC]
details:
name: primary
tableId: 109
Expand Down Expand Up @@ -428,6 +428,11 @@ DROP OWNED BY r
details:
arrayTypeId: 112
typeId: 111
- [[EnumTypeValue:{DescID: 111, Name: a}, ABSENT], PUBLIC]
details:
logicalRepresentation: a
physicalRepresentation: gA==
typeId: 111
- [[IndexColumn:{DescID: 108, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC]
details:
columnId: 1
Expand Down
7 changes: 6 additions & 1 deletion pkg/sql/schemachanger/scbuild/testdata/drop_schema
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ DROP SCHEMA defaultdb.SC1 CASCADE
usesSequenceIds:
- 106
tableId: 107
- [[ColumnFamily:{DescID: 107, ColumnFamilyID: 0, Name: primary}, ABSENT], PUBLIC]
- [[ColumnFamily:{DescID: 107, Name: primary, ColumnFamilyID: 0}, ABSENT], PUBLIC]
details:
name: primary
tableId: 107
Expand Down Expand Up @@ -710,6 +710,11 @@ DROP SCHEMA defaultdb.SC1 CASCADE
details:
arrayTypeId: 113
typeId: 112
- [[EnumTypeValue:{DescID: 112, Name: a}, ABSENT], PUBLIC]
details:
logicalRepresentation: a
physicalRepresentation: gA==
typeId: 112
- [[IndexColumn:{DescID: 107, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC]
details:
columnId: 1
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/schemachanger/scbuild/testdata/drop_table
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ DROP TABLE defaultdb.shipments CASCADE;
usesSequenceIds:
- 106
tableId: 109
- [[ColumnFamily:{DescID: 109, ColumnFamilyID: 0, Name: primary}, ABSENT], PUBLIC]
- [[ColumnFamily:{DescID: 109, Name: primary, ColumnFamilyID: 0}, ABSENT], PUBLIC]
details:
name: primary
tableId: 109
Expand Down
5 changes: 5 additions & 0 deletions pkg/sql/schemachanger/scbuild/testdata/drop_type
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ DROP TYPE defaultdb.typ
details:
arrayTypeId: 105
typeId: 104
- [[EnumTypeValue:{DescID: 104, Name: a}, ABSENT], PUBLIC]
details:
logicalRepresentation: a
physicalRepresentation: gA==
typeId: 104
- [[Namespace:{DescID: 104, Name: typ, ReferencedDescID: 100}, ABSENT], PUBLIC]
details:
databaseId: 100
Expand Down
7 changes: 7 additions & 0 deletions pkg/sql/schemachanger/scdecomp/decomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ func (w *walkCtx) walkType(typ catalog.TypeDescriptor) {
ArrayTypeID: typ.GetArrayTypeID(),
IsMultiRegion: typ.GetKind() == descpb.TypeDescriptor_MULTIREGION_ENUM,
})
for ord := 0; ord < typ.NumEnumMembers(); ord++ {
w.ev(descriptorStatus(typ), &scpb.EnumTypeValue{
TypeID: typ.GetID(),
PhysicalRepresentation: typ.GetMemberPhysicalRepresentation(ord),
LogicalRepresentation: typ.GetMemberLogicalRepresentation(ord),
})
}
default:
panic(errors.AssertionFailedf("unsupported type kind %q", typ.GetKind()))
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/sql/schemachanger/scdecomp/testdata/other
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ ElementState:
objectId: 110
parentSchemaId: 106
Status: PUBLIC
- EnumTypeValue:
logicalRepresentation: a
physicalRepresentation: gA==
typeId: 110
Status: PUBLIC

decompose
v1
Expand Down
10 changes: 10 additions & 0 deletions pkg/sql/schemachanger/scdecomp/testdata/type
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ ElementState:
objectId: 104
parentSchemaId: 101
Status: PUBLIC
- EnumTypeValue:
logicalRepresentation: hello
physicalRepresentation: QA==
typeId: 104
Status: PUBLIC
- EnumTypeValue:
logicalRepresentation: hi
physicalRepresentation: gA==
typeId: 104
Status: PUBLIC

decompose
tbl
Expand Down
9 changes: 9 additions & 0 deletions pkg/sql/schemachanger/scpb/elements.proto
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ message ElementProto {

// Object elements.
ObjectParent object_parent = 100 [(gogoproto.moretags) = "parent:\"AliasType, EnumType, Table, View, Sequence\""];

// Enum type elements
EnumTypeValue enum_type_value = 120 [(gogoproto.moretags) = "parent:\"EnumType\""];
}

// TypeT is a wrapper for a types.T which contains its user-defined type ID
Expand Down Expand Up @@ -483,3 +486,9 @@ message IndexColumn {
// Direction is only populated for KEY columns.
sql.catalog.catpb.IndexColumn.Direction direction = 6;
}

message EnumTypeValue {
uint32 type_id = 1 [(gogoproto.customname) = "TypeID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.DescID"];
bytes physical_representation = 2;
string logical_representation = 3;
}
31 changes: 31 additions & 0 deletions pkg/sql/schemachanger/scpb/elements_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/sql/schemachanger/scpb/uml/table.puml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ object ObjectParent
ObjectParent : ObjectID
ObjectParent : ParentSchemaID

object EnumTypeValue

EnumTypeValue : TypeID
EnumTypeValue : []PhysicalRepresentation
EnumTypeValue : LogicalRepresentation

Table <|-- ColumnFamily
Table <|-- Column
View <|-- Column
Expand Down Expand Up @@ -332,4 +338,5 @@ EnumType <|-- ObjectParent
Table <|-- ObjectParent
View <|-- ObjectParent
Sequence <|-- ObjectParent
EnumType <|-- EnumTypeValue
@enduml
1 change: 1 addition & 0 deletions pkg/sql/schemachanger/scplan/internal/opgen/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ go_library(
"opgen_database_region_config.go",
"opgen_database_role_setting.go",
"opgen_enum_type.go",
"opgen_enum_type_value.go",
"opgen_foreign_key_constraint.go",
"opgen_index_column.go",
"opgen_index_comment.go",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2021 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package opgen

import (
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb"
)

func init() {
opRegistry.register((*scpb.EnumTypeValue)(nil),
toPublic(
scpb.Status_ABSENT,
to(scpb.Status_PUBLIC,
emit(func(this *scpb.EnumTypeValue) scop.Op {
return notImplemented(this)
}),
),
),
toAbsent(
scpb.Status_PUBLIC,
to(scpb.Status_ABSENT,
emit(func(this *scpb.EnumTypeValue) scop.Op {
return notImplemented(this)
}),
),
),
)
}
1 change: 1 addition & 0 deletions pkg/sql/schemachanger/scplan/internal/rules/op_drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func init() {
(*scpb.ColumnFamily)(nil),
(*scpb.Owner)(nil),
(*scpb.UserPrivileges)(nil),
(*scpb.EnumTypeValue)(nil),
),
joinOnDescID(desc.el, dep.el, descID),
desc.joinTarget(),
Expand Down
Loading