Skip to content

Commit

Permalink
scbuildstmt: Rerewrite a few function with better APIs
Browse files Browse the repository at this point in the history
This commit cleaned up a few functions using the preferred .FilterXxx()
API to retrieve element from an element set. No functional change is
introduced.

Informs: cockroachdb#117574
Release note: None
  • Loading branch information
Xiang-Gu authored and sriram2000na committed May 16, 2024
1 parent ec4d9bc commit b567a5f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,23 @@ func addSecondaryIndexTargetsForAddColumn(
}
}

func mustRetrieveTemporaryIndexElem(
func retrieveTemporaryIndexElem(
b BuildCtx, tableID catid.DescID, indexID catid.IndexID,
) (temporaryIndexElem *scpb.TemporaryIndex) {
scpb.ForEachTemporaryIndex(b.QueryByID(tableID), func(current scpb.Status, target scpb.TargetStatus, e *scpb.TemporaryIndex) {
b.QueryByID(tableID).FilterTemporaryIndex().ForEach(func(
_ scpb.Status, _ scpb.TargetStatus, e *scpb.TemporaryIndex,
) {
if e.IndexID == indexID {
temporaryIndexElem = e
}
})
return temporaryIndexElem
}

func mustRetrieveTemporaryIndexElem(
b BuildCtx, tableID catid.DescID, indexID catid.IndexID,
) (temporaryIndexElem *scpb.TemporaryIndex) {
temporaryIndexElem = retrieveTemporaryIndexElem(b, tableID, indexID)
if temporaryIndexElem == nil {
panic(errors.AssertionFailedf("programming error: cannot find a TemporaryIndex element"+
" of ID %v", indexID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,16 @@ func ensureColCanBeUsedInInboundFK(b BuildCtx, tableID catid.DescID, columnID ca
}
}

func retrieveTableElem(b BuildCtx, tableID catid.DescID) *scpb.Table {
return b.QueryByID(tableID).FilterTable().Filter(func(
current scpb.Status, target scpb.TargetStatus, e *scpb.Table,
) bool {
return e.TableID == tableID
}).MustGetZeroOrOneElement()
}

func mustRetrieveTableElem(b BuildCtx, tableID catid.DescID) *scpb.Table {
_, _, tblElem := scpb.FindTable(b.QueryByID(tableID))
tblElem := retrieveTableElem(b, tableID)
if tblElem == nil {
panic(errors.AssertionFailedf("programming error: cannot find a Table element for table %v", tableID))
}
Expand Down

0 comments on commit b567a5f

Please sign in to comment.