Skip to content

Commit

Permalink
Stable order for unrecognized columns in disco-balled tables
Browse files Browse the repository at this point in the history
  • Loading branch information
hasty committed Nov 8, 2024
1 parent b583863 commit bf3b885
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions disco/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func (b *Ball) reorderColumns(doc *spec.Doc, section *spec.Section, ti *spec.Tab
}
}
// Recognized columns, but not in the column order
var recognizedColumnIndexes []int
for tc, i := range columnMap {
if newColumnIndexes[i] >= 0 {
continue
Expand All @@ -198,9 +199,12 @@ func (b *Ball) reorderColumns(doc *spec.Doc, section *spec.Section, ti *spec.Tab
newColumnIndexes[i] = -2
continue
}
newColumnIndexes[i] = index
recognizedColumnIndexes = append(recognizedColumnIndexes, i)
}
slices.Sort(recognizedColumnIndexes)
for _, extraColumnIndex := range recognizedColumnIndexes {
newColumnIndexes[extraColumnIndex] = index
index++

}
// Unrecognized columns come last
for i, v := range newColumnIndexes {
Expand Down

0 comments on commit bf3b885

Please sign in to comment.