Skip to content

Commit

Permalink
sql/schemachanger/scbuild: remove mention of nodes
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
ajwerner committed Jun 24, 2021
1 parent 65df23c commit d27186f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
20 changes: 9 additions & 11 deletions pkg/sql/schemachanger/scbuild/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ type Dependencies struct {
type buildContext struct {
Dependencies

// outputNodes contains the internal state when building targets for an individual
// output contains the internal state when building targets for an individual
// statement.
outputNodes scpb.State
output scpb.State
}

type notImplementedError struct {
Expand Down Expand Up @@ -111,13 +111,13 @@ func (e *ConcurrentSchemaChangeError) DescriptorID() descpb.ID {
return e.descID
}

// Build constructs a new set of nodes from an initial set and a statement.
// Build constructs a new set state from an initial state and a statement.
func Build(
ctx context.Context, dependencies Dependencies, initial scpb.State, n tree.Statement,
) (outputNodes scpb.State, err error) {
) (built scpb.State, err error) {
buildContext := &buildContext{
Dependencies: dependencies,
outputNodes: cloneState(initial),
output: cloneState(initial),
}
return buildContext.build(ctx, n)
}
Expand All @@ -135,9 +135,7 @@ func cloneState(state scpb.State) scpb.State {

// build builds targets and transforms the provided schema change nodes
// accordingly, given a statement.
func (b *buildContext) build(
ctx context.Context, n tree.Statement,
) (outputNodes scpb.State, err error) {
func (b *buildContext) build(ctx context.Context, n tree.Statement) (output scpb.State, err error) {
defer func() {
if recErr := recover(); recErr != nil {
if errObj, ok := recErr.(error); ok {
Expand Down Expand Up @@ -165,7 +163,7 @@ func (b *buildContext) build(
default:
return nil, &notImplementedError{n: n}
}
return b.outputNodes, nil
return b.output, nil
}

// checkIfNodeExists checks if an existing node is already there,
Expand All @@ -175,7 +173,7 @@ func (b *buildContext) checkIfNodeExists(
) (exists bool, index int) {
// Check if any existing node matches the new node we are
// trying to add.
for idx, node := range b.outputNodes {
for idx, node := range b.output {
if scpb.EqualElements(node.Element(), elem) {
return true, idx
}
Expand All @@ -197,7 +195,7 @@ func (b *buildContext) addNode(dir scpb.Target_Direction, elem scpb.Element) {
if exists, _ := b.checkIfNodeExists(dir, elem); exists {
panic(errors.Errorf("attempted to add duplicate element %s", elem))
}
b.outputNodes = append(b.outputNodes, &scpb.Node{
b.output = append(b.output, &scpb.Node{
Target: scpb.NewTarget(dir, elem),
Status: s,
})
Expand Down
16 changes: 8 additions & 8 deletions pkg/sql/schemachanger/scbuild/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (b *buildContext) validateColumnName(
}
panic(sqlerrors.NewColumnAlreadyExistsError(string(d.Name), table.GetName()))
}
for _, n := range b.outputNodes {
for _, n := range b.output {
switch t := n.Element().(type) {
case *scpb.Column:
if t.TableID != table.GetID() || t.Column.Name != string(d.Name) {
Expand Down Expand Up @@ -251,7 +251,7 @@ func (b *buildContext) findOrAddColumnFamily(
// TODO(ajwerner): Decide what to do if the only column in a family of this
// name is being dropped and then if there is or isn't a create directive.
nextFamilyID := table.GetNextFamilyID()
for _, n := range b.outputNodes {
for _, n := range b.output {
switch col := n.Element().(type) {
case *scpb.Column:
if col.TableID != table.GetID() {
Expand Down Expand Up @@ -293,7 +293,7 @@ func (b *buildContext) alterTableDropColumn(
panic(err)
}
// Check whether the column is being dropped.
for _, n := range b.outputNodes {
for _, n := range b.output {
switch col := n.Element().(type) {
case *scpb.Column:
if col.TableID != table.GetID() ||
Expand Down Expand Up @@ -423,9 +423,9 @@ func (b *buildContext) addOrUpdatePrimaryIndexTargetsForAddColumn(
) (idxID descpb.IndexID) {
// Check whether a target to add a PK already exists. If so, update its
// storing columns.
for i, n := range b.outputNodes {
for i, n := range b.output {
if t, ok := n.Element().(*scpb.PrimaryIndex); ok &&
b.outputNodes[i].Target.Direction == scpb.Target_ADD &&
b.output[i].Target.Direction == scpb.Target_ADD &&
t.TableID == table.GetID() {
t.Index.StoreColumnIDs = append(t.Index.StoreColumnIDs, colID)
t.Index.StoreColumnNames = append(t.Index.StoreColumnNames, colName)
Expand Down Expand Up @@ -475,7 +475,7 @@ func (b *buildContext) addOrUpdatePrimaryIndexTargetsForDropColumn(
) (idxID descpb.IndexID) {
// Check whether a target to add a PK already exists. If so, update its
// storing columns.
for _, n := range b.outputNodes {
for _, n := range b.output {
if t, ok := n.Element().(*scpb.PrimaryIndex); ok &&
n.Target.Direction == scpb.Target_ADD &&
t.TableID == table.GetID() {
Expand Down Expand Up @@ -542,7 +542,7 @@ func (b *buildContext) nextColumnID(table catalog.TableDescriptor) descpb.Column
nextColID := table.GetNextColumnID()
var maxColID descpb.ColumnID

for _, n := range b.outputNodes {
for _, n := range b.output {
if n.Target.Direction != scpb.Target_ADD || scpb.GetDescID(n.Element()) != table.GetID() {
continue
}
Expand All @@ -561,7 +561,7 @@ func (b *buildContext) nextColumnID(table catalog.TableDescriptor) descpb.Column
func (b *buildContext) nextIndexID(table catalog.TableDescriptor) descpb.IndexID {
nextMaxID := table.GetNextIndexID()
var maxIdxID descpb.IndexID
for _, n := range b.outputNodes {
for _, n := range b.output {
if n.Target.Direction != scpb.Target_ADD || scpb.GetDescID(n.Element()) != table.GetID() {
continue
}
Expand Down

0 comments on commit d27186f

Please sign in to comment.