Skip to content

Commit ad7125a

Browse files
authored
fix: Metadata.Equal comparison with keys in different order (#571)
### Rationale for this change fixes #565 ### What changes are included in this PR? Fixing `Metadata.sortedIndices` to properly sort the key indices ### Are these changes tested? Yes, a unit test is added for this situation ### Are there any user-facing changes? No
1 parent 3160eef commit ad7125a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

arrow/schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (md Metadata) sortedIndices() []int {
130130
}
131131

132132
slices.SortFunc(idxes, func(i, j int) int {
133-
return strings.Compare(md.keys[idxes[i]], md.keys[idxes[j]])
133+
return strings.Compare(md.keys[i], md.keys[j])
134134
})
135135
return idxes
136136
}

arrow/schema_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ func TestMetadata(t *testing.T) {
149149
})
150150
}
151151

152+
func TestMetadataSortedIndices(t *testing.T) {
153+
md1 := NewMetadata(
154+
[]string{"..", "a", "b", "c", "A", "B", "C"},
155+
[]string{"1", "2", "3", "4", "5", "6", "7"})
156+
157+
md2 := NewMetadata(
158+
[]string{"A", "B", "C", "..", "a", "b", "c"},
159+
[]string{"5", "6", "7", "1", "2", "3", "4"})
160+
161+
assert.True(t, md1.Equal(md2))
162+
}
163+
152164
func TestSchema(t *testing.T) {
153165
for _, tc := range []struct {
154166
fields []Field

0 commit comments

Comments
 (0)