-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathdependencies.go
146 lines (118 loc) · 5.79 KB
/
dependencies.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2022 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 scbuild
import (
"context"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scbuild/internal/scbuildstmt"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scdecomp"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/util/uuid"
"github.com/cockroachdb/redact"
)
// Dependencies contains all the external dependencies required by the scbuild
// package and its children.
type Dependencies interface {
scbuildstmt.ClusterAndSessionInfo
scbuildstmt.Telemetry
// CatalogReader returns a CatalogReader implementation.
CatalogReader() CatalogReader
// AuthorizationAccessor returns an AuthorizationAccessor implementation.
AuthorizationAccessor() AuthorizationAccessor
// ClusterID returns the ID of the cluster.
// So far this is used only to build a tree.EvalContext, for the purpose
// of checking whether CCL features are enabled.
ClusterID() uuid.UUID
// Codec returns the current session data, as in execCfg.
// So far this is used only to build a tree.EvalContext.
Codec() keys.SQLCodec
// Statements returns the statements behind this schema change.
Statements() []string
// AstFormatter returns something that can format AST nodes.
AstFormatter() AstFormatter
// FeatureChecker returns something that checks schema feature flags.
FeatureChecker() FeatureChecker
// IndexPartitioningCCLCallback returns the CCL callback for creating
// partitioning descriptors for indexes.
IndexPartitioningCCLCallback() CreatePartitioningCCLCallback
// DescriptorMetadataFetcher returns a scdecomp.DescriptorMetadataFetcher
// Implementation.
DescriptorMetadataFetcher() scdecomp.DescriptorMetadataFetcher
}
// CreatePartitioningCCLCallback is the type of the CCL callback for creating
// partitioning descriptors for indexes.
type CreatePartitioningCCLCallback func(
ctx context.Context,
st *cluster.Settings,
evalCtx *tree.EvalContext,
columnLookupFn func(tree.Name) (catalog.Column, error),
oldNumImplicitColumns int,
oldKeyColumnNames []string,
partBy *tree.PartitionBy,
allowedNewColumnNames []tree.Name,
allowImplicitPartitioning bool,
) (newImplicitCols []catalog.Column, newPartitioning catpb.PartitioningDescriptor, err error)
// CatalogReader should implement descriptor resolution, namespace lookups, and
// all such catalog read operations for the builder. The following contract must
// apply:
// - errors are panicked;
// - caches are avoided at all times, we read straight from storage;
// - MayResolve* methods return zero values if nothing could be found;
// - MayResolve* methods ignore dropped or offline descriptors;
// - MustReadDescriptor does not;
// - MustReadDescriptor panics if the descriptor was not found.
type CatalogReader interface {
tree.TypeReferenceResolver
tree.QualifiedNameResolver
// MayResolveDatabase looks up a database by name.
MayResolveDatabase(ctx context.Context, name tree.Name) catalog.DatabaseDescriptor
// MayResolveSchema looks up a schema by name.
MayResolveSchema(ctx context.Context, name tree.ObjectNamePrefix) (catalog.DatabaseDescriptor, catalog.SchemaDescriptor)
// MayResolveTable looks up a table by name.
MayResolveTable(ctx context.Context, name tree.UnresolvedObjectName) (catalog.ResolvedObjectPrefix, catalog.TableDescriptor)
// MayResolveIndex looks up an index using a naked index name with database
// and schema prefix. Resolved index and the owner table name are returned.
MayResolveIndex(ctx context.Context, indexName tree.Name, prefix tree.ObjectNamePrefix) (catalog.Index, tree.TableName)
// MayResolveType looks up a type by name.
MayResolveType(ctx context.Context, name tree.UnresolvedObjectName) (catalog.ResolvedObjectPrefix, catalog.TypeDescriptor)
// ReadObjectNamesAndIDs looks up the namespace entries for a schema.
ReadObjectNamesAndIDs(ctx context.Context, db catalog.DatabaseDescriptor, schema catalog.SchemaDescriptor) (tree.TableNames, descpb.IDs)
// MustReadDescriptor looks up a descriptor by ID.
MustReadDescriptor(ctx context.Context, id descpb.ID) catalog.Descriptor
// MustGetSchemasForDatabase gets schemas associated with
// a database.
MustGetSchemasForDatabase(
ctx context.Context, database catalog.DatabaseDescriptor,
) map[descpb.ID]string
}
// AuthorizationAccessor for checking authorization (e.g. desc privileges).
type AuthorizationAccessor interface {
// CheckPrivilege verifies that the current user has `privilege` on
// `descriptor`.
CheckPrivilege(
ctx context.Context, descriptor catalog.Descriptor, privilege privilege.Kind,
) error
// HasAdminRole verifies if a user has an admin role.
HasAdminRole(ctx context.Context) (bool, error)
// HasOwnership returns true iff the role, or any role the role is a member
// of, has ownership privilege of the desc.
HasOwnership(ctx context.Context, descriptor catalog.Descriptor) (bool, error)
}
// AstFormatter provides interfaces for formatting AST nodes.
type AstFormatter interface {
// FormatAstAsRedactableString formats a tree.Statement into SQL with fully
// qualified names, where parts can be redacted.
FormatAstAsRedactableString(statement tree.Statement, annotations *tree.Annotations) redact.RedactableString
}