Skip to content

Commit

Permalink
GH-35256: [Go] Add ToMap to Metadata (#35257)
Browse files Browse the repository at this point in the history
### Rationale for this change

### What changes are included in this PR?

### Are these changes tested?

### Are there any user-facing changes?

* Closes: #35256
* Closes: #35256

Authored-by: Yevgeny Pats <16490766+yevgenypats@users.noreply.github.com>
Signed-off-by: Matthew Topol <zotthewizard@gmail.com>
  • Loading branch information
yevgenypats committed Apr 22, 2023
1 parent a1403d4 commit 8601aac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions go/arrow/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ func MetadataFrom(kv map[string]string) Metadata {
func (md Metadata) Len() int { return len(md.keys) }
func (md Metadata) Keys() []string { return md.keys }
func (md Metadata) Values() []string { return md.values }
func (md Metadata) ToMap() map[string]string {
m := make(map[string]string, len(md.keys))
for i := range md.keys {
m[md.keys[i]] = md.values[i]
}
return m
}

func (md Metadata) String() string {
o := new(strings.Builder)
Expand Down
4 changes: 4 additions & 0 deletions go/arrow/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"

"github.com/apache/arrow/go/v12/arrow/endian"
"github.com/stretchr/testify/assert"
)

func TestMetadata(t *testing.T) {
Expand Down Expand Up @@ -99,6 +100,9 @@ func TestMetadata(t *testing.T) {
if got, want := tc.md.String(), tc.serialize; got != want {
t.Fatalf("invalid stringer: got=%q, want=%q", got, want)
}
if len(tc.kvs) != 0 {
assert.Equal(t, tc.kvs, md.ToMap())
}
})
}

Expand Down

0 comments on commit 8601aac

Please sign in to comment.