Skip to content

Commit

Permalink
impossible nil checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jwtryg committed Dec 18, 2024
1 parent be00619 commit 8f51473
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions table/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type Metadata interface {
CurrentSnapshot() *Snapshot
// Ref returns the snapshot ref for the main branch.
Ref() SnapshotRef
// Refs returns a map of snapshot refs by name.
// Refs returns a list of snapshot name/reference pairs.
Refs() iter.Seq2[string, SnapshotRef]
// SnapshotLogs returns the list of snapshot logs for the table.
SnapshotLogs() iter.Seq[SnapshotLogEntry]
Expand Down Expand Up @@ -275,20 +275,18 @@ func (b *MetadataBuilder) AddSnapshot(snapshot *Snapshot) (*MetadataBuilder, err
}

func (b *MetadataBuilder) AddSortOrder(sortOrder *SortOrder, initial bool) (*MetadataBuilder, error) {
for _, s := range b.sortOrderList {
if s.OrderID == sortOrder.OrderID && !initial {
return nil, fmt.Errorf("sort order with id %d already exists", sortOrder.OrderID)
}
}

var sortOrders []SortOrder
if initial {
sortOrders = []SortOrder{*sortOrder}
} else {
if !initial {
sortOrders = append(b.sortOrderList, *sortOrder)
}

b.sortOrderList = sortOrders
for _, s := range sortOrders {
if s.OrderID == sortOrder.OrderID {
return nil, fmt.Errorf("sort order with id %d already exists", sortOrder.OrderID)
}
}

b.sortOrderList = append(sortOrders, *sortOrder)
b.updates = append(b.updates, NewAddSortOrderUpdate(sortOrder, initial))

return b, nil
Expand Down Expand Up @@ -945,10 +943,6 @@ func (m *metadataV1) Equals(other Metadata) bool {
return true
}

if m == nil || rhs == nil {
return false
}

return m.Schema.Equals(rhs.Schema) && slices.Equal(m.Partition, rhs.Partition) &&
m.commonMetadata.Equals(&rhs.commonMetadata)
}
Expand Down Expand Up @@ -1020,10 +1014,6 @@ func (m *metadataV2) Equals(other Metadata) bool {
return true
}

if m == nil || rhs == nil {
return false
}

return m.LastSequenceNumber == rhs.LastSequenceNumber &&
m.commonMetadata.Equals(&rhs.commonMetadata)
}
Expand Down

0 comments on commit 8f51473

Please sign in to comment.